mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-07-21 15:09:48 +08:00
@@ -17,6 +17,8 @@
|
||||
package org.dromara.hutool.core.stream;
|
||||
|
||||
import org.dromara.hutool.core.collection.ListUtil;
|
||||
import org.dromara.hutool.core.lang.tuple.Pair;
|
||||
import org.dromara.hutool.core.lang.tuple.Triple;
|
||||
import org.dromara.hutool.core.map.MapUtil;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
@@ -135,4 +137,43 @@ public class CollectorUtilTest {
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testToPairList() {
|
||||
final List<Pair<Integer,String>> list = Arrays.asList(Pair.of(1,"one"), Pair.of(2,"two"));
|
||||
Pair<List<Integer>, List<String>> pairList = list.stream()
|
||||
.collect(CollectorUtil.toPairList(Pair::getLeft, Pair::getRight));
|
||||
|
||||
Assertions.assertEquals(pairList.getLeft().size(),list.size());
|
||||
Assertions.assertEquals(pairList.getRight().size(),list.size());
|
||||
|
||||
Pair<HashSet<Integer>, ArrayList<String>> pairMixed = list.stream()
|
||||
.collect(CollectorUtil.toPairCollection(Pair::getLeft, Pair::getRight, HashSet::new, ArrayList::new));
|
||||
|
||||
Assertions.assertEquals(pairMixed.getLeft().size(),list.size());
|
||||
Assertions.assertEquals(pairMixed.getRight().size(),list.size());
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testToTripleList() {
|
||||
final List<Triple<Integer,Long,String>> list
|
||||
= Arrays.asList(Triple.of(1,1L,"one"), Triple.of(2,2L,"two"));
|
||||
Triple<List<Integer>, List<Long>, List<String>> tripleList = list.stream()
|
||||
.collect(CollectorUtil.toTripleList(Triple::getLeft, Triple::getMiddle, Triple::getRight));
|
||||
|
||||
Assertions.assertEquals(tripleList.getLeft().size(),list.size());
|
||||
Assertions.assertEquals(tripleList.getMiddle().size(),list.size());
|
||||
Assertions.assertEquals(tripleList.getRight().size(),list.size());
|
||||
|
||||
Triple<HashSet<Integer>, HashSet<Long>, ArrayList<String>> tripleMixed = list.stream()
|
||||
.collect(CollectorUtil.toTripleCollection(Triple::getLeft, Triple::getMiddle, Triple::getRight, HashSet::new, HashSet::new, ArrayList::new));
|
||||
|
||||
Assertions.assertEquals(tripleMixed.getLeft().size(),list.size());
|
||||
Assertions.assertEquals(tripleMixed.getMiddle().size(),list.size());
|
||||
Assertions.assertEquals(tripleMixed.getRight().size(),list.size());
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user