mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-07-21 15:09:48 +08:00
!479 新增CollStreamUtil.groupKeyValue(java.util.Collection<E>, java.util.function.Function<E,K>, java.util.function.Function<E,V>),用于分组后能直接获取属性
Merge pull request !479 from 阿超/v5-dev
This commit is contained in:
@@ -149,6 +149,26 @@ public class CollStreamUtilTest {
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGroupKeyValue() {
|
||||
Map<Long, List<Long>> map = CollStreamUtil.groupKeyValue(null, Student::getTermId, Student::getClassId);
|
||||
Assert.assertEquals(map, Collections.EMPTY_MAP);
|
||||
|
||||
List<Student> list = new ArrayList<>();
|
||||
map = CollStreamUtil.groupKeyValue(list, Student::getTermId, Student::getClassId);
|
||||
Assert.assertEquals(map, Collections.EMPTY_MAP);
|
||||
list.add(new Student(1, 1, 1, "张三"));
|
||||
list.add(new Student(1, 2, 1, "李四"));
|
||||
list.add(new Student(2, 2, 1, "王五"));
|
||||
map = CollStreamUtil.groupKeyValue(list, Student::getTermId, Student::getClassId);
|
||||
|
||||
Map<Long, List<Long>> compare = new HashMap<>();
|
||||
compare.put(1L, Arrays.asList(1L, 2L));
|
||||
compare.put(2L, Collections.singletonList(2L));
|
||||
Assert.assertEquals(compare, map);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testTranslate2List() {
|
||||
List<String> list = CollStreamUtil.toList(null, Student::getName);
|
||||
|
Reference in New Issue
Block a user