KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > tonbeller > wcf > tree > N


1 /*
2  * Created on 17.10.2003
3  *
4  * To change the template for this generated file go to
5  * Window>Preferences>Java>Code Generation>Code and Comments
6  */

7 package com.tonbeller.wcf.tree;
8
9 import java.util.ArrayList JavaDoc;
10 import java.util.Iterator JavaDoc;
11
12 class N {
13   String JavaDoc label;
14   N parent;
15   ArrayList JavaDoc children = new ArrayList JavaDoc();
16
17   N(String JavaDoc label) {
18     this.label = label;
19   }
20
21   N(String JavaDoc 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 JavaDoc toString() {
34     StringBuffer JavaDoc sb = new StringBuffer JavaDoc();
35     sb.append(label);
36     if (children.size() > 0) {
37       sb.append("[");
38       for (Iterator JavaDoc 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   /**
50    * @return
51    */

52   public ArrayList JavaDoc getChildren() {
53     return children;
54   }
55
56   /**
57    * @return
58    */

59   public String JavaDoc getLabel() {
60     return label;
61   }
62
63   /**
64    * @return
65    */

66   public N getParent() {
67     return parent;
68   }
69
70 }
Popular Tags