Skip to content

Commit

Permalink
Merge branch 'master' into fix/openapi-path-builder
Browse files Browse the repository at this point in the history
  • Loading branch information
nobodyiam authored Sep 14, 2021
2 parents 260c228 + d8b685e commit 60e2fe2
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 53 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -344,44 +344,4 @@ public interface StringFormatter<T> {
String format(T obj);
}

public static <T> String join(Collection<T> collection, String separator) {
return join(collection, separator, new StringFormatter<T>() {
@Override
public String format(T obj) {
return obj.toString();
}
});
}

public static <T> String join(Collection<T> collection, String separator,
StringFormatter<T> formatter) {
Iterator<T> iterator = collection.iterator();
// handle null, zero and one elements before building a buffer
if (iterator == null) {
return null;
}
if (!iterator.hasNext()) {
return EMPTY;
}
T first = iterator.next();
if (!iterator.hasNext()) {
return first == null ? "" : formatter.format(first);
}

// two or more elements
StringBuilder buf = new StringBuilder(256); // Java default is 16, probably too small
if (first != null) {
buf.append(formatter.format(first));
}

while (iterator.hasNext()) {
buf.append(separator);
T obj = iterator.next();
if (obj != null) {
buf.append(formatter.format(obj));
}
}

return buf.toString();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -68,19 +68,6 @@ public void testIsNumeric() {
Assert.assertTrue(StringUtils.isNumeric("1"));
}

@Test
public void testJoin() {
Assert.assertEquals("", StringUtils.join(new ArrayList(), "1a 2b 3c"));

ArrayList collection = new ArrayList();
collection.add(null);
Assert.assertEquals("", StringUtils.join(collection, "1a 2b 3c"));

collection = new ArrayList();
collection.add(-2_147_483_648);
Assert.assertEquals("-2147483648", StringUtils.join(collection, "1a 2b 3c"));
}

@Test
public void testStartsWithIgnoreCase() {
Assert.assertFalse(StringUtils.startsWithIgnoreCase("A1B2C3", "BAZ"));
Expand Down

0 comments on commit 60e2fe2

Please sign in to comment.