diff --git a/src/main/java/xyz/zhouxy/plusone/commons/util/TreeBuilder.java b/src/main/java/xyz/zhouxy/plusone/commons/util/TreeBuilder.java index 684fb21..d2c180c 100644 --- a/src/main/java/xyz/zhouxy/plusone/commons/util/TreeBuilder.java +++ b/src/main/java/xyz/zhouxy/plusone/commons/util/TreeBuilder.java @@ -88,7 +88,8 @@ public class TreeBuilder { final Map identityNodeMap = allNodes.stream() .collect(Collectors.toMap(identityGetter, Function.identity(), (n1, n2) -> n1)); - final List result = allNodes.stream() + // 根节点 + final List rootNodes = allNodes.stream() .filter(node -> !this.parentIdentityGetter.apply(node).isPresent()) .collect(Collectors.toList()); allNodes.forEach(node -> parentIdentityGetter.apply(node).ifPresent(parentIdentity -> { @@ -98,6 +99,6 @@ public class TreeBuilder { addChildMethod.accept(parentNode, node); } })); - return result; + return rootNodes; } }