From aebd66d0593704ce53a8ba0fde28fc8b272638f0 Mon Sep 17 00:00:00 2001 From: ZhouXY108 Date: Mon, 26 Aug 2024 17:37:30 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=20TreeBuilder#buildTreeInter?= =?UTF-8?q?nal=20=E4=B8=AD=E7=9A=84=E5=B1=80=E9=83=A8=E5=8F=98=E9=87=8F?= =?UTF-8?q?=E5=90=8D=EF=BC=8C=E4=BE=BF=E4=BA=8E=E7=90=86=E8=A7=A3=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/xyz/zhouxy/plusone/commons/util/TreeBuilder.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) 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; } }