fc.util
Class Tree.Node

java.lang.Object
  extended by fc.util.Tree.Node
Enclosing class:
Tree

public static class Tree.Node
extends Object


Constructor Summary
Tree.Node(Object data)
          Creates a new Node.
Tree.Node(Tree.Node parent, Object data)
          Creates a new Node and adds it as a child of the specified Node
 
Method Summary
 void add(Tree.Node child)
          Adds the specified node as a new child node to this node.
 boolean containsChild(Tree.Node child)
          Returns true if this node contains the specified element.
 boolean equals(Object obj)
          Calls super.equals(), i.e, reference equality.
 Tree.Node getChildContaining(Object obj)
          Returns the first child node whose data object equals the specified argument.
 List getChildren()
          Returns the children of this node.
 Object getData()
          Returns the Object representing the data for this node, null if no data has been assigned.
 int getLevel()
          Gets the level of this node starting from the root (the root node is at level 0)
 int getMaxDepth()
          Returns the maximum depth of the tree starting from this node and following the deepest branch.
 Tree.Node getParent()
          Returns the parent of the TreeNode, null if there is no parent
 Iterator getSiblings()
          Returns the siblings of this node.
 boolean isLeaf()
          Returns true is this node has no children, false otherwise
 boolean isNodeAncestor(Tree.Node ancestor)
          Returns true if the specified node is an ancestor of this node false otherwise.
 boolean isNodeChild(Tree.Node child)
          Returns true if the specified node is a child of this node false otherwise.
 boolean isNodeDescendant(Tree.Node descendent)
          Returns true if the specified node is a descendent of this node false otherwise.
 boolean isNodeSibling(Tree.Node node)
          Returns true if the specified node is a sibling of this node false otherwise.
 boolean isRoot()
          Returns true if this node is the root node of the tree, false otherwise.
 Iterator iterator(Tree.IterationOrder order)
          Returns an iterator for all the nodes in the tree, starting from this node onwards.
 int recursiveSize()
          Returns the total number of all nodes reachable under this node.
 boolean remove(Tree.Node child)
          Removes a single instance of the specified element from this node's children, if it is present.
 String toString()
           
 boolean valEquals(Tree.Node one, Tree.Node other)
          Compares the values of 2 nodes.
 
Methods inherited from class java.lang.Object
getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Tree.Node

public Tree.Node(Object data)
Creates a new Node. The created Node is not attached to any other node in the tree and must be manually attached via the #setParent(TreeNode) method.

Parameters:
data - the data object associated with this node.

Tree.Node

public Tree.Node(Tree.Node parent,
                 Object data)
Creates a new Node and adds it as a child of the specified Node

Parameters:
parent - the parent of this node
data - the data object associated with this node
Method Detail

add

public void add(Tree.Node child)
Adds the specified node as a new child node to this node.


remove

public boolean remove(Tree.Node child)
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. Returns true if 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

public List 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

public Tree.Node getChildContaining(Object obj)
Returns the first child node whose data object equals the specified argument. That is, returns child node where childnode.data.equals(obj) == true. Returns null is no matching child node is found.

Parameters:
obj - the object against which the child nodes will be compared

containsChild

public boolean containsChild(Tree.Node child)
Returns true if this node contains the specified element. Follows the contract of Collection.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

public Tree.Node getParent()
Returns the parent of the TreeNode, null if there is no parent


getSiblings

public Iterator 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

public Object getData()
Returns the Object representing the data for this node, null if no data has been assigned.


recursiveSize

public int 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

public boolean isRoot()
Returns true if this node is the root node of the tree, false otherwise.


isNodeAncestor

public boolean isNodeAncestor(Tree.Node ancestor)
Returns true if the specified node is an ancestor of this node false otherwise. An ancestor is any node between thre root node and this node, not including this node itself.


isNodeChild

public boolean isNodeChild(Tree.Node child)
Returns true if the specified node is a child of this node false otherwise. A node is not a child of itself.


isNodeDescendant

public boolean isNodeDescendant(Tree.Node descendent)
Returns true if the specified node is a descendent of this node false otherwise. A node is not a descendent of itself.


isNodeSibling

public boolean isNodeSibling(Tree.Node node)
Returns true if the specified node is a sibling of this node false otherwise. A node is not a sibling of itself.


isLeaf

public boolean isLeaf()
Returns true is this node has no children, false otherwise


getLevel

public int getLevel()
Gets the level of this node starting from the root (the root node is at level 0)


getMaxDepth

public int 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

public Iterator iterator(Tree.IterationOrder order)
Returns an iterator for all the nodes in the tree, starting from this node onwards.


equals

public boolean equals(Object obj)
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.

Overrides:
equals in class Object

valEquals

public boolean valEquals(Tree.Node one,
                         Tree.Node other)
Compares the values of 2 nodes. Only the data associated with the nodes is compared; the number/structure of any child nodes is ignored by this method


toString

public String toString()
Overrides:
toString in class Object