-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTree.java
More file actions
224 lines (173 loc) · 4.98 KB
/
Tree.java
File metadata and controls
224 lines (173 loc) · 4.98 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
package net.posick.tree;
import java.util.List;
/**
* @author Steve Posick
*
* @param <T> The Tree node type.
* @param <V> The value contained within the Tree node
*/
public interface Tree<T extends Tree<T, V>, V>
{
/**
* <code>PARENT</code> node indicator.
*/
public static final int PARENT = 0;
/**
* <code>CHILD</code> node indicator.
*/
public static final int CHILD = 1;
/**
* <code>LASTCHILD</code> node indicator.
*/
public static final int LASTCHILD = 2;
/**
* <code>NEXT</code> node indicator.
*/
public static final int NEXT = 3;
/**
* <code>PREVIOUS</code> node indicator.
*/
public static final int PREVIOUS = 4;
/**
* <code>LAST</code> node indicator.
*/
public static final int LAST = 5;
/**
* Gets the parent for this node in the Tree.
*
* @return the parent for this node in the Tree
*/
public T getParent();
/**
* Sets the parent for this node.
*
* @return the parent for this node
*/
public void setParent(T parent);
/**
* Gets the first child for this node in the Tree.
*
* @return the the first child for this node in the Tree
*/
public T getFirstChild();
/**
* Sets the first child for this node in the Tree.
*
* @return the the first child for this node in the Tree
*/
public void setFirstChild(T child);
/**
* Gets the next sibling for this node in the Tree.
*
* @return The next sibling for this node in the Tree
*/
public T getNextSibling();
/**
* Sets the next sibling for this node in the Tree.
*
* @return The next sibling for this node in the Tree
*/
public void setNextSibling(T sibling);
/**
* Gets the previous sibling for this node in the Tree.
*
* @return The previous sibling for this node in the Tree
*/
public T getPreviousSibling();
/**
* Sets the previous sibling for this node in the Tree.
*
* @return The previous sibling for this node in the Tree
*/
public void setPreviousSibling(T sibling);
/**
* Adds a new node to the tree using this node as a reference point.
*
* @param newNode The new node to add
* @param mode The node indicator, how the node will be added
* @return The node that was added to the Tree
*/
public T add(T newNode, int mode);
/**
* Adds a new node to the tree using this node as a reference point.
*
* @param value The value for the new node
* @param mode The node indicator, how the node will be added
* @return The node that was added to the Tree
*/
public T add(V value, int mode);
/**
* Gets the first child that has this value.
*
* @param value The value
* @return The first child that has this value or null.
*/
public T getChild(V value);
/**
* Gets the first sibling that has this value.
*
* @param value The value
* @return The first sibling that has this value or null.
*/
public T getSibling(V value);
/**
* Replaces this node with the specified node.
*
* @param newNode The node to replace this node with.
*/
public void replace(T newNode);
/**
* Deletes this node from the tree.
*/
public void remove();
/**
* Tests if this node has children.
*
* @return True if this node has children
*/
public boolean hasChildren();
/**
* Returns an Iterator of all the children of this node, recursively.
*
* @return The iterator of children.
*/
public List<T> getDescendants();
/**
* Returns an Iterator of all the direct children of this node.
*
* @return The iterator of children.
*/
public List<T> getChildren();
/**
* Returns an Iterator of this nodes siblings. Includes this node in the
* Iterator.
*
* @return The iterator of siblings.
*/
public List<T> getSiblings();
/**
* Returns the value contained within this node of the Tree.
*
* @return The value contained within this node of the Tree
*/
public V getValue();
/**
* Sets the value to store within this node of the Tree.
*
* @param value The value to store within this node of the Tree
*/
public void setValue(V value);
/**
* Returns the root most node of the tree.
*
* @return
*/
public T getRoot();
/**
* Traverses the tree using this node as a starting point. The traverse action is executed for
* each node encountered.
*
* @param action The action to perform for each node, flow control
*/
public void traverse(TraverseAction<T, V> action);
}