|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectinfo.monitorenter.cpdetector.util.collections.ITreeNode.DefaultTreeNode
public static class ITreeNode.DefaultTreeNode
Plain-forward implementation of the ITreeNodeinterface.
This implementation covers many of the algorithms that may be somewhat tricky to implement in an elegant way for beginners. Subclasses may add other policies and constraints to achieve a special invariant with a certain behaviour.
| Nested Class Summary |
|---|
| Nested classes/interfaces inherited from interface info.monitorenter.cpdetector.util.collections.ITreeNode |
|---|
ITreeNode.DefaultTreeNode |
| Field Summary | |
|---|---|
protected SortedSet |
m_children
A Listof child ITreeNode instances. |
protected Object |
m_userObject
Member for saving the user Object. |
protected boolean |
marked
Flag for saving the marking-state. |
| Fields inherited from interface info.monitorenter.cpdetector.util.collections.ITreeNode |
|---|
ROOT |
| Constructor Summary | |
|---|---|
ITreeNode.DefaultTreeNode()
Create a ITreeNode without a parent, user Object and m_children. |
|
ITreeNode.DefaultTreeNode(Object userObject)
Create a ITreeNode without a parent that carries the given user Object. |
|
ITreeNode.DefaultTreeNode(Object userObject,
ITreeNode child)
Create a ITreeNode without a parent that carries the given user Object and has the given ITreeNode as child. |
|
ITreeNode.DefaultTreeNode(Object userObject,
ITreeNode[] children)
Create a ITreeNode without a parent that carries the given user Object and has the given ITreeNode instances as m_children. |
|
| Method Summary | |
|---|---|
ITreeNode |
addChild(Object userObject)
The given Object will be stored in a newly created ITreeNode which will get assigned this node to be it's father, while this instance will store the new node in it's list (unconditionally: e.g. |
boolean |
addChildNode(ITreeNode node)
The given ITreeNode will become this node to be it's father, while this instance will store the given node in it's list if not null (unconditionally: e.g. |
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. |
int |
compareTo(Object o)
|
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 obj)
Two instances are equal, if they both are of this type and user objects are equal. |
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)
The search is a "prefix-search": |
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. |
String |
toString()
|
protected void |
toStringInternal(StringBuffer buf,
int depth)
|
void |
unmark()
Unmarks this ITreeNode instance (e.g. |
| Methods inherited from class java.lang.Object |
|---|
clone, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Field Detail |
|---|
protected boolean marked
protected Object m_userObject
getUserObject()protected SortedSet m_children
Listof child ITreeNode instances.
| Constructor Detail |
|---|
public ITreeNode.DefaultTreeNode()
Create a ITreeNode without a parent, user Object and m_children. After this call, this instance will be the root node (no parent).
public ITreeNode.DefaultTreeNode(Object userObject)
Create a ITreeNode without a parent that carries the given user Object.
userObject - An Object that is desired to be stored in the node.
public ITreeNode.DefaultTreeNode(Object userObject,
ITreeNode child)
userObject - An Object that is desired to be stored in the node.child - The first child of this node.
public ITreeNode.DefaultTreeNode(Object userObject,
ITreeNode[] children)
Create a ITreeNode without a parent that carries the given user Object and has the given ITreeNode instances as m_children.
Perhaps the most useful constructor. It allows to construct trees in a short overviewable way:
new DefaultTreeNode(
new Integer(1),
new ITreeNode[]{
new DefaultTreeNode(
new Integer(2)
),
new DefaultTreeNode(
new Integer(3),
new DefaultTreeNode(
new Integer
)
)
);
userObject - An Object that is desired to be stored in the node.children - An array of ITreeNode instances that will become
childs of this node.| Method Detail |
|---|
public boolean equals(Object obj)
equals in interface ITreeNodeequals in class Objectobj - Possibly a ITreeNode that has to be checked for
equality.
setUserObject(Object),
Object.equals(java.lang.Object)public final ITreeNode addChild(Object userObject)
addChild in interface ITreeNodeuserObject - The Object that should be carried by the new ITreeNode
or null, if no one is desired.
ITreeNode{interface}: Null may be returned in
case of failure!!!ITreeNode.addChild(Object)public boolean addChildNode(ITreeNode node)
addChildNode in interface ITreeNodenode - the node to add as child.
ITreeNode.addChildNode(ITreeNode)public final boolean contains(Object userObject)
ITreeNode
contains in interface ITreeNodeuserObject - Any Object, that might be contained in this tree -
Identification is done by the means of the Objects
Object.equals(Object)- method.
public final boolean containsNode(ITreeNode node)
ITreeNodeFind out, wether the given ITreeNode is a member of this node's subtree.
containsNode in interface ITreeNodenode - A ITreeNode that migth possibly linked to (or be) this
instance by the means of the equals operation.
ITreeNode.equals(Object)public final int getChildCount()
ITreeNodeReturns the amount of child ITreeNodes of this ITreeNode.
getChildCount in interface ITreeNodepublic final Iterator getChilds()
ITreeNode
The Iteratorreturned will not traverse the whole subtree
but only the direct child nodes of this ITreeNode.
getChilds in interface ITreeNodeIteratorover the direct childs of this
ITreeNode.public final ITreeNode getParent()
ITreeNode
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), ITreeNode.ROOThas to be returned.
getParent in interface ITreeNodeITreeNode.ROOT, if
this node is the root.public final int getSubtreeCount()
ITreeNodeGet the amount of direct and indirect childs of this ITreeNode.
getSubtreeCount in interface ITreeNodepublic final Object getUserObject()
ITreeNode
getUserObject in interface ITreeNodepublic final void mark()
ITreeNodeMarks 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".
mark in interface ITreeNodepublic final boolean isMarked()
ITreeNodeCheck, wether this ITreeNode is marked.
isMarked in interface ITreeNodepublic final ITreeNode remove(Object userObject)
The search is a "prefix-search":
A
/ \
B C
/ \
D E
The search will be done in the order: A,B,D,E,C. If this
ITreeNode contains the user Object equal to the argument,
itself will be returned. This ITreeNode may be the root!
remove in interface ITreeNodeuserObject - The user Object identifying the treenode to remove.
ITreeNode.remove(Object)public final List removeAllChildren()
ITreeNode
removeAllChildren in interface ITreeNodeListcontaining all removed child nodes. An
empty List should be provided instead of null!public boolean removeChild(ITreeNode node)
ITreeNodeRemove 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.
removeChild in interface ITreeNodenode - A child of this ITreeNode (by the means of the
ITreeNode.equals(Object)operation) .
public final Object setUserObject(Object store)
ITreeNode
setUserObject in interface ITreeNodepublic final void unmark()
ITreeNodeUnmarks 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".
unmark in interface ITreeNodepublic final void setParent(ITreeNode parent)
ITreeNode
This method should not be called from outside. It is a callback for the
method ITreeNode.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).
setParent in interface ITreeNodeparent - The new parental node.public final boolean isLeaf()
ITreeNodeFind out, wether this ITreeNode is a childless leaf.
isLeaf in interface ITreeNodepublic final boolean isRoot()
ITreeNodeFind out, wether there is no path to a higher parental node from this ITreeNode.
isRoot in interface ITreeNodepublic String toString()
toString in class Object
protected void toStringInternal(StringBuffer buf,
int depth)
public final boolean addChildNodes(ITreeNode[] nodes)
ITreeNode
Adds all given ITreeNode instances to the set of this instances
childs. This operation should delegate to ITreeNode.addChildNode(ITreeNode).
addChildNodes in interface ITreeNodenodes - An arry of ITreeNode instances.
public final ITreeNode[] addChildren(Object[] userObjects)
ITreeNodeITreeNode.addChild(Object).
addChildren in interface ITreeNodeuserObjects - An arry of Objects instances which will become the
m_userObject members of the newly created ITreeNode
instances.
public final List getAllChildren()
ITreeNodeGet all child nodes of the ITreeNode.
getAllChildren in interface ITreeNodeListcontaining all child nodes. An empty List
should be provided instead of null!public ITreeNode newInstance()
ITreeNodeGeneric 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.
newInstance in interface ITreeNodepublic void getPathFromRoot(List l)
getPathFromRoot in interface ITreeNodel - An empty List: After this call it will be filled with
ITreeNodeinstances starting from the root node to the
current node that is invoked.public void getUserObjectPathFromRoot(List l)
getUserObjectPathFromRoot in interface ITreeNodel - An empty List: After this call it will be filled with the
ITreeNode.getUserObject()instances starting from the root node to
the current node that was invoked.
public int compareTo(Object o)
throws ClassCastException
compareTo in interface ComparableClassCastException
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||