mirror of
https://gitee.com/dromara/hutool.git
synced 2025-04-24 18:04:54 +08:00
:trollface: 递归改为遍历
This commit is contained in:
parent
e81585d7d0
commit
0dda333b07
@ -1,7 +1,6 @@
|
|||||||
package cn.hutool.core.stream;
|
package cn.hutool.core.stream;
|
||||||
|
|
||||||
import cn.hutool.core.lang.Opt;
|
import cn.hutool.core.lang.Opt;
|
||||||
import cn.hutool.core.lang.mutable.MutableObj;
|
|
||||||
import cn.hutool.core.text.StrUtil;
|
import cn.hutool.core.text.StrUtil;
|
||||||
import cn.hutool.core.util.ArrayUtil;
|
import cn.hutool.core.util.ArrayUtil;
|
||||||
|
|
||||||
@ -481,18 +480,14 @@ public class CollectorUtil {
|
|||||||
final BiConsumer<T, List<T>> childrenSetter,
|
final BiConsumer<T, List<T>> childrenSetter,
|
||||||
final boolean isParallel) {
|
final boolean isParallel) {
|
||||||
return pIdValuesMap -> {
|
return pIdValuesMap -> {
|
||||||
final MutableObj<Consumer<List<T>>> recursiveRef = new MutableObj<>();
|
EasyStream.of(pIdValuesMap.values(), isParallel).flat(Function.identity())
|
||||||
final Consumer<List<T>> recursive = parents -> EasyStream.of(parents, isParallel).forEach(parent -> {
|
.forEach(value -> {
|
||||||
final List<T> children = pIdValuesMap.get(idGetter.apply(parent));
|
final List<T> children = pIdValuesMap.get(idGetter.apply(value));
|
||||||
childrenSetter.accept(parent, children);
|
if (children != null) {
|
||||||
recursiveRef.get().accept(children);
|
childrenSetter.accept(value, children);
|
||||||
});
|
}
|
||||||
final List<T> parents = parentFactory.apply(pIdValuesMap);
|
});
|
||||||
if (false == parents.isEmpty()) {
|
return parentFactory.apply(pIdValuesMap);
|
||||||
recursiveRef.set(recursive);
|
|
||||||
recursiveRef.get().accept(parents);
|
|
||||||
}
|
|
||||||
return parents;
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user