1、NodeUtils类
public class NodeUtils
{
public static <T extends Node> T find(Collection<T> trees, String path)
{
for (Node t : trees) {
if (path.equals(t.getPath())) {
return t;
}
if ((t.getChildren() != null) && (t.getChildren().size() > 0))
{
Node childNode = find(t.getChildren(), path);
if (childNode != null) {
return childNode;
}
}
}
return null;
}
public static <T extends Node> List<T> convertToTrees(Collection<T> trees)
{
if (trees == null) {
return Collections.EMPTY_LIST;
}
List rootTrees = new ArrayList();
for (Iterator i$ = trees.iterator(); i$.hasNext(); ) { tree = (Node)i$.next();
if ((tree.getParentId() == null) || (!hasParent(trees, tree.getParentId()))) {
rootTrees.add(tree);
}
for (Node t : trees)
if ((t.getParentId() != null) && (tree.getId().equals(t.getParentId())))
tree.addChild(t);
}
Node tree;
return rootTrees;
}
private static <T extends Node> boolean hasParent(Collection<T> trees, String parentId)
{
for (Node t : trees) {
if (parentId.equals(t.getId())) {
return true;
}
}
return false;
}
}
2、Node类
import com.alibaba.fastjson.JSONObject;
import java.util.ArrayList;
import java.util.Collection;
public class Node extends BaseJsonObject
{
private String id;
private String name;
@Deprecated
private String nodeType;
private String parentId;
private Collection<Node> children;
private String path;
public String getId()
{
return this.id;
}
public void setId(String id) {
this.id = id;
}
public String getName() {
return this.name;
}
public void setName(String name) {
this.name = name;
}
@Deprecated
public String getNodeType() {
return this.nodeType;
}
@Deprecated
public void setNodeType(String nodeType) {
this.nodeType = nodeType;
}
public String getParentId() {
return this.parentId;
}
public void setParentId(String parentId) {
this.parentId = parentId;
}
public Collection<Node> getChildren() {
return this.children;
}
public void setChildren(Collection<Node> children) {
this.children = children;
}
public String getPath() {
return this.path;
}
public void setPath(String path) {
this.path = path;
}
public void addChild(Node t) {
synchronized (this) {
if (this.children == null) {
this.children = new ArrayList();
}
this.children.add(t);
}
}
public JSONObject toJsonObject()
throws Exception
{
throw new Exception();
}
3、NodeAttribute类
import java.util.Date;
@Deprecated
public class NodeAttribute
{
private String id;
private String NodeId;
private String attributeType;
private String attributeValue;
private String attributeDesc;
private String createdBy;
private Date createdDate;
private String updatedBy;
private Date updatedDate;
public String getId()
{
return this.id;
}
public void setId(String id) {
this.id = id;
}
public String getNodeId() {
return this.NodeId;
}
public void setNodeId(String nodeId) {
this.NodeId = nodeId;
}
public String getAttributeType() {
return this.attributeType;
}
public void setAttributeType(String attributeType) {
this.attributeType = attributeType;
}
public String getAttributeValue() {
return this.attributeValue;
}
public void setAttributeValue(String attributeValue) {
this.attributeValue = attributeValue;
}
public String getAttributeDesc() {
return this.attributeDesc;
}
public void setAttributeDesc(String attributeDesc) {
this.attributeDesc = attributeDesc;
}
public String getCreatedBy() {
return this.createdBy;
}
public void setCreatedBy(String createdBy) {
this.createdBy = createdBy;
}
public Date getCreatedDate() {
return this.createdDate;
}
public void setCreatedDate(Date createdDate) {
this.createdDate = createdDate;
}
public String getUpdatedBy() {
return this.updatedBy;
}
public void setUpdatedBy(String updatedBy) {
this.updatedBy = updatedBy;
}
public Date getUpdatedDate() {
return this.updatedDate;
}
public void setUpdatedDate(Date updatedDate) {
this.updatedDate = updatedDate;
}
}