提交 a00c1800 编写于 作者: D ding.lid

add util method

git-svn-id: http://code.alibabatech.com/svn/dubbo/trunk@1565 1a56cb94-b969-4eaa-88fa-be21384802f2
上级 119de4d7
...@@ -124,6 +124,17 @@ public class CollectionUtils { ...@@ -124,6 +124,17 @@ public class CollectionUtils {
return list; return list;
} }
public static String join(List<String> list, String separator) {
StringBuilder sb = new StringBuilder();
for(String ele : list) {
if(sb.length() > 0) {
sb.append(separator);
}
sb.append(ele);
}
return sb.toString();
}
public static boolean mapEquals(Map<?, ?> map1, Map<?, ?> map2) { public static boolean mapEquals(Map<?, ?> map1, Map<?, ?> map2) {
if (map1 == null && map2 == null) { if (map1 == null && map2 == null) {
return true; return true;
......
...@@ -124,7 +124,19 @@ public class CollectionUtilsTest { ...@@ -124,7 +124,19 @@ public class CollectionUtilsTest {
assertEquals(expected, output); assertEquals(expected, output);
} }
@Test
public void test_joinList() throws Exception {
List<String> list = Arrays.asList();
assertEquals("", CollectionUtils.join(list, "/"));
list = Arrays.asList("x");
assertEquals("x", CollectionUtils.join(list, "-"));
list = Arrays.asList("a", "b");
assertEquals("a/b", CollectionUtils.join(list, "/"));
}
@Test @Test
public void test_mapEquals() throws Exception { public void test_mapEquals() throws Exception {
assertTrue(CollectionUtils.mapEquals(null, null)); assertTrue(CollectionUtils.mapEquals(null, null));
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册