Class Node<T>

java.lang.Object
org.gcube.informationsystem.tree.Node<T>
Type Parameters:
T - The type of the element stored in the node.
All Implemented Interfaces:
Comparable<Node<T>>

public class Node<T> extends Object implements Comparable<Node<T>>
Represents a node in a Tree.
Author:
Luca Frosini (ISTI - CNR)
  • Field Details

    • INDENTATION

      public static String INDENTATION
      The string used for indentation when printing the tree.
    • t

      protected T t
      The element stored in this node.
    • tree

      protected Tree<T> tree
      The tree to which this node belongs.
    • childrenElements

      protected Set<T> childrenElements
      The elements of the children of this node.
    • descendantElements

      protected Set<T> descendantElements
      The elements of all descendants of this node.
    • parent

      protected Node<T> parent
      The parent of this node.
    • children

      protected Set<Node<T>> children
      The children of this node.
    • descendants

      protected Set<Node<T>> descendants
      All descendants of this node.
  • Constructor Details

    • Node

      public Node(T t)
      Constructs a new node with the given element.
      Parameters:
      t - The element to store in the node.
  • Method Details

    • getTree

      public Tree<T> getTree()
      Returns the tree to which this node belongs.
      Returns:
      The parent tree.
    • getNodeElement

      public T getNodeElement()
      Returns the element stored in this node.
      Returns:
      The node's element.
    • getParent

      public Node<T> getParent()
      Returns the parent of this node.
      Returns:
      The parent node, or null if this is the root.
    • setParent

      public Node<T> setParent(Node<T> parent)
      Sets the parent of this node.
      Parameters:
      parent - The parent node.
      Returns:
      This node.
    • addChild

      public Node<T> addChild(Node<T> child)
      Adds a child to this node.
      Parameters:
      child - The child node to add.
      Returns:
      This node.
    • getIdentifier

      public String getIdentifier()
      Returns the identifier of this node's element.
      Returns:
      The identifier.
    • getChildren

      public Set<Node<T>> getChildren()
      Returns the children of this node.
      Returns:
      A set of child nodes.
    • getDescendants

      public Set<Node<T>> getDescendants()
      Returns all descendants of this node.
      Returns:
      A set of all descendant nodes.
    • getChildrenElements

      public Set<T> getChildrenElements()
      Returns the elements of the children of this node.
      Returns:
      A set of the elements of the child nodes.
    • getDescendantElements

      public Set<T> getDescendantElements()
      Returns the elements of all descendants of this node.
      Returns:
      A set of the elements of all descendant nodes.
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • compareTo

      public int compareTo(Node<T> other)
      Specified by:
      compareTo in interface Comparable<T>
    • elaborate

      public void elaborate(NodeElaborator<T> nodeElaborator) throws Exception
      Traverses the subtree starting from this node and applies the given elaborator.
      Parameters:
      nodeElaborator - The elaborator to apply to each node.
      Throws:
      Exception - if an error occurs during elaboration.
    • elaborate

      protected void elaborate(NodeElaborator<T> nodeElaborator, int level) throws Exception
      Traverses the subtree starting from this node and applies the given elaborator.
      Parameters:
      nodeElaborator - The elaborator to apply to each node.
      level - The current level in the tree.
      Throws:
      Exception - if an error occurs during elaboration.