mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-05-09 23:51:34 +08:00
Update hutool-core/src/main/java/cn/hutool/core/tree/BeanTree.java
This commit is contained in:
parent
ce576a1d33
commit
f1f741bb58
@ -120,10 +120,13 @@ public class BeanTree<T, R extends Comparable<R>> {
|
|||||||
* @return 转换后的树
|
* @return 转换后的树
|
||||||
*/
|
*/
|
||||||
public List<T> toTree(final List<T> list) {
|
public List<T> toTree(final List<T> list) {
|
||||||
if (Objects.isNull(parentPredicate)) {
|
if (CollUtil.isEmpty(list)) {
|
||||||
final Map<R, List<T>> pIdValuesMap = EasyStream.of(list)
|
return ListUtil.zero();
|
||||||
.peek(e -> Objects.requireNonNull(idGetter.apply(e), "The id of tree node must not be null")
|
}
|
||||||
)).group(pidGetter);
|
if (Objects.isNull(parentPredicate)) {
|
||||||
|
final Map<R, List<T>> pIdValuesMap = EasyStream.of(list)
|
||||||
|
.peek(e -> Objects.requireNonNull(idGetter.apply(e), "The id of tree node must not be null")
|
||||||
|
).group(pidGetter);
|
||||||
final List<T> parents = pIdValuesMap.getOrDefault(pidValue, new ArrayList<>());
|
final List<T> parents = pIdValuesMap.getOrDefault(pidValue, new ArrayList<>());
|
||||||
findChildren(list, pIdValuesMap);
|
findChildren(list, pIdValuesMap);
|
||||||
return parents;
|
return parents;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user