Class Tree.Node

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

public static class Tree.Node extends Object
  • Constructor Summary

    Constructors
    Constructor
    Description
    Node(Tree.Node parent, Object data)
    Creates a new Node and adds it as a child of the specified Node
    Node(Object data)
    Creates a new Node.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    add(Tree.Node child)
    Adds the specified node as a new child node to this node.
    boolean
    Returns true if this node contains the specified element.
    boolean
    Calls super.equals(), i.e, reference equality.
    Returns the first child node whose data object equals the specified argument.
    Returns the children of this node.
    Returns the Object representing the data for this node, null if no data has been assigned.
    int
    Gets the level of this node starting from the root (the root node is at level 0)
    int
    Returns the maximum depth of the tree starting from this node and following the deepest branch.
    Returns the parent of the TreeNode, null if there is no parent
    Returns the siblings of this node.
    boolean
    Returns true is this node has no children, false otherwise
    boolean
    Returns true if the specified node is an ancestor of this node false otherwise.
    boolean
    Returns true if the specified node is a child of this node false otherwise.
    boolean
    Returns true if the specified node is a descendent of this node false otherwise.
    boolean
    Returns true if the specified node is a sibling of this node false otherwise.
    boolean
    Returns true if this node is the root node of the tree, false otherwise.
    Returns an iterator for all the nodes in the tree, starting from this node onwards.
    int
    Returns the total number of all nodes reachable under this node.
    boolean
    Removes a single instance of the specified element from this node's children, if it is present.
     
    boolean
    Compares the values of 2 nodes.

    Methods inherited from class Object

    getClass, hashCode, notify, notifyAll, wait, wait, wait
  • Constructor Details

    • Node

      public 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
      invalid reference
      #setParent(TreeNode)
      method.
      Parameters:
      data - the data object associated with this node.
    • Node

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

    • 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

      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

      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

      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