Update hutool-core/src/main/java/cn/hutool/core/tree/BeanTree.java

This commit is contained in:
emptypoint 2022-11-28 08:54:26 +00:00 committed by Gitee
parent ce576a1d33
commit f1f741bb58
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F

View File

@ -120,10 +120,13 @@ public class BeanTree<T, R extends Comparable<R>> {
* @return 转换后的树
*/
public List<T> toTree(final List<T> list) {
if (CollUtil.isEmpty(list)) {
return ListUtil.zero();
}
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);
).group(pidGetter);
final List<T> parents = pIdValuesMap.getOrDefault(pidValue, new ArrayList<>());
findChildren(list, pIdValuesMap);
return parents;