Class Tree.Node
java.lang.Object
fc.util.Tree.Node
- Enclosing class:
Tree
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidAdds the specified node as a new child node to this node.booleancontainsChild(Tree.Node child) Returns true if this node contains the specified element.booleanCalls super.equals(), i.e, reference equality.getChildContaining(Object obj) Returns the first child node whose data object equals the specified argument.Returns the children of this node.getData()Returns the Object representing the data for this node,nullif no data has been assigned.intgetLevel()Gets the level of this node starting from the root (the root node is at level 0)intReturns the maximum depth of the tree starting from this node and following the deepest branch.Returns the parent of the TreeNode,nullif there is no parentReturns the siblings of this node.booleanisLeaf()Returnstrueis this node has no children,falseotherwisebooleanisNodeAncestor(Tree.Node ancestor) Returnstrueif the specified node is an ancestor of this nodefalseotherwise.booleanisNodeChild(Tree.Node child) Returnstrueif the specified node is a child of this nodefalseotherwise.booleanisNodeDescendant(Tree.Node descendent) Returnstrueif the specified node is a descendent of this nodefalseotherwise.booleanisNodeSibling(Tree.Node node) Returnstrueif the specified node is a sibling of this nodefalseotherwise.booleanisRoot()Returnstrueif this node is the root node of the tree,falseotherwise.iterator(Tree.IterationOrder order) Returns an iterator for all the nodes in the tree, starting from this node onwards.intReturns the total number of all nodes reachable under this node.booleanRemoves a single instance of the specified element from this node's children, if it is present.toString()booleanCompares the values of 2 nodes.
-
Constructor Details
-
Node
Creates a new Node. The created Node is not attached to any other node in the tree and must be manually attached via theadd(fc.util.Tree.Node)method.- Parameters:
data- the data object associated with this node.
-
Node
-
-
Method Details
-
add
-
remove
Removes a single instance of the specified element from this node's children, if it is present. More formally, removes an element e such that (o==null ? e==null : o.equals(e)), if this node contains one or more such elements. Returnstrueif this node contained the specified element (or equivalently, if this collection changed as a result of the call).- Parameters:
child- child element to be removed from this node if present.- Returns:
- true if this node changed as a result of the call
-
getChildren
Returns the children of this node. The returned list is not a copy of this node's trees therefore any modification made to the returned object will be seen by this node. This is useful for reordering nodes etc. -
getChildContaining
Returns the first child node whose data object equals the specified argument. That is, returns child node wherechildnode.data.equals(obj) == true. Returnsnullis no matching child node is found.- Parameters:
obj- the object against which the child nodes will be compared
-
containsChild
Returns true if this node contains the specified element. Follows the contract ofCollection.contains(Object)- Parameters:
child- node whose presence in this collection is to be tested.- Returns:
- true if this node contains the specified child element
-
getParent
-
getSiblings
Returns the siblings of this node. A sibling is any node that is a child of this node's parent and is not the same as this node.Returns an iterator with no elements if there are no siblings or if this is the root node (which can have no siblings).
-
getData
-
recursiveSize
Returns the total number of all nodes reachable under this node. If there are no children, this method returns 1 (this node itself is of size 1) -
isRoot
Returnstrueif this node is the root node of the tree,falseotherwise. -
isNodeAncestor
Returnstrueif the specified node is an ancestor of this nodefalseotherwise. An ancestor is any node between thre root node and this node, not including this node itself. -
isNodeChild
Returnstrueif the specified node is a child of this nodefalseotherwise. A node is not a child of itself. -
isNodeDescendant
Returnstrueif the specified node is a descendent of this nodefalseotherwise. A node is not a descendent of itself. -
isNodeSibling
Returnstrueif the specified node is a sibling of this nodefalseotherwise. A node is not a sibling of itself. -
isLeaf
Returnstrueis this node has no children,falseotherwise -
getLevel
Gets the level of this node starting from the root (the root node is at level 0) -
getMaxDepth
Returns the maximum depth of the tree starting from this node and following the deepest branch. The ending depth is a node that contains only data (leaves) and no children. If this node has no children, this method returns 0 (i.e., this node itself is at depth 0). -
iterator
Returns an iterator for all the nodes in the tree, starting from this node onwards.- Parameters:
order- the tree transveral order for the iteration
-
equals
Calls super.equals(), i.e, reference equality. java.util.Collection operations like add/remove nodes etc., are defined in terms of equals(). It becomes very inefficient to have a full-fledged equals that compares both the data of this node and the exact number and structure of the children of this node. Subclasses can optionally redefine this method if necessary. -
valEquals
-
toString
-