|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.j4me.collections.TreeNode
public class TreeNode
TreeNode
objects can be combined into a tree. The tree is not
a special tree such as a balanced tree. It can have any number of levels
and each node can have any number of children.
Each tree node may have at most one parent and 0 or more children.
TreeNode
provides operations for examining and modifying a node's
parent and children. A node's tree is the set of all nodes that can be
reached by starting at the node and following all the possible links to
parents and children. A node with no parent is the root of its tree; a
node with no children is a leaf. A tree may consist of many subtrees,
each node acting as the root for its own subtree.
Every TreeNode
can hold a reference to one user object. It is up
to the developer to decide what the object is and how to use it. For
example in maintaining the golf course tree the user object is an
ICourseElement
.
This is not a thread safe class. If used from multiple threads it must be manually sychronized by your code.
Constructor Summary | |
---|---|
TreeNode()
Constructs a tree node object. |
|
TreeNode(java.lang.Object userObject)
Constructs a tree node object. |
Method Summary | |
---|---|
void |
add(TreeNode child)
Adds the child node to this container making this its parent. |
void |
add(TreeNode child,
int index)
Adds the child node to this container making this its parent. |
TreeNode[] |
children()
Gets a list of all the child nodes of this node. |
int |
depth()
Gets this node's depth in the tree. |
TreeNode |
getParent()
Gets the parent node of this one. |
java.lang.Object |
getUserObject()
Gets the user defined object attached to this node. |
boolean |
hasChildren()
Returns if this node has children or if it is a leaf node. |
int |
index()
Gets the position of this node in the list of siblings managed by the parent node. |
boolean |
isRoot()
Returns if this node is the root node in the tree or not. |
TreeNode |
remove(int index)
Removes the child at position index from the tree. |
void |
removeFromParent()
Removes this node from its parent. |
void |
setUserObject(java.lang.Object userObject)
Attaches a user defined object to this node. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public TreeNode()
add
method.
There is no user object attached to the node. Call setUserObject
to attach one.
public TreeNode(java.lang.Object userObject)
add
method.
userObject
- is an object this node encapsulates. It is up to
the developer to maintain its type. To get the object back out
call getUserObject
.Method Detail |
---|
public void add(TreeNode child, int index)
child
node to this container making this its parent.
child
- is the node to add to the tree as a child of this
index
- is the position within the children list to add the
child. It must be between 0 (the first child) and the
total number of current children (the last child). If it is
negative the child will become the last child.public void add(TreeNode child)
child
node to this container making this its parent.
The child is appended to the list of children as the last child.
public TreeNode remove(int index)
index
from the tree.
index
- is the position of the child. It should be between
0 (the first child) and the total number of children minus 1
(the last child).
null
if
no child exists at the specified index
.public void removeFromParent()
Calling this on the root node has no effect.
public TreeNode getParent()
null
if this node is the root node in the tree.public boolean isRoot()
true
if this node is the root of the tree;
false
if it has a parent.public TreeNode[] children()
null
.public boolean hasChildren()
true
if this node has children; false
if it does not have any children.public int index()
this = parent.children[this.index()]
.
public int depth()
public void setUserObject(java.lang.Object userObject)
userObject
- is the programmer defined object to
attach to this node in the tree. Set it to null
to clear any objects.public java.lang.Object getUserObject()
null
if no object is
attached.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |