public static class ITreeNode.DefaultTreeNode extends Object implements ITreeNode, Comparable<ITreeNode>
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.
ITreeNode.DefaultTreeNode| 限定符和类型 | 字段和说明 |
|---|---|
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.
|
| 构造器和说明 |
|---|
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.
|
| 限定符和类型 | 方法和说明 |
|---|---|
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. no test, if already contained).
|
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. no test, if already contained).
|
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(ITreeNode 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. for being visited or
invisible).
|
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":
A
/ \
B C
/ \
D E
The search will be done in the order: A,B,D,E,C.
|
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. for being visited or
invisible).
|
protected boolean marked
protected Object m_userObject
getUserObject()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.public boolean equals(Object obj)
equals 在接口中 ITreeNodeequals 在类中 Objectobj - Possibly a ITreeNode that has to be checked for
equality.setUserObject(Object),
Object.equals(Object)public final ITreeNode addChild(Object userObject)
addChild 在接口中 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 在接口中 ITreeNodenode - the node to add as child.ITreeNode.addChildNode(ITreeNode)public final boolean contains(Object userObject)
ITreeNodecontains 在接口中 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 在接口中 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 在接口中 ITreeNodepublic final Iterator getChilds()
ITreeNode
The Iteratorreturned will not traverse the whole subtree
but only the direct child nodes 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 在接口中 ITreeNodeITreeNode.ROOT, if
this node is the root.public final int getSubtreeCount()
ITreeNodeGet the amount of direct and indirect childs of this ITreeNode.
getSubtreeCount 在接口中 ITreeNodepublic final Object getUserObject()
ITreeNodegetUserObject 在接口中 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".
public final boolean isMarked()
ITreeNodeCheck, wether this ITreeNode is marked.
public 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 在接口中 ITreeNodeuserObject - The user Object identifying the treenode to remove.ITreeNode.remove(Object)public final List removeAllChildren()
ITreeNoderemoveAllChildren 在接口中 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 在接口中 ITreeNodenode - A child of this ITreeNode (by the means of the
ITreeNode.equals(Object)operation) .public final Object setUserObject(Object store)
ITreeNodesetUserObject 在接口中 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".
public 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).
public final boolean isLeaf()
ITreeNodeFind out, wether this ITreeNode is a childless leaf.
public final boolean isRoot()
ITreeNodeFind out, wether there is no path to a higher parental node from this ITreeNode.
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 在接口中 ITreeNodenodes - An arry of ITreeNode instances.public final ITreeNode[] addChildren(Object[] userObjects)
ITreeNodeITreeNode.addChild(Object).
addChildren 在接口中 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 在接口中 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 在接口中 ITreeNodepublic void getPathFromRoot(List l)
getPathFromRoot 在接口中 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 在接口中 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(ITreeNode o) throws ClassCastException
compareTo 在接口中 Comparable<ITreeNode>ClassCastExceptionCopyright © 2016. All rights reserved.