|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
public interface ITreeNode
Basic interface for a tree node. It is an approach at node-level instead of a procedural interface from outside. Working with a tree from outside very often is not as fast and incurs additional memory constumption for saving states and partial results (no recursion may keep traversal-related data on the heap, but the current positions for step-operations has to saved). Supporting an "outside-interface" for a tree is recommended by using a visitor pattern but may also be done in a classical way.
Every node of the tree may carry a so-called "user-Object". While the structure of the tree models the relation of these objects, they themselve contain the data needed.
| Nested Class Summary | |
|---|---|
static class |
ITreeNode.DefaultTreeNode
Plain-forward implementation of the ITreeNodeinterface. |
| Field Summary | |
|---|---|
static ITreeNode |
ROOT
Returned from getParent() of the root node of the tree. |
| Method Summary | |
|---|---|
ITreeNode |
addChild(Object userObject)
Comfortable method for adding child nodes. |
boolean |
addChildNode(ITreeNode node)
Adds the given ITreeNode to the set of this instances childs. |
boolean |
addChildNodes(ITreeNode[] nodes)
Adds all given ITreeNode instances to the set of this instances childs. |
ITreeNode[] |
addChildren(Object[] userObjects)
Adds all given Objects to newly instanciated ITreeNode instances that are added to the set of this instances childs. |
boolean |
contains(Object userObject)
Find out, wether a certain "user" Object is carried by any of this ITreeNodes subtree. |
boolean |
containsNode(ITreeNode node)
Find out, wether the given ITreeNode is a member of this node's subtree. |
boolean |
equals(Object o)
Convenience method recommended for usage by implemenations. |
List |
getAllChildren()
Get all child nodes of the ITreeNode. |
int |
getChildCount()
Returns the amount of child ITreeNodes of this ITreeNode. |
Iterator |
getChilds()
The Iteratorreturned will not traverse the whole subtree
but only the direct child nodes of this ITreeNode. |
ITreeNode |
getParent()
Get the parent node of this ITreeNode. |
void |
getPathFromRoot(List l)
|
int |
getSubtreeCount()
Get the amount of direct and indirect childs of this ITreeNode. |
Object |
getUserObject()
Returns the "user" Object that may be carried by the ITreeNode, or null, if no one was assigned. |
void |
getUserObjectPathFromRoot(List l)
|
boolean |
isLeaf()
Find out, wether this ITreeNode is a childless leaf. |
boolean |
isMarked()
Check, wether this ITreeNode is marked. |
boolean |
isRoot()
Find out, wether there is no path to a higher parental node from this ITreeNode. |
void |
mark()
Marks this ITreeNode instance (e.g. |
ITreeNode |
newInstance()
Generic operations in default implementations may need to allocate new instances but have to choose the right type to support the provided invariants. |
ITreeNode |
remove(Object userObject)
Remove the ITreeNode and it's whole subree! in this node's subtree, that contains a user Object equal to the given argument. |
List |
removeAllChildren()
Remove all child nodes of the ITreeNode. |
boolean |
removeChild(ITreeNode node)
Remove the given ITreeNode from this node. |
void |
setParent(ITreeNode parent)
This method should not be called from outside. |
Object |
setUserObject(Object store)
Assigns the "user" Object that may be carried by the ITreeNode. |
void |
unmark()
Unmarks this ITreeNode instance (e.g. |
| Field Detail |
|---|
static final ITreeNode ROOT
getParent() of the root node of the tree.
| Method Detail |
|---|
Object getUserObject()
Object setUserObject(Object store)
void mark()
Marks this ITreeNode instance (e.g. for being visited or invisible). Marking may be used to traverse the tree in an asynchronous manner from outside (TreeIterator) or for other desireable tasks.
Subsequent calls to this method should not change the state to "unmarked".
void unmark()
Unmarks this ITreeNode instance (e.g. for being visited or invisible). Marking may be used to traverse the tree in an asynchronous manner from outside (TreeIterator) or for other desireable tasks.
Subsequent calls to this method should not change the state to "marked".
boolean isMarked()
Check, wether this ITreeNode is marked.
int getChildCount()
Returns the amount of child ITreeNodes of this ITreeNode.
int getSubtreeCount()
Get the amount of direct and indirect childs of this ITreeNode.
Iterator getChilds()
The Iteratorreturned will not traverse the whole subtree
but only the direct child nodes of this ITreeNode.
Iteratorover the direct childs of this
ITreeNode.ITreeNode getParent()
Get the parent node of this ITreeNode. If the TreeNode has no
parent node (e.g. a member of an implementation for the parent node is
null), ROOThas to be returned.
ROOT, if
this node is the root.void setParent(ITreeNode parent)
This method should not be called from outside. It is a callback for the
method addChildNode(ITreeNode)and should be used by
implementations of that method but not any further. Else inconsistencies
could occur: A node thinks it is the father of another node which itself
does not know about that relation any more (remove itself from the old
parent member's list could avoid it).
parent - The new parental node.boolean addChildNode(ITreeNode node)
Adds the given ITreeNode to the set of this instances childs. Note, that the given node has to get to know, that it has a new parent (implementation detail).
node - The new child ITreeNode whose parent this instance will
become.
boolean addChildNodes(ITreeNode[] nodes)
Adds all given ITreeNode instances to the set of this instances
childs. This operation should delegate to addChildNode(ITreeNode).
nodes - An arry of ITreeNode instances.
ITreeNode addChild(Object userObject)
Comfortable method for adding child nodes. Could be expressed as:
...
ITreeNode ret = new <TreeNodeImpl>(m_userObject);
if(this.addChildNode(ret){
return ret;
}
else{
return null;
}
...
userObject - The Object that should be carried by the new ITreeNode
or null, if no one is desired.
ITreeNode[] addChildren(Object[] userObjects)
addChild(Object).
userObjects - An arry of Objects instances which will become the
m_userObject members of the newly created ITreeNode
instances.
boolean removeChild(ITreeNode node)
Remove the given ITreeNode from this node. If the operation is successful the given node will not have any parent node (e.g. null for parent member) but be the root node of it's subtree.
The operation may fail, if the given ITreeNode is no child of this node, or the implementation permits the removal.
node - A child of this ITreeNode (by the means of the
equals(Object)operation) .
ITreeNode remove(Object userObject)
userObject - The user Object identifying the treenode to remove.
List removeAllChildren()
Listcontaining all removed child nodes. An
empty List should be provided instead of null!List getAllChildren()
Get all child nodes of the ITreeNode.
Listcontaining all child nodes. An empty List
should be provided instead of null!boolean contains(Object userObject)
userObject - Any Object, that might be contained in this tree -
Identification is done by the means of the Objects
Object.equals(Object)- method.
boolean containsNode(ITreeNode node)
Find out, wether the given ITreeNode is a member of this node's subtree.
node - A ITreeNode that migth possibly linked to (or be) this
instance by the means of the equals operation.
equals(Object)boolean isLeaf()
Find out, wether this ITreeNode is a childless leaf.
boolean isRoot()
Find out, wether there is no path to a higher parental node from this ITreeNode.
void getPathFromRoot(List l)
l - An empty List: After this call it will be filled with
ITreeNodeinstances starting from the root node to the
current node that is invoked.void getUserObjectPathFromRoot(List l)
l - An empty List: After this call it will be filled with the
getUserObject()instances starting from the root node to
the current node that was invoked.boolean equals(Object o)
Convenience method recommended for usage by implemenations.
equals in class Objecto - Possibly a ITreeNode that has to be checked for
equality.
containsNode(ITreeNode node),
removeChild(ITreeNode node)ITreeNode newInstance()
Generic operations in default implementations may need to allocate new instances but have to choose the right type to support the provided invariants.
If you provide a subclass that has invariants you should overload this.
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||