|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object net.sf.click.extras.tree.TreeNode
Provides an implementation of a Tree
model.
Object
.
Nodes contain a reference to their parent node as well as their children.
Two types of leaf nodes are supported by this implementation. A leaf node can
either support the addition of new child nodes or not. An example of a leaf node
where children are supported is a directory. A directory can be empty, meaning
it is a leaf node, but files and subdirectories can be added as children.
Another type of of leaf node does not support the addition of child nodes. A
file would be an example of such a node. A file does not support the addition
of new files or subdirectories as children. By default newly created nodes
supports the addition of child nodes. Use the appropriate constructor to
disable the support of child nodes, or call setChildrenSupported(boolean)
.
Note: Since each TreeNode must have a
unique id within the tree, a default id is generated if one is not provided in
the constructors. Id's are generated by an instance of Random
.
The current implementation generates a Long using random.nextLong(). This
means a total of 2 64 numbers can be generated.
Constructor Summary | |
TreeNode()
Creates a default node with no value or id. |
|
TreeNode(Object value)
Creates a node and sets the value to the specified argument. |
|
TreeNode(Object value,
String id)
Creates a node and sets the value and id to the specified arguments. |
|
TreeNode(Object value,
String id,
TreeNode parent)
Creates a node and sets the value, id and parent to the specified arguments. |
|
TreeNode(Object value,
String id,
TreeNode parent,
boolean childrenSupported)
Creates a node and sets the value, id and parent to the specified arguments. |
Method Summary | |
void |
add(int index,
TreeNode child)
Adds the specified node at the specified index as a child of this node and sets the child's parent to this node. |
void |
add(TreeNode child)
Adds the specified node as a child of this node and sets the child's parent to this node. |
void |
addChildOnly(int index,
TreeNode child)
Adds the specified node at the specified index as a child of this node but does NOT set the child's parent to this node. |
void |
addChildOnly(TreeNode child)
Adds the specified node as a child of this node but does NOT set the child's parent to this node. |
void |
cacheTreeDepth(int depth)
Stores the specified depth in a variable for fast retrieval. |
int |
calcTreeDepth()
Calculate and return the depth of the tree where this node is set as the root of the calculation. |
int |
calcTreeDepth(boolean useCacheIfSet)
Calculate and return the depth of the tree where this node is set as the root of the calculation. |
boolean |
equals(Object thatObject)
Checks if this node's id is equals to the specified node's id. |
List |
getChildren()
Returns a unmodifiable list of this nodes children. |
String |
getId()
Returns this node's id value. |
int |
getLevel()
Returns this node's level in the tree structure. |
TreeNode |
getParent()
Returns this node's parent object or null if parent is not specified. |
Object |
getValue()
Return this node's value. |
boolean |
hasChildren()
Returns true if this node has any children nodes false otherwise. |
int |
hashCode()
Returns the hashCode value for this node. |
boolean |
isChildrenSupported()
Returns true if this node supports children, false otherwise. |
boolean |
isExpanded()
Returns true if this node is currently in the expanded state, false otherwise. |
boolean |
isLastChild()
Returns true if either this node is the last child of its parent, or this node is the root node. |
boolean |
isLeaf()
Returns true if this node does not have any children, false otherwise. |
boolean |
isRoot()
Returns true if this node is the root node. |
boolean |
isSelected()
Returns true if this node is currently in the selected state, false otherwise. |
void |
remove(TreeNode child)
Removes the specified node from the list of children and sets child's parent node to null. |
void |
setChildrenSupported(boolean childrenSupported)
Sets whether this node supports child nodes or not. |
void |
setId(String id)
Set this node's new id value. |
void |
setParent(TreeNode parent)
Sets this node's parent to the specified argument. |
void |
setValue(Object value)
Set this node's value. |
String |
toString()
Renders a string representation of this node. |
Methods inherited from class java.lang.Object |
clone, finalize, getClass, notify, notifyAll, wait, wait, wait |
Constructor Detail |
public TreeNode()
Random
.
public TreeNode(Object value)
Random
.
value
- the nodes valuepublic TreeNode(Object value, String id)
value
- the nodes valueid
- the nodes idpublic TreeNode(Object value, String id, TreeNode parent)
value
- the nodes valueid
- the nodes idparent
- specifies the parent of this nodepublic TreeNode(Object value, String id, TreeNode parent, boolean childrenSupported)
value
- the nodes valueid
- the nodes idparent
- specifies the parent of this nodechildrenSupported
- indicates if the treeNode supports child nodes
or not.Method Detail |
public TreeNode getParent()
public void setParent(TreeNode parent)
parent
- this node's parent objectpublic Object getValue()
public void setValue(Object value)
value
- the new value of this nodepublic boolean isLeaf()
public boolean isChildrenSupported()
public void setChildrenSupported(boolean childrenSupported)
childrenSupported
- whether this node supports children or notpublic String getId()
public void setId(String id)
id
- this node's new id valuepublic List getChildren()
public boolean isSelected()
public boolean isExpanded()
public void add(TreeNode child)
child
- child node to add
IllegalArgumentException
- if the argument is null or if this node
does not support child nodespublic void add(int index, TreeNode child)
index
- the index at which specified child must be addedchild
- child node to add
IllegalArgumentException
- if the argument is null or if this node
does not support child nodespublic void addChildOnly(TreeNode child)
child
- child node to add
IllegalArgumentException
- if the argument is null or if this node
does not support child nodespublic void addChildOnly(int index, TreeNode child)
index
- of the child node to add tochild
- child node to add
IllegalArgumentException
- if the argument is null or if this node
does not support child nodespublic void remove(TreeNode child)
child
- child node to remove from this nodes children
IllegalArgumentException
- if the argument is nullpublic boolean isRoot()
public boolean hasChildren()
public boolean isLastChild()
public int calcTreeDepth()
cacheTreeDepth(int)
.
Time complexity: This method performs in O(n) where n is
the number of nodes in the tree. In other words no optimized algorithm is
used by this method.
cacheTreeDepth(int)
public int calcTreeDepth(boolean useCacheIfSet)
cacheTreeDepth(int)
. If useCacheIfSet is false
this method will recalculate the depth of the tree.
Time complexity: This method performs in O(n) where n is
the number of nodes in the tree. In other words no optimized algorithm is
used by this method.
useCacheIfSet
- if true use the cached value if it was set,
else recalculate the depth
cacheTreeDepth(int)
public void cacheTreeDepth(int depth)
calcTreeDepth(boolean)
with 'true'.
depth
- this node's depth to cachecalcTreeDepth(boolean)
public int getLevel()
public boolean equals(Object thatObject)
thatObject
- the specified object to check for equality
Object.equals(Object)
public int hashCode()
Object.hashCode()
public String toString()
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |