未验证 提交 d8b685ea 编写于 作者: W Willard 提交者: GitHub

Delete unused method StringUtils.join(..) (#3983)

上级 0b5d2277
......@@ -344,44 +344,4 @@ public class StringUtils {
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();
}
}
......@@ -68,19 +68,6 @@ public class StringUtilsTest {
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"));
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册