mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-05-09 23:51:34 +08:00
分流收集器收集方式从固定Collection改为自定义收集器,可以自定义如何收集元素
This commit is contained in:
parent
49e9ede07b
commit
3658d9f7ca
@ -489,7 +489,6 @@ public class CollectorUtil {
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 将一个{@code Collection<T>}两个属性分流至两个Collection,并使用Pair收集。
|
||||
*
|
||||
@ -527,14 +526,14 @@ public class CollectorUtil {
|
||||
rDownstream.combiner().apply(listPair1.getRight(), listPair2.getRight())),
|
||||
|
||||
finisherPair -> {
|
||||
LR finisherLeftValue;
|
||||
final LR finisherLeftValue;
|
||||
if (lDownstream.characteristics().contains(Collector.Characteristics.IDENTITY_FINISH)) {
|
||||
finisherLeftValue = (LR) finisherPair.getLeft();
|
||||
} else {
|
||||
finisherLeftValue = lDownstream.finisher().apply(finisherPair.getLeft());
|
||||
}
|
||||
|
||||
RR finisherRightValue;
|
||||
final RR finisherRightValue;
|
||||
if (lDownstream.characteristics().contains(Collector.Characteristics.IDENTITY_FINISH)) {
|
||||
finisherRightValue = (RR) finisherPair.getRight();
|
||||
} else {
|
||||
@ -568,7 +567,6 @@ public class CollectorUtil {
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 将一个{@code Collection<T>}两个属性分流至两个Collection,并使用Pair收集。
|
||||
*
|
||||
@ -576,6 +574,7 @@ public class CollectorUtil {
|
||||
* @param mMapper 中元素收集方法
|
||||
* @param rMapper 右元素收集方法
|
||||
* @param lDownstream 左元素下游操作
|
||||
* @param mDownstream 中元素下游操作
|
||||
* @param rDownstream 右元素下游操作
|
||||
* @param <T> 元素类型
|
||||
* @param <LU> 左属性类型
|
||||
@ -614,21 +613,21 @@ public class CollectorUtil {
|
||||
rDownstream.combiner().apply(listTriple1.getRight(), listTriple2.getRight())),
|
||||
|
||||
finisherTriple -> {
|
||||
LR finisherLeftValue;
|
||||
final LR finisherLeftValue;
|
||||
if (lDownstream.characteristics().contains(Collector.Characteristics.IDENTITY_FINISH)) {
|
||||
finisherLeftValue = (LR) finisherTriple.getLeft();
|
||||
} else {
|
||||
finisherLeftValue = lDownstream.finisher().apply(finisherTriple.getLeft());
|
||||
}
|
||||
|
||||
MR finisherMiddleValue;
|
||||
final MR finisherMiddleValue;
|
||||
if (mDownstream.characteristics().contains(Collector.Characteristics.IDENTITY_FINISH)) {
|
||||
finisherMiddleValue = (MR) finisherTriple.getMiddle();
|
||||
} else {
|
||||
finisherMiddleValue = mDownstream.finisher().apply(finisherTriple.getMiddle());
|
||||
}
|
||||
|
||||
RR finisherRightValue;
|
||||
final RR finisherRightValue;
|
||||
if (lDownstream.characteristics().contains(Collector.Characteristics.IDENTITY_FINISH)) {
|
||||
finisherRightValue = (RR) finisherTriple.getRight();
|
||||
} else {
|
||||
|
@ -167,7 +167,7 @@ public class CollectorUtilTest {
|
||||
Assertions.assertEquals(list.size(),tripleList.getMiddle().size());
|
||||
Assertions.assertEquals(list.size(),tripleList.getRight().size());
|
||||
|
||||
Triple<Integer, List<Long>, String> tripleMixed = list.stream()
|
||||
final Triple<Integer, List<Long>, String> tripleMixed = list.stream()
|
||||
.collect(CollectorUtil.toTriple(Triple::getLeft, Triple::getMiddle, Triple::getRight,
|
||||
Collectors.summingInt(s->s), Collectors.toList(), Collectors.joining()));
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user