1 package org.catacomb.druid.util.tree; 2 3 4 import org.catacomb.interlish.structure.TreeNode; 5 6 import java.util.ArrayList; 7 8 9 public class ArrayListNode implements TreeNode { 10 11 12 public ArrayList<TreeNode> children; 13 14 String name; 15 16 Object parent; 17 18 public ArrayListNode(Object p, String sn) { 19 name = sn; 20 children = new ArrayList<TreeNode>(); 21 parent = p; 22 } 23 24 25 public Object getParent() { 26 return parent; 27 } 28 29 public String toString() { 30 return name; 31 } 32 33 34 35 public void setChildren(ArrayList<? extends TreeNode> arl) { 36 children.clear(); 37 children.addAll(arl); 38 } 39 40 41 public void clearChildren() { 42 children.clear(); 43 } 44 45 46 public void addChild(ArrayListNode arn) { 47 children.add(arn); 48 } 49 50 51 public void removeChild(ArrayListNode arn) { 52 children.remove(arn); 53 } 54 55 56 public boolean hasChildren() { 57 return (!(children.isEmpty())); 58 } 59 60 61 62 public int getChildCount() { 63 return children.size(); 64 } 65 66 public Object getChild(int index) { 67 return children.get(index); 68 } 69 70 public int getIndexOfChild(Object child) { 71 return children.indexOf(child); 72 } 73 74 public boolean isLeaf() { 75 return (children == null || children.size() == 0); 76 } 77 78 }