package com.auth.common.tree;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import com.auth.entity.Function;
public class Tree {
private List<Node> nodes=new LinkedList();
private Node root=null;
public Tree(List<Function> functions){
for(Function function:functions){
Node node=new Node(function.getId(),function.getParentId(),function.getName(),"open",new NodeAttribute(null==function.getUrl()?"":function.getUrl(),function.getId()),function.getSerialNum());
nodes.add(node);
if(node.getParentId()==-1){//菜单树根节点
root=node;
}
}
}
public List<Node> build(){
buildTree(root);
List<Node> result=new ArrayList<Node>();
result.add(root);
return result;
}
public void buildTree(Node parent){
Node node=null;
for(Iterator<Node> ite=nodes.iterator();ite.hasNext();){
node=ite.next();
if(node.getParentId()!=null && node.getParentId().equals(parent.getId())){
parent.getChildren().add(node);
buildTree(node);
}
}
}
}
最近下载更多
xiaoaitx LV8
1月2日
lxzlxzl LV1
2024年6月21日
xhqxhq LV1
2024年6月6日
yangxinyullll LV1
2024年4月28日
微信网友_6512020493586432 LV2
2024年4月8日
xiongM LV4
2024年4月4日
wangsheng818 LV4
2024年2月28日
马宇轩 LV1
2023年11月19日
泓鼎168 LV20
2023年10月16日
1257592068 LV6
2023年6月6日

最近浏览