package com.qianwen.core.tool.node; import com.google.common.collect.ImmutableMap; import com.google.common.collect.Maps; import java.util.ArrayList; import java.util.List; import java.util.Map; import com.qianwen.core.tool.node.INode; import com.qianwen.core.tool.utils.StringPool; /* loaded from: blade-core-tool-9.3.0.0-SNAPSHOT.jar:org/springblade/core/tool/node/ForestNodeManager.class */ public class ForestNodeManager> { private final ImmutableMap nodeMap; private final Map parentIdMap = Maps.newHashMap(); public ForestNodeManager(List nodes) { this.nodeMap = Maps.uniqueIndex(nodes, (v0) -> { return v0.getId(); }); } public INode getTreeNodeAt(Long id) { if (this.nodeMap.containsKey(id)) return (INode) this.nodeMap.get(id); return null; } public void addParentId(Long parentId) { this.parentIdMap.put(parentId, StringPool.EMPTY); } public List getRoot() { List roots = new ArrayList<>(); this.nodeMap.forEach((key, node) -> { if (node.getParentId().longValue() == 0L || this.parentIdMap.containsKey(node.getId())) roots.add(node); }); return roots; } }