1 7 package com.tonbeller.wcf.tree; 8 9 import java.util.ArrayList ; 10 import java.util.Iterator ; 11 12 class N { 13 String label; 14 N parent; 15 ArrayList children = new ArrayList (); 16 17 N(String label) { 18 this.label = label; 19 } 20 21 N(String label, N left, N right) { 22 this.label = label; 23 if (left != null) { 24 left.parent = this; 25 children.add(left); 26 } 27 if (right != null) { 28 right.parent = this; 29 children.add(right); 30 } 31 } 32 33 public String toString() { 34 StringBuffer sb = new StringBuffer (); 35 sb.append(label); 36 if (children.size() > 0) { 37 sb.append("["); 38 for (Iterator it = children.iterator(); it.hasNext();) { 39 N n = (N) it.next(); 40 sb.append(n.toString()); 41 if (it.hasNext()) 42 sb.append(","); 43 } 44 sb.append("]"); 45 } 46 return sb.toString(); 47 } 48 49 52 public ArrayList getChildren() { 53 return children; 54 } 55 56 59 public String getLabel() { 60 return label; 61 } 62 63 66 public N getParent() { 67 return parent; 68 } 69 70 } | Popular Tags |