mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-08-18 20:38:02 +08:00
add SetUtil
This commit is contained in:
@@ -3,14 +3,14 @@ package cn.hutool.core.bean;
|
||||
import cn.hutool.core.annotation.Alias;
|
||||
import cn.hutool.core.bean.copier.CopyOptions;
|
||||
import cn.hutool.core.bean.copier.ValueProvider;
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.hutool.core.collection.ListUtil;
|
||||
import cn.hutool.core.collection.SetUtil;
|
||||
import cn.hutool.core.map.MapBuilder;
|
||||
import cn.hutool.core.map.MapUtil;
|
||||
import cn.hutool.core.text.StrUtil;
|
||||
import cn.hutool.core.thread.ThreadUtil;
|
||||
import cn.hutool.core.util.ArrayUtil;
|
||||
import cn.hutool.core.util.ObjUtil;
|
||||
import cn.hutool.core.text.StrUtil;
|
||||
import lombok.Data;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
@@ -285,7 +285,7 @@ public class BeanUtilTest {
|
||||
|
||||
@Test
|
||||
public void getPropertyDescriptorsTest() {
|
||||
final HashSet<Object> set = CollUtil.newHashSet();
|
||||
final HashSet<Object> set = SetUtil.newHashSet();
|
||||
final PropertyDescriptor[] propertyDescriptors = BeanUtil.getPropertyDescriptors(SubPerson.class);
|
||||
for (final PropertyDescriptor propertyDescriptor : propertyDescriptors) {
|
||||
set.add(propertyDescriptor.getName());
|
||||
|
||||
@@ -35,22 +35,22 @@ public class CollUtilTest {
|
||||
|
||||
@Test
|
||||
public void testPredicateContains() {
|
||||
final ArrayList<String> list = CollUtil.newArrayList("bbbbb", "aaaaa", "ccccc");
|
||||
final ArrayList<String> list = ListUtil.toList("bbbbb", "aaaaa", "ccccc");
|
||||
Assert.assertTrue(CollUtil.contains(list, s -> s.startsWith("a")));
|
||||
Assert.assertFalse(CollUtil.contains(list, s -> s.startsWith("d")));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRemoveWithAddIf() {
|
||||
ArrayList<Integer> list = CollUtil.newArrayList(1, 2, 3);
|
||||
final ArrayList<Integer> exceptRemovedList = CollUtil.newArrayList(2, 3);
|
||||
final ArrayList<Integer> exceptResultList = CollUtil.newArrayList(1);
|
||||
ArrayList<Integer> list = ListUtil.toList(1, 2, 3);
|
||||
final ArrayList<Integer> exceptRemovedList = ListUtil.toList(2, 3);
|
||||
final ArrayList<Integer> exceptResultList = ListUtil.toList(1);
|
||||
|
||||
List<Integer> resultList = CollUtil.removeWithAddIf(list, ele -> 1 == ele);
|
||||
Assert.assertEquals(list, exceptRemovedList);
|
||||
Assert.assertEquals(resultList, exceptResultList);
|
||||
|
||||
list = CollUtil.newArrayList(1, 2, 3);
|
||||
list = ListUtil.toList(1, 2, 3);
|
||||
resultList = new ArrayList<>();
|
||||
CollUtil.removeWithAddIf(list, resultList, ele -> 1 == ele);
|
||||
Assert.assertEquals(list, exceptRemovedList);
|
||||
@@ -59,27 +59,27 @@ public class CollUtilTest {
|
||||
|
||||
@Test
|
||||
public void testPadLeft() {
|
||||
List<String> srcList = CollUtil.newArrayList();
|
||||
List<String> answerList = CollUtil.newArrayList("a", "b");
|
||||
List<String> srcList = ListUtil.toList();
|
||||
List<String> answerList = ListUtil.toList("a", "b");
|
||||
CollUtil.padLeft(srcList, 1, "b");
|
||||
CollUtil.padLeft(srcList, 2, "a");
|
||||
Assert.assertEquals(srcList, answerList);
|
||||
|
||||
srcList = CollUtil.newArrayList("a", "b");
|
||||
answerList = CollUtil.newArrayList("a", "b");
|
||||
srcList = ListUtil.toList("a", "b");
|
||||
answerList = ListUtil.toList("a", "b");
|
||||
CollUtil.padLeft(srcList, 2, "a");
|
||||
Assert.assertEquals(srcList, answerList);
|
||||
|
||||
srcList = CollUtil.newArrayList("c");
|
||||
answerList = CollUtil.newArrayList("a", "a", "c");
|
||||
srcList = ListUtil.toList("c");
|
||||
answerList = ListUtil.toList("a", "a", "c");
|
||||
CollUtil.padLeft(srcList, 3, "a");
|
||||
Assert.assertEquals(srcList, answerList);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPadRight() {
|
||||
final List<String> srcList = CollUtil.newArrayList("a");
|
||||
final List<String> answerList = CollUtil.newArrayList("a", "b", "b", "b", "b");
|
||||
final List<String> srcList = ListUtil.toList("a");
|
||||
final List<String> answerList = ListUtil.toList("a", "b", "b", "b", "b");
|
||||
CollUtil.padRight(srcList, 5, "b");
|
||||
Assert.assertEquals(srcList, answerList);
|
||||
}
|
||||
@@ -91,7 +91,7 @@ public class CollUtilTest {
|
||||
|
||||
@Test
|
||||
public void newHashSetTest() {
|
||||
final Set<String> set = CollUtil.newHashSet((String[]) null);
|
||||
final Set<String> set = SetUtil.newHashSet((String[]) null);
|
||||
Assert.assertNotNull(set);
|
||||
}
|
||||
|
||||
@@ -114,8 +114,8 @@ public class CollUtilTest {
|
||||
|
||||
@Test
|
||||
public void unionTest() {
|
||||
final ArrayList<String> list1 = CollUtil.newArrayList("a", "b", "b", "c", "d", "x");
|
||||
final ArrayList<String> list2 = CollUtil.newArrayList("a", "b", "b", "b", "c", "d");
|
||||
final ArrayList<String> list1 = ListUtil.toList("a", "b", "b", "c", "d", "x");
|
||||
final ArrayList<String> list2 = ListUtil.toList("a", "b", "b", "b", "c", "d");
|
||||
|
||||
final Collection<String> union = CollUtil.union(list1, list2);
|
||||
|
||||
@@ -124,8 +124,8 @@ public class CollUtilTest {
|
||||
|
||||
@Test
|
||||
public void intersectionTest() {
|
||||
final ArrayList<String> list1 = CollUtil.newArrayList("a", "b", "b", "c", "d", "x");
|
||||
final ArrayList<String> list2 = CollUtil.newArrayList("a", "b", "b", "b", "c", "d");
|
||||
final ArrayList<String> list1 = ListUtil.toList("a", "b", "b", "c", "d", "x");
|
||||
final ArrayList<String> list2 = ListUtil.toList("a", "b", "b", "b", "c", "d");
|
||||
|
||||
final Collection<String> intersection = CollUtil.intersection(list1, list2);
|
||||
Assert.assertEquals(2, CollUtil.count(intersection, "b"::equals));
|
||||
@@ -133,12 +133,12 @@ public class CollUtilTest {
|
||||
|
||||
@Test
|
||||
public void intersectionDistinctTest() {
|
||||
final ArrayList<String> list1 = CollUtil.newArrayList("a", "b", "b", "c", "d", "x");
|
||||
final ArrayList<String> list2 = CollUtil.newArrayList("a", "b", "b", "b", "c", "d");
|
||||
final ArrayList<String> list3 = CollUtil.newArrayList();
|
||||
final ArrayList<String> list1 = ListUtil.toList("a", "b", "b", "c", "d", "x");
|
||||
final ArrayList<String> list2 = ListUtil.toList("a", "b", "b", "b", "c", "d");
|
||||
final ArrayList<String> list3 = ListUtil.toList();
|
||||
|
||||
final Collection<String> intersectionDistinct = CollUtil.intersectionDistinct(list1, list2);
|
||||
Assert.assertEquals(CollUtil.newLinkedHashSet("a", "b", "c", "d"), intersectionDistinct);
|
||||
Assert.assertEquals(SetUtil.newLinkedHashSet("a", "b", "c", "d"), intersectionDistinct);
|
||||
|
||||
final Collection<String> intersectionDistinct2 = CollUtil.intersectionDistinct(list1, list2, list3);
|
||||
Assert.assertTrue(intersectionDistinct2.isEmpty());
|
||||
@@ -146,8 +146,8 @@ public class CollUtilTest {
|
||||
|
||||
@Test
|
||||
public void disjunctionTest() {
|
||||
final ArrayList<String> list1 = CollUtil.newArrayList("a", "b", "b", "c", "d", "x");
|
||||
final ArrayList<String> list2 = CollUtil.newArrayList("a", "b", "b", "b", "c", "d", "x2");
|
||||
final ArrayList<String> list1 = ListUtil.toList("a", "b", "b", "c", "d", "x");
|
||||
final ArrayList<String> list2 = ListUtil.toList("a", "b", "b", "b", "c", "d", "x2");
|
||||
|
||||
final Collection<String> disjunction = CollUtil.disjunction(list1, list2);
|
||||
Assert.assertTrue(disjunction.contains("b"));
|
||||
@@ -163,8 +163,8 @@ public class CollUtilTest {
|
||||
@Test
|
||||
public void disjunctionTest2() {
|
||||
// 任意一个集合为空,差集为另一个集合
|
||||
final ArrayList<String> list1 = CollUtil.newArrayList();
|
||||
final ArrayList<String> list2 = CollUtil.newArrayList("a", "b", "b", "b", "c", "d", "x2");
|
||||
final ArrayList<String> list1 = ListUtil.toList();
|
||||
final ArrayList<String> list2 = ListUtil.toList("a", "b", "b", "b", "c", "d", "x2");
|
||||
|
||||
final Collection<String> disjunction = CollUtil.disjunction(list1, list2);
|
||||
Assert.assertEquals(list2, disjunction);
|
||||
@@ -175,8 +175,8 @@ public class CollUtilTest {
|
||||
@Test
|
||||
public void disjunctionTest3() {
|
||||
// 无交集下返回共同的元素
|
||||
final ArrayList<String> list1 = CollUtil.newArrayList("1", "2", "3");
|
||||
final ArrayList<String> list2 = CollUtil.newArrayList("a", "b", "c");
|
||||
final ArrayList<String> list1 = ListUtil.toList("1", "2", "3");
|
||||
final ArrayList<String> list2 = ListUtil.toList("a", "b", "c");
|
||||
|
||||
final Collection<String> disjunction = CollUtil.disjunction(list1, list2);
|
||||
Assert.assertTrue(disjunction.contains("1"));
|
||||
@@ -196,8 +196,8 @@ public class CollUtilTest {
|
||||
|
||||
@Test
|
||||
public void subtractTest() {
|
||||
final List<String> list1 = CollUtil.newArrayList("a", "b", "b", "c", "d", "x");
|
||||
final List<String> list2 = CollUtil.newArrayList("a", "b", "b", "b", "c", "d", "x2");
|
||||
final List<String> list1 = ListUtil.toList("a", "b", "b", "c", "d", "x");
|
||||
final List<String> list2 = ListUtil.toList("a", "b", "b", "b", "c", "d", "x2");
|
||||
final Collection<String> subtract = CollUtil.subtract(list1, list2);
|
||||
Assert.assertEquals(1, subtract.size());
|
||||
Assert.assertEquals("x", subtract.iterator().next());
|
||||
@@ -236,7 +236,7 @@ public class CollUtilTest {
|
||||
map2.put("c", "值3");
|
||||
|
||||
// ----------------------------------------------------------------------------------------
|
||||
final ArrayList<HashMap<String, String>> list = CollUtil.newArrayList(map1, map2);
|
||||
final ArrayList<HashMap<String, String>> list = ListUtil.toList(map1, map2);
|
||||
final Map<String, List<String>> map = CollUtil.toListMap(list);
|
||||
Assert.assertEquals("值1", map.get("a").get(0));
|
||||
Assert.assertEquals("值2", map.get("a").get(1));
|
||||
@@ -251,7 +251,7 @@ public class CollUtilTest {
|
||||
public void getFieldValuesTest() {
|
||||
final Dict v1 = Dict.create().set("id", 12).set("name", "张三").set("age", 23);
|
||||
final Dict v2 = Dict.create().set("age", 13).set("id", 15).set("name", "李四");
|
||||
final ArrayList<Dict> list = CollUtil.newArrayList(v1, v2);
|
||||
final ArrayList<Dict> list = ListUtil.toList(v1, v2);
|
||||
|
||||
final List<Object> fieldValues = CollUtil.getFieldValues(list, "name");
|
||||
Assert.assertEquals("张三", fieldValues.get(0));
|
||||
@@ -260,7 +260,7 @@ public class CollUtilTest {
|
||||
|
||||
@Test
|
||||
public void splitTest() {
|
||||
final ArrayList<Integer> list = CollUtil.newArrayList(1, 2, 3, 4, 5, 6, 7, 8, 9);
|
||||
final ArrayList<Integer> list = ListUtil.toList(1, 2, 3, 4, 5, 6, 7, 8, 9);
|
||||
final List<List<Integer>> split = CollUtil.split(list, 3);
|
||||
Assert.assertEquals(3, split.size());
|
||||
Assert.assertEquals(3, split.get(0).size());
|
||||
@@ -285,35 +285,35 @@ public class CollUtilTest {
|
||||
|
||||
@Test
|
||||
public void filterTest() {
|
||||
final ArrayList<String> list = CollUtil.newArrayList("a", "b", "c");
|
||||
final ArrayList<String> list = ListUtil.toList("a", "b", "c");
|
||||
|
||||
final Collection<String> filtered = CollUtil.edit(list, t -> t + 1);
|
||||
|
||||
Assert.assertEquals(CollUtil.newArrayList("a1", "b1", "c1"), filtered);
|
||||
Assert.assertEquals(ListUtil.toList("a1", "b1", "c1"), filtered);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void filterTest2() {
|
||||
final ArrayList<String> list = CollUtil.newArrayList("a", "b", "c");
|
||||
final ArrayList<String> list = ListUtil.toList("a", "b", "c");
|
||||
|
||||
final ArrayList<String> filtered = CollUtil.filter(list, t -> false == "a".equals(t));
|
||||
|
||||
// 原地过滤
|
||||
Assert.assertSame(list, filtered);
|
||||
Assert.assertEquals(CollUtil.newArrayList("b", "c"), filtered);
|
||||
Assert.assertEquals(ListUtil.toList("b", "c"), filtered);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void filterSetTest() {
|
||||
final Set<String> set = CollUtil.newLinkedHashSet("a", "b", "", " ", "c");
|
||||
final Set<String> set = SetUtil.newLinkedHashSet("a", "b", "", " ", "c");
|
||||
final Set<String> filtered = CollUtil.filter(set, StrUtil::isNotBlank);
|
||||
|
||||
Assert.assertEquals(CollUtil.newLinkedHashSet("a", "b", "c"), filtered);
|
||||
Assert.assertEquals(SetUtil.newLinkedHashSet("a", "b", "c"), filtered);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void filterRemoveTest() {
|
||||
final ArrayList<String> list = CollUtil.newArrayList("a", "b", "c");
|
||||
final ArrayList<String> list = ListUtil.toList("a", "b", "c");
|
||||
|
||||
final List<String> removed = new ArrayList<>();
|
||||
final ArrayList<String> filtered = CollUtil.filter(list, t -> {
|
||||
@@ -329,45 +329,45 @@ public class CollUtilTest {
|
||||
|
||||
// 原地过滤
|
||||
Assert.assertSame(list, filtered);
|
||||
Assert.assertEquals(CollUtil.newArrayList("b", "c"), filtered);
|
||||
Assert.assertEquals(ListUtil.toList("b", "c"), filtered);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void removeNullTest() {
|
||||
final ArrayList<String> list = CollUtil.newArrayList("a", "b", "c", null, "", " ");
|
||||
final ArrayList<String> list = ListUtil.toList("a", "b", "c", null, "", " ");
|
||||
|
||||
final ArrayList<String> filtered = CollUtil.removeNull(list);
|
||||
|
||||
// 原地过滤
|
||||
Assert.assertSame(list, filtered);
|
||||
Assert.assertEquals(CollUtil.newArrayList("a", "b", "c", "", " "), filtered);
|
||||
Assert.assertEquals(ListUtil.toList("a", "b", "c", "", " "), filtered);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void removeEmptyTest() {
|
||||
final ArrayList<String> list = CollUtil.newArrayList("a", "b", "c", null, "", " ");
|
||||
final ArrayList<String> list = ListUtil.toList("a", "b", "c", null, "", " ");
|
||||
|
||||
final ArrayList<String> filtered = CollUtil.removeEmpty(list);
|
||||
|
||||
// 原地过滤
|
||||
Assert.assertSame(list, filtered);
|
||||
Assert.assertEquals(CollUtil.newArrayList("a", "b", "c", " "), filtered);
|
||||
Assert.assertEquals(ListUtil.toList("a", "b", "c", " "), filtered);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void removeBlankTest() {
|
||||
final ArrayList<String> list = CollUtil.newArrayList("a", "b", "c", null, "", " ");
|
||||
final ArrayList<String> list = ListUtil.toList("a", "b", "c", null, "", " ");
|
||||
|
||||
final ArrayList<String> filtered = CollUtil.removeBlank(list);
|
||||
|
||||
// 原地过滤
|
||||
Assert.assertSame(list, filtered);
|
||||
Assert.assertEquals(CollUtil.newArrayList("a", "b", "c"), filtered);
|
||||
Assert.assertEquals(ListUtil.toList("a", "b", "c"), filtered);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void groupTest() {
|
||||
final List<String> list = CollUtil.newArrayList("1", "2", "3", "4", "5", "6");
|
||||
final List<String> list = ListUtil.toList("1", "2", "3", "4", "5", "6");
|
||||
final List<List<String>> group = CollUtil.group(list, null);
|
||||
Assert.assertTrue(group.size() > 0);
|
||||
|
||||
@@ -375,13 +375,13 @@ public class CollUtilTest {
|
||||
// 按照奇数偶数分类
|
||||
return Integer.parseInt(t) % 2;
|
||||
});
|
||||
Assert.assertEquals(CollUtil.newArrayList("2", "4", "6"), group2.get(0));
|
||||
Assert.assertEquals(CollUtil.newArrayList("1", "3", "5"), group2.get(1));
|
||||
Assert.assertEquals(ListUtil.toList("2", "4", "6"), group2.get(0));
|
||||
Assert.assertEquals(ListUtil.toList("1", "3", "5"), group2.get(1));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void groupByFieldTest() {
|
||||
final List<TestBean> list = CollUtil.newArrayList(new TestBean("张三", 12), new TestBean("李四", 13), new TestBean("王五", 12));
|
||||
final List<TestBean> list = ListUtil.toList(new TestBean("张三", 12), new TestBean("李四", 13), new TestBean("王五", 12));
|
||||
final List<List<TestBean>> groupByField = CollUtil.groupByField(list, "age");
|
||||
Assert.assertEquals("张三", groupByField.get(0).get(0).getName());
|
||||
Assert.assertEquals("王五", groupByField.get(0).get(1).getName());
|
||||
@@ -391,7 +391,7 @@ public class CollUtilTest {
|
||||
|
||||
@Test
|
||||
public void sortByPropertyTest() {
|
||||
final List<TestBean> list = CollUtil.newArrayList(
|
||||
final List<TestBean> list = ListUtil.toList(
|
||||
new TestBean("张三", 12, DateUtil.parse("2018-05-01")), //
|
||||
new TestBean("李四", 13, DateUtil.parse("2018-03-01")), //
|
||||
new TestBean("王五", 12, DateUtil.parse("2018-04-01"))//
|
||||
@@ -405,7 +405,7 @@ public class CollUtilTest {
|
||||
|
||||
@Test
|
||||
public void sortByPropertyTest2() {
|
||||
final List<TestBean> list = CollUtil.newArrayList(
|
||||
final List<TestBean> list = ListUtil.toList(
|
||||
new TestBean("张三", 0, DateUtil.parse("2018-05-01")), //
|
||||
new TestBean("李四", -12, DateUtil.parse("2018-03-01")), //
|
||||
new TestBean("王五", 23, DateUtil.parse("2018-04-01"))//
|
||||
@@ -419,7 +419,7 @@ public class CollUtilTest {
|
||||
|
||||
@Test
|
||||
public void fieldValueMapTest() {
|
||||
final List<TestBean> list = CollUtil.newArrayList(new TestBean("张三", 12, DateUtil.parse("2018-05-01")), //
|
||||
final List<TestBean> list = ListUtil.toList(new TestBean("张三", 12, DateUtil.parse("2018-05-01")), //
|
||||
new TestBean("李四", 13, DateUtil.parse("2018-03-01")), //
|
||||
new TestBean("王五", 12, DateUtil.parse("2018-04-01"))//
|
||||
);
|
||||
@@ -432,7 +432,7 @@ public class CollUtilTest {
|
||||
|
||||
@Test
|
||||
public void fieldValueAsMapTest() {
|
||||
final List<TestBean> list = CollUtil.newArrayList(new TestBean("张三", 12, DateUtil.parse("2018-05-01")), //
|
||||
final List<TestBean> list = ListUtil.toList(new TestBean("张三", 12, DateUtil.parse("2018-05-01")), //
|
||||
new TestBean("李四", 13, DateUtil.parse("2018-03-01")), //
|
||||
new TestBean("王五", 14, DateUtil.parse("2018-04-01"))//
|
||||
);
|
||||
@@ -470,8 +470,8 @@ public class CollUtilTest {
|
||||
|
||||
@Test
|
||||
public void listTest() {
|
||||
final List<Object> list1 = CollUtil.list(false);
|
||||
final List<Object> list2 = CollUtil.list(true);
|
||||
final List<Object> list1 = ListUtil.list(false);
|
||||
final List<Object> list2 = ListUtil.list(true);
|
||||
|
||||
Assert.assertTrue(list1 instanceof ArrayList);
|
||||
Assert.assertTrue(list2 instanceof LinkedList);
|
||||
@@ -479,8 +479,8 @@ public class CollUtilTest {
|
||||
|
||||
@Test
|
||||
public void listTest2() {
|
||||
final List<String> list1 = CollUtil.list(false, "a", "b", "c");
|
||||
final List<String> list2 = CollUtil.list(true, "a", "b", "c");
|
||||
final List<String> list1 = ListUtil.list(false, "a", "b", "c");
|
||||
final List<String> list2 = ListUtil.list(true, "a", "b", "c");
|
||||
Assert.assertEquals("[a, b, c]", list1.toString());
|
||||
Assert.assertEquals("[a, b, c]", list2.toString());
|
||||
}
|
||||
@@ -492,15 +492,15 @@ public class CollUtilTest {
|
||||
set.add("b");
|
||||
set.add("c");
|
||||
|
||||
final List<String> list1 = CollUtil.list(false, set);
|
||||
final List<String> list2 = CollUtil.list(true, set);
|
||||
final List<String> list1 = ListUtil.list(false, set);
|
||||
final List<String> list2 = ListUtil.list(true, set);
|
||||
Assert.assertEquals("[a, b, c]", list1.toString());
|
||||
Assert.assertEquals("[a, b, c]", list2.toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getTest() {
|
||||
final HashSet<String> set = CollUtil.set(true, "A", "B", "C", "D");
|
||||
final HashSet<String> set = SetUtil.set(true, "A", "B", "C", "D");
|
||||
String str = CollUtil.get(set, 2);
|
||||
Assert.assertEquals("C", str);
|
||||
|
||||
@@ -701,43 +701,43 @@ public class CollUtilTest {
|
||||
|
||||
@Test
|
||||
public void sortPageAllTest() {
|
||||
final List<Integer> list = CollUtil.newArrayList(1, 2, 3, 4, 5, 6, 7, 8, 9);
|
||||
final List<Integer> list = ListUtil.toList(1, 2, 3, 4, 5, 6, 7, 8, 9);
|
||||
final List<Integer> sortPageAll = CollUtil.sortPageAll(1, 5, Comparator.reverseOrder(), list);
|
||||
|
||||
Assert.assertEquals(CollUtil.newArrayList(4, 3, 2, 1), sortPageAll);
|
||||
Assert.assertEquals(ListUtil.toList(4, 3, 2, 1), sortPageAll);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void containsAnyTest() {
|
||||
final ArrayList<Integer> list1 = CollUtil.newArrayList(1, 2, 3, 4, 5);
|
||||
final ArrayList<Integer> list2 = CollUtil.newArrayList(5, 3, 1, 9, 11);
|
||||
final ArrayList<Integer> list1 = ListUtil.toList(1, 2, 3, 4, 5);
|
||||
final ArrayList<Integer> list2 = ListUtil.toList(5, 3, 1, 9, 11);
|
||||
|
||||
Assert.assertTrue(CollUtil.containsAny(list1, list2));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void containsAllTest() {
|
||||
final ArrayList<Integer> list1 = CollUtil.newArrayList(1, 2, 3, 4, 5);
|
||||
final ArrayList<Integer> list2 = CollUtil.newArrayList(5, 3, 1);
|
||||
final ArrayList<Integer> list1 = ListUtil.toList(1, 2, 3, 4, 5);
|
||||
final ArrayList<Integer> list2 = ListUtil.toList(5, 3, 1);
|
||||
Assert.assertTrue(CollUtil.containsAll(list1, list2));
|
||||
|
||||
final ArrayList<Integer> list3 = CollUtil.newArrayList(1);
|
||||
final ArrayList<Integer> list4 = CollUtil.newArrayList();
|
||||
final ArrayList<Integer> list3 = ListUtil.toList(1);
|
||||
final ArrayList<Integer> list4 = ListUtil.toList();
|
||||
Assert.assertTrue(CollUtil.containsAll(list3, list4));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getLastTest() {
|
||||
// 测试:空数组返回null而不是报错
|
||||
final List<String> test = CollUtil.newArrayList();
|
||||
final List<String> test = ListUtil.toList();
|
||||
final String last = CollUtil.getLast(test);
|
||||
Assert.assertNull(last);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void zipTest() {
|
||||
final Collection<String> keys = CollUtil.newArrayList("a", "b", "c", "d");
|
||||
final Collection<Integer> values = CollUtil.newArrayList(1, 2, 3, 4);
|
||||
final Collection<String> keys = ListUtil.toList("a", "b", "c", "d");
|
||||
final Collection<Integer> values = ListUtil.toList(1, 2, 3, 4);
|
||||
|
||||
final Map<String, Integer> map = CollUtil.zip(keys, values);
|
||||
|
||||
@@ -751,7 +751,7 @@ public class CollUtilTest {
|
||||
|
||||
@Test
|
||||
public void toMapTest() {
|
||||
final Collection<String> keys = CollUtil.newArrayList("a", "b", "c", "d");
|
||||
final Collection<String> keys = ListUtil.toList("a", "b", "c", "d");
|
||||
final Map<String, String> map = CollUtil.toMap(keys, new HashMap<>(), (value) -> "key" + value);
|
||||
Assert.assertEquals("a", map.get("keya"));
|
||||
Assert.assertEquals("b", map.get("keyb"));
|
||||
@@ -778,7 +778,7 @@ public class CollUtilTest {
|
||||
|
||||
@Test
|
||||
public void countMapTest() {
|
||||
final ArrayList<String> list = CollUtil.newArrayList("a", "b", "c", "c", "a", "b", "d");
|
||||
final ArrayList<String> list = ListUtil.toList("a", "b", "c", "c", "a", "b", "d");
|
||||
final Map<String, Integer> countMap = CollUtil.countMap(list);
|
||||
|
||||
Assert.assertEquals(Integer.valueOf(2), countMap.get("a"));
|
||||
@@ -789,7 +789,7 @@ public class CollUtilTest {
|
||||
|
||||
@Test
|
||||
public void indexOfTest() {
|
||||
final ArrayList<String> list = CollUtil.newArrayList("a", "b", "c", "c", "a", "b", "d");
|
||||
final ArrayList<String> list = ListUtil.toList("a", "b", "c", "c", "a", "b", "d");
|
||||
final int i = CollUtil.indexOf(list, (str) -> str.charAt(0) == 'c');
|
||||
Assert.assertEquals(2, i);
|
||||
}
|
||||
@@ -797,14 +797,14 @@ public class CollUtilTest {
|
||||
@Test
|
||||
public void lastIndexOfTest() {
|
||||
// List有优化
|
||||
final ArrayList<String> list = CollUtil.newArrayList("a", "b", "c", "c", "a", "b", "d");
|
||||
final ArrayList<String> list = ListUtil.toList("a", "b", "c", "c", "a", "b", "d");
|
||||
final int i = CollUtil.lastIndexOf(list, (str) -> str.charAt(0) == 'c');
|
||||
Assert.assertEquals(3, i);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void lastIndexOfSetTest() {
|
||||
final Set<String> list = CollUtil.set(true, "a", "b", "c", "c", "a", "b", "d");
|
||||
final Set<String> list = SetUtil.set(true, "a", "b", "c", "c", "a", "b", "d");
|
||||
// 去重后c排第三
|
||||
final int i = CollUtil.lastIndexOf(list, (str) -> str.charAt(0) == 'c');
|
||||
Assert.assertEquals(2, i);
|
||||
@@ -812,7 +812,7 @@ public class CollUtilTest {
|
||||
|
||||
@Test
|
||||
public void pageTest() {
|
||||
final List<Dict> objects = CollUtil.newArrayList();
|
||||
final List<Dict> objects = ListUtil.toList();
|
||||
for (int i = 0; i < 10; i++) {
|
||||
objects.add(Dict.create().set("name", "姓名:" + i));
|
||||
}
|
||||
|
||||
@@ -24,13 +24,13 @@ public class IterUtilTest {
|
||||
|
||||
@Test
|
||||
public void getFirstNonNullTest(){
|
||||
final ArrayList<String> strings = CollUtil.newArrayList(null, null, "123", "456", null);
|
||||
final ArrayList<String> strings = ListUtil.toList(null, null, "123", "456", null);
|
||||
Assert.assertEquals("123", IterUtil.getFirstNoneNull(strings));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void fieldValueMapTest() {
|
||||
final ArrayList<Car> carList = CollUtil.newArrayList(new Car("123", "大众"), new Car("345", "奔驰"), new Car("567", "路虎"));
|
||||
final ArrayList<Car> carList = ListUtil.toList(new Car("123", "大众"), new Car("345", "奔驰"), new Car("567", "路虎"));
|
||||
final Map<String, Car> carNameMap = IterUtil.fieldValueMap(carList.iterator(), "carNumber");
|
||||
|
||||
Assert.assertEquals("大众", carNameMap.get("123").getCarName());
|
||||
@@ -40,30 +40,30 @@ public class IterUtilTest {
|
||||
|
||||
@Test
|
||||
public void joinTest() {
|
||||
final ArrayList<String> list = CollUtil.newArrayList("1", "2", "3", "4");
|
||||
final ArrayList<String> list = ListUtil.toList("1", "2", "3", "4");
|
||||
final String join = IterUtil.join(list.iterator(), ":");
|
||||
Assert.assertEquals("1:2:3:4", join);
|
||||
|
||||
final ArrayList<Integer> list1 = CollUtil.newArrayList(1, 2, 3, 4);
|
||||
final ArrayList<Integer> list1 = ListUtil.toList(1, 2, 3, 4);
|
||||
final String join1 = IterUtil.join(list1.iterator(), ":");
|
||||
Assert.assertEquals("1:2:3:4", join1);
|
||||
|
||||
// 包装每个节点
|
||||
final ArrayList<String> list2 = CollUtil.newArrayList("1", "2", "3", "4");
|
||||
final ArrayList<String> list2 = ListUtil.toList("1", "2", "3", "4");
|
||||
final String join2 = IterUtil.join(list2.iterator(), ":", "\"", "\"");
|
||||
Assert.assertEquals("\"1\":\"2\":\"3\":\"4\"", join2);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void joinWithFuncTest() {
|
||||
final ArrayList<String> list = CollUtil.newArrayList("1", "2", "3", "4");
|
||||
final ArrayList<String> list = ListUtil.toList("1", "2", "3", "4");
|
||||
final String join = IterUtil.join(list.iterator(), ":", String::valueOf);
|
||||
Assert.assertEquals("1:2:3:4", join);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void joinWithNullTest() {
|
||||
final ArrayList<String> list = CollUtil.newArrayList("1", null, "3", "4");
|
||||
final ArrayList<String> list = ListUtil.toList("1", null, "3", "4");
|
||||
final String join = IterUtil.join(list.iterator(), ":", String::valueOf);
|
||||
Assert.assertEquals("1:null:3:4", join);
|
||||
}
|
||||
@@ -142,7 +142,7 @@ public class IterUtilTest {
|
||||
|
||||
@Test
|
||||
public void getTest() {
|
||||
final HashSet<String> set = CollUtil.set(true, "A", "B", "C", "D");
|
||||
final HashSet<String> set = SetUtil.set(true, "A", "B", "C", "D");
|
||||
final String str = IterUtil.get(set.iterator(), 2);
|
||||
Assert.assertEquals("C", str);
|
||||
}
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
package cn.hutool.core.convert;
|
||||
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.hutool.core.codec.HexUtil;
|
||||
import cn.hutool.core.collection.SetUtil;
|
||||
import cn.hutool.core.date.DateException;
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import cn.hutool.core.reflect.TypeReference;
|
||||
import cn.hutool.core.map.MapUtil;
|
||||
import cn.hutool.core.reflect.TypeReference;
|
||||
import cn.hutool.core.util.ByteUtil;
|
||||
import cn.hutool.core.codec.HexUtil;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.Getter;
|
||||
@@ -293,7 +293,7 @@ public class ConvertTest {
|
||||
public void toSetTest(){
|
||||
final Set<Integer> result = Convert.convert(new TypeReference<Set<Integer>>() {
|
||||
}, "1,2,3");
|
||||
Assert.assertEquals(CollUtil.set(false, 1,2,3), result);
|
||||
Assert.assertEquals(SetUtil.set(false, 1,2,3), result);
|
||||
}
|
||||
|
||||
@Getter
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package cn.hutool.core.convert;
|
||||
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.hutool.core.collection.ListUtil;
|
||||
import cn.hutool.core.reflect.TypeReference;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
@@ -128,7 +128,7 @@ public class ConvertToCollectionTest {
|
||||
public void toSetTest() {
|
||||
final Object[] a = { "a", "你", "好", "", 1 };
|
||||
final LinkedHashSet<?> set = Convert.convert(LinkedHashSet.class, a);
|
||||
final ArrayList<?> list = CollUtil.newArrayList(set);
|
||||
final ArrayList<?> list = ListUtil.toList(set);
|
||||
Assert.assertEquals("a", list.get(0));
|
||||
Assert.assertEquals("你", list.get(1));
|
||||
Assert.assertEquals("好", list.get(2));
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package cn.hutool.core.date;
|
||||
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.hutool.core.collection.ListUtil;
|
||||
import cn.hutool.core.date.BetweenFormatter.Level;
|
||||
import cn.hutool.core.date.format.FastDateFormat;
|
||||
import cn.hutool.core.lang.Console;
|
||||
@@ -800,13 +800,13 @@ public class DateUtilTest {
|
||||
Assert.assertEquals("20184", yearAndQuarter);
|
||||
|
||||
final LinkedHashSet<String> yearAndQuarters = DateUtil.yearAndQuarter(DateUtil.parse("2018-09-10"), DateUtil.parse("2018-12-20"));
|
||||
final List<String> list = CollUtil.list(false, yearAndQuarters);
|
||||
final List<String> list = ListUtil.list(false, yearAndQuarters);
|
||||
Assert.assertEquals(2, list.size());
|
||||
Assert.assertEquals("20183", list.get(0));
|
||||
Assert.assertEquals("20184", list.get(1));
|
||||
|
||||
final LinkedHashSet<String> yearAndQuarters2 = DateUtil.yearAndQuarter(DateUtil.parse("2018-10-10"), DateUtil.parse("2018-12-10"));
|
||||
final List<String> list2 = CollUtil.list(false, yearAndQuarters2);
|
||||
final List<String> list2 = ListUtil.list(false, yearAndQuarters2);
|
||||
Assert.assertEquals(1, list2.size());
|
||||
Assert.assertEquals("20184", list2.get(0));
|
||||
}
|
||||
|
||||
@@ -1,10 +1,9 @@
|
||||
package cn.hutool.core.lang;
|
||||
|
||||
import cn.hutool.core.collection.ListUtil;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
|
||||
public class WeightRandomTest {
|
||||
|
||||
@Test
|
||||
@@ -15,6 +14,6 @@ public class WeightRandomTest {
|
||||
random.add("C", 100);
|
||||
|
||||
final String result = random.next();
|
||||
Assert.assertTrue(CollUtil.newArrayList("A", "B", "C").contains(result));
|
||||
Assert.assertTrue(ListUtil.toList("A", "B", "C").contains(result));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package cn.hutool.core.text;
|
||||
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.hutool.core.collection.ListUtil;
|
||||
import cn.hutool.core.collection.SetUtil;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
@@ -34,7 +34,7 @@ public class StrJoinerTest {
|
||||
public void joinMultiArrayTest(){
|
||||
final StrJoiner append = StrJoiner.of(",");
|
||||
append.append(new Object[]{ListUtil.of("1", "2"),
|
||||
CollUtil.newLinkedHashSet("3", "4")
|
||||
SetUtil.newLinkedHashSet("3", "4")
|
||||
});
|
||||
Assert.assertEquals("1,2,3,4", append.toString());
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package cn.hutool.core.text.dfa;
|
||||
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.hutool.core.collection.ListUtil;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
@@ -27,7 +27,7 @@ public class DfaTest {
|
||||
// 匹配到【大】,就不再继续匹配了,因此【大土豆】不匹配
|
||||
// 匹配到【刚出锅】,就跳过这三个字了,因此【出锅】不匹配(由于刚首先被匹配,因此长的被匹配,最短匹配只针对第一个字相同选最短)
|
||||
final List<String> matchAll = tree.matchAll(text, -1, false, false);
|
||||
Assert.assertEquals(matchAll, CollUtil.newArrayList("大", "土^豆", "刚出锅"));
|
||||
Assert.assertEquals(matchAll, ListUtil.toList("大", "土^豆", "刚出锅"));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -43,7 +43,7 @@ public class DfaTest {
|
||||
// 【大】被匹配,最短匹配原则【大土豆】被跳过,【土豆继续被匹配】
|
||||
// 【刚出锅】被匹配,由于不跳过已经匹配的词,【出锅】被匹配
|
||||
final List<String> matchAll = tree.matchAll(text, -1, true, false);
|
||||
Assert.assertEquals(matchAll, CollUtil.newArrayList("大", "土^豆", "刚出锅", "出锅"));
|
||||
Assert.assertEquals(matchAll, ListUtil.toList("大", "土^豆", "刚出锅", "出锅"));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -59,7 +59,7 @@ public class DfaTest {
|
||||
// 匹配到【大】,由于非密集匹配,因此从下一个字符开始查找,匹配到【土豆】接着被匹配
|
||||
// 由于【刚出锅】被匹配,由于非密集匹配,【出锅】被跳过
|
||||
final List<String> matchAll = tree.matchAll(text, -1, false, true);
|
||||
Assert.assertEquals(matchAll, CollUtil.newArrayList("大", "土^豆", "刚出锅"));
|
||||
Assert.assertEquals(matchAll, ListUtil.toList("大", "土^豆", "刚出锅"));
|
||||
|
||||
}
|
||||
|
||||
@@ -76,7 +76,7 @@ public class DfaTest {
|
||||
// 匹配到【大】,由于到最长匹配,因此【大土豆】接着被匹配,由于不跳过已经匹配的关键词,土豆继续被匹配
|
||||
// 【刚出锅】被匹配,由于不跳过已经匹配的词,【出锅】被匹配
|
||||
final List<String> matchAll = tree.matchAll(text, -1, true, true);
|
||||
Assert.assertEquals(matchAll, CollUtil.newArrayList("大", "大土^豆", "土^豆", "刚出锅", "出锅"));
|
||||
Assert.assertEquals(matchAll, ListUtil.toList("大", "大土^豆", "土^豆", "刚出锅", "出锅"));
|
||||
|
||||
}
|
||||
|
||||
@@ -112,7 +112,7 @@ public class DfaTest {
|
||||
tree.addWord("tio");
|
||||
|
||||
final List<String> all = tree.matchAll("AAAAAAAt-ioBBBBBBB");
|
||||
Assert.assertEquals(all, CollUtil.newArrayList("t-io"));
|
||||
Assert.assertEquals(all, ListUtil.toList("t-io"));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -1,10 +1,6 @@
|
||||
package cn.hutool.core.tree;
|
||||
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.hutool.core.tree.Tree;
|
||||
import cn.hutool.core.tree.TreeNode;
|
||||
import cn.hutool.core.tree.TreeNodeConfig;
|
||||
import cn.hutool.core.tree.TreeUtil;
|
||||
import cn.hutool.core.collection.ListUtil;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
@@ -18,7 +14,7 @@ import java.util.List;
|
||||
*/
|
||||
public class TreeTest {
|
||||
// 模拟数据
|
||||
static List<TreeNode<String>> nodeList = CollUtil.newArrayList();
|
||||
static List<TreeNode<String>> nodeList = ListUtil.toList();
|
||||
|
||||
static {
|
||||
// 模拟数据
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package cn.hutool.core.util;
|
||||
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.hutool.core.collection.ListUtil;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
@@ -323,7 +323,7 @@ public class ArrayUtilTest {
|
||||
|
||||
@Test
|
||||
public void toArrayTest() {
|
||||
final ArrayList<String> list = CollUtil.newArrayList("A", "B", "C", "D");
|
||||
final ArrayList<String> list = ListUtil.toList("A", "B", "C", "D");
|
||||
final String[] array = ArrayUtil.toArray(list, String.class);
|
||||
Assert.assertEquals("A", array[0]);
|
||||
Assert.assertEquals("B", array[1]);
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package cn.hutool.core.util;
|
||||
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.hutool.core.collection.ListUtil;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
@@ -18,13 +18,13 @@ public class EnumUtilTest {
|
||||
@Test
|
||||
public void getNamesTest() {
|
||||
final List<String> names = EnumUtil.getNames(TestEnum.class);
|
||||
Assert.assertEquals(CollUtil.newArrayList("TEST1", "TEST2", "TEST3"), names);
|
||||
Assert.assertEquals(ListUtil.toList("TEST1", "TEST2", "TEST3"), names);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getFieldValuesTest() {
|
||||
final List<Object> types = EnumUtil.getFieldValues(TestEnum.class, "type");
|
||||
Assert.assertEquals(CollUtil.newArrayList("type1", "type2", "type3"), types);
|
||||
Assert.assertEquals(ListUtil.toList("type1", "type2", "type3"), types);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package cn.hutool.core.util;
|
||||
|
||||
import cn.hutool.core.clone.CloneSupport;
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.hutool.core.collection.ListUtil;
|
||||
import cn.hutool.core.date.DatePattern;
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import org.junit.Assert;
|
||||
@@ -58,7 +58,7 @@ public class ObjectUtilTest {
|
||||
|
||||
@Test
|
||||
public void toStringTest() {
|
||||
final ArrayList<String> strings = CollUtil.newArrayList("1", "2");
|
||||
final ArrayList<String> strings = ListUtil.toList("1", "2");
|
||||
final String result = ObjUtil.toString(strings);
|
||||
Assert.assertEquals("[1, 2]", result);
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package cn.hutool.core.util;
|
||||
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.hutool.core.collection.ListUtil;
|
||||
import cn.hutool.core.lang.Console;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Ignore;
|
||||
@@ -15,13 +15,13 @@ public class RandomUtilTest {
|
||||
|
||||
@Test
|
||||
public void randomEleSetTest(){
|
||||
final Set<Integer> set = RandomUtil.randomEleSet(CollUtil.newArrayList(1, 2, 3, 4, 5, 6), 2);
|
||||
final Set<Integer> set = RandomUtil.randomEleSet(ListUtil.toList(1, 2, 3, 4, 5, 6), 2);
|
||||
Assert.assertEquals(set.size(), 2);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void randomElesTest(){
|
||||
final List<Integer> result = RandomUtil.randomEles(CollUtil.newArrayList(1, 2, 3, 4, 5, 6), 2);
|
||||
final List<Integer> result = RandomUtil.randomEles(ListUtil.toList(1, 2, 3, 4, 5, 6), 2);
|
||||
Assert.assertEquals(result.size(), 2);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package cn.hutool.core.util;
|
||||
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.hutool.core.collection.ListUtil;
|
||||
import cn.hutool.core.lang.Console;
|
||||
import cn.hutool.core.regex.PatternPool;
|
||||
import cn.hutool.core.regex.ReUtil;
|
||||
@@ -82,7 +82,7 @@ public class ReUtilTest {
|
||||
public void findAllTest() {
|
||||
// 查找所有匹配文本
|
||||
final List<String> resultFindAll = ReUtil.findAll("\\w{2}", content, 0, new ArrayList<>());
|
||||
final ArrayList<String> expected = CollUtil.newArrayList("ZZ", "Za", "aa", "bb", "bc", "cc", "12", "34");
|
||||
final ArrayList<String> expected = ListUtil.toList("ZZ", "Za", "aa", "bb", "bc", "cc", "12", "34");
|
||||
Assert.assertEquals(expected, resultFindAll);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
package cn.hutool.core.util;
|
||||
|
||||
import cn.hutool.core.bean.BeanUtil;
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.hutool.core.collection.ListUtil;
|
||||
import cn.hutool.core.collection.SetUtil;
|
||||
import cn.hutool.core.io.resource.ResourceUtil;
|
||||
import cn.hutool.core.lang.Console;
|
||||
import cn.hutool.core.map.MapBuilder;
|
||||
@@ -109,7 +110,7 @@ public class XmlUtilTest {
|
||||
final Map<String, Object> map = XmlUtil.xmlToMap(xml);
|
||||
|
||||
Assert.assertEquals(1, map.size());
|
||||
Assert.assertEquals(CollUtil.newArrayList("张三", "李四"), map.get("name"));
|
||||
Assert.assertEquals(ListUtil.toList("张三", "李四"), map.get("name"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -137,7 +138,7 @@ public class XmlUtilTest {
|
||||
public void mapToXmlTest2() {
|
||||
// 测试List
|
||||
final Map<String, Object> map = MapBuilder.create(new LinkedHashMap<String, Object>())
|
||||
.put("Town", CollUtil.newArrayList("town1", "town2"))
|
||||
.put("Town", ListUtil.toList("town1", "town2"))
|
||||
.build();
|
||||
|
||||
final Document doc = XmlUtil.mapToXml(map, "City");
|
||||
@@ -157,7 +158,7 @@ public class XmlUtilTest {
|
||||
|
||||
@Test
|
||||
public void readBySaxTest(){
|
||||
final Set<String> eles = CollUtil.newHashSet(
|
||||
final Set<String> eles = SetUtil.newHashSet(
|
||||
"returnsms", "returnstatus", "message", "remainpoint", "taskID", "successCounts");
|
||||
XmlUtil.readBySax(ResourceUtil.getStream("test.xml"), new DefaultHandler(){
|
||||
@Override
|
||||
|
||||
Reference in New Issue
Block a user