NodeUtils

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;
  }
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值