1 /***
2 * The contents of this file are subject to the Mozilla Public
3 * License Version 1.1 (the "License"); you may not use this file
4 * except in compliance with the License. You may obtain a copy of
5 * the License at http://www.mozilla.org/MPL/
6 *
7 * Software distributed under the License is distributed on an "AS
8 * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
9 * implied. See the License for the specific language governing
10 * rights and limitations under the License.
11 *
12 * The Original Code is pow2toolkit library.
13 *
14 * The Initial Owner of the Original Code is
15 * particle (www.theparticle.com)
16 *
17 * Portions created by Power Of Two S.R.L. are
18 * Copyright (C) Power Of Two S.R.L.
19 * All Rights Reserved.
20 *
21 * Contributor(s):
22 */
23
24 package com.pow2.structures.tree;
25
26
27 /***
28 * Tree Node class.
29 *
30 * @author <a mailto="particle@theparticle.com">particle</a>
31 * (<a href="http://www.theparticle.com/">www.theparticle.com</a>)
32 * @author Luca Fossato
33 * @created 06 July 2002
34 */
35 public class Node
36 {
37 /*** node identifier */
38 protected String id;
39
40 /*** node data object */
41 protected Object data;
42
43 /*** left node */
44 protected Node left;
45
46 /*** right node */
47 protected Node right;
48
49 /*** parent node */
50 protected Node parent;
51
52 /*** node depth level */
53 protected int depth;
54
55 /*** child nodes visibility */
56 protected boolean open;
57
58
59 /*** Default constructor for Node object. */
60 public Node()
61 {
62 id = null;
63 parent = null;
64 left = null;
65 right = null;
66 data = null;
67 depth = 0;
68 open = false;
69 }
70
71
72 /***
73 * Constructor for the Node object.
74 * Instance a new Node object, setting its data object.
75 *
76 * @param data the node data object
77 */
78 public Node(Object data)
79 {
80 this();
81 this.data = data;
82 }
83
84
85 /***
86 * Constructor for the Node object.
87 * Instance a new Node object, setting
88 * its depth level and its data object.
89 *
90 * @param data the node data object
91 * @param depth the node depth
92 */
93 public Node(Object data, int depth)
94 {
95 this(data);
96 this.depth = depth;
97 }
98
99 /***
100 * Constructor for the Node object
101 *
102 * @param id the node identifier
103 * @param d the node data object
104 */
105 public Node(String id, Object data)
106 {
107 this(data);
108 this.id = id;
109 }
110
111
112 /***
113 * Sets the id attribute of the Node object
114 *
115 * @param v The new id value
116 */
117 public void setId(long v)
118 {
119 id = String.valueOf(v);
120 }
121
122
123 /***
124 * Sets the id attribute of the Node object
125 *
126 * @param v The new id value
127 */
128 public void setId(String v)
129 {
130 id = v;
131 }
132
133
134 /***
135 * Gets the id attribute of the ItemNode object
136 *
137 * @return The id value
138 */
139 public String getId()
140 {
141 return id;
142 }
143
144
145 /***
146 * Sets the left attribute of the Node object
147 *
148 * @param l The new left value
149 */
150 public void setLeft(Node l)
151 {
152 left = l;
153 }
154
155
156 /***
157 * Sets the right attribute of the Node object
158 *
159 * @param r The new right value
160 */
161 public void setRight(Node r)
162 {
163 right = r;
164 }
165
166
167 /***
168 * Sets the parent attribute of the Node object
169 *
170 * @param p The new parent value
171 */
172 public void setParent(Node p)
173 {
174 parent = p;
175 }
176
177
178 /***
179 * Sets the data attribute of the Node object
180 *
181 * @param d The new data value
182 */
183 public void setData(Object d)
184 {
185 data = d;
186 }
187
188
189 /***
190 * Gets the left attribute of the Node object
191 *
192 * @return The left value
193 */
194 public Node getLeft()
195 {
196 return left;
197 }
198
199
200 /***
201 * Gets the right attribute of the Node object
202 *
203 * @return The right value
204 */
205 public Node getRight()
206 {
207 return right;
208 }
209
210
211 /***
212 * Gets the parent attribute of the Node object
213 *
214 * @return The parent value
215 */
216 public Node getParent()
217 {
218 return parent;
219 }
220
221
222 /***
223 * Gets the data attribute of the Node object
224 *
225 * @return The data value
226 */
227 public Object getData()
228 {
229 return data;
230 }
231
232
233 /***
234 * Test if the node is open.
235 *
236 * @return true if the node is open, false otherwise.
237 */
238 public boolean isOpen()
239 {
240 return open;
241 }
242
243
244 /***
245 * Set the node orifice.
246 *
247 * @param open true to set the <code>open</code> attribute to true;
248 * false otherwise.
249 */
250 public void setOpening(boolean open)
251 {
252 this.open = open;
253 }
254
255
256 /***
257 * Gets the depth attribute of the Node object
258 *
259 * @return The depth value
260 */
261 public int getDepth()
262 {
263 return depth;
264 }
265
266
267 /***
268 * Sets the depth attribute of the Node object
269 *
270 * @param depth The new depth value
271 */
272 public void setDepth(int depth)
273 {
274 this.depth = depth;
275 }
276
277
278 /***
279 * Finalize this node.
280 * <br>
281 * Clear all the node references.
282 */
283 public void finalize()
284 {
285 id = null;
286 parent = null;
287 left = null;
288 right = null;
289 data = null;
290 }
291 }
292