mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-07-21 15:09:48 +08:00
feat: CollUtil add groupByFunc
This commit is contained in:
@@ -427,6 +427,26 @@ public class CollUtilTest {
|
||||
Assert.assertEquals("李四", groupByField.get(1).get(0).getName());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void groupByFuncTest() {
|
||||
final List<TestBean> list = ListUtil.of(new TestBean("张三", 12), new TestBean("李四", 13), new TestBean("王五", 12));
|
||||
final List<List<TestBean>> groupByField = CollUtil.groupByFunc(list, TestBean::getAge);
|
||||
Assert.assertEquals("张三", groupByField.get(0).get(0).getName());
|
||||
Assert.assertEquals("王五", groupByField.get(0).get(1).getName());
|
||||
|
||||
Assert.assertEquals("李四", groupByField.get(1).get(0).getName());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void groupByFunc2Test() {
|
||||
final List<TestBean> list = ListUtil.of(new TestBean("张三", 12), new TestBean("李四", 13), new TestBean("王五", 12));
|
||||
final List<List<TestBean>> groupByField = CollUtil.groupByFunc(list, a -> a.getAge() > 12);
|
||||
Assert.assertEquals("张三", groupByField.get(0).get(0).getName());
|
||||
Assert.assertEquals("王五", groupByField.get(0).get(1).getName());
|
||||
|
||||
Assert.assertEquals("李四", groupByField.get(1).get(0).getName());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void sortByPropertyTest() {
|
||||
final List<TestBean> list = ListUtil.of(
|
||||
@@ -854,7 +874,7 @@ public class CollUtilTest {
|
||||
|
||||
final List<Long> result = CollUtil.subtractToList(list1, list2);
|
||||
Assert.assertEquals(1, result.size());
|
||||
Assert.assertEquals(1L, (long)result.get(0));
|
||||
Assert.assertEquals(1L, (long) result.get(0));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
Reference in New Issue
Block a user