예제 #1
0
 /**
  * 查找以name为value的祖先节点
  *
  * @param name 查找条件
  * @return 如果找到则返回treenode找不到则返回null
  */
 public TreeNode findAncestor(String name) {
   TreeNode cur = this;
   if (cur.getName() == null || cur.getName().equals("")) return null;
   if (cur.getName().equals(name)) return cur;
   while (cur.getParent() != null) {
     cur = cur.getParent();
     if (cur.getName().equals(name)) return cur;
   }
   return null;
 }
예제 #2
0
 /** 输出当前节点的所有子节点 */
 public void printChildrenName() {
   List<TreeNode> children = this.getChildren();
   if (children != null) {
     for (TreeNode child : children) {
       System.out.print(child.getName() + " ");
     }
   } else {
     System.out.print("null");
   }
 }
예제 #3
0
 /**
  * 查找以name为value的子节点
  *
  * @param name 查找条件
  * @return 如果找到则返回treenode找不到则返回null
  */
 public TreeNode findChild(String name) {
   List<TreeNode> children = this.getChildren();
   if (children != null) {
     for (TreeNode child : children) {
       if (child.getName().equals(name)) {
         return child;
       }
     }
   }
   return null;
 }