Class Node<T>

java.lang.Object
org.gcube.informationsystem.dag.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 Dag.
Author:
Luca Frosini (ISTI - CNR)
  • Field Details

    • INDENTATION

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

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

      protected Dag<T> dag
      The DAG 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.
    • parents

      protected Set<Node<T>> parents
      The parents of this node -- a Set, not a single value: a node can legitimately have more than one (e.g. an interface extending two already-placed interfaces within the same hierarchy, real Java multiple inheritance), and addChild(Node) is called once per matching parent.
    • 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

    • getDag

      public Dag<T> getDag()
      Returns the DAG to which this node belongs.
      Returns:
      The parent DAG.
    • getNodeElement

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

      public Set<Node<T>> getParents()
      Returns the parents of this node -- more than one for a node with genuine multiple inheritance within this hierarchy (see parents), empty if this is a root.
      Returns:
      The parent nodes.
    • 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 sub-DAG rooted at 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 sub-DAG rooted at this node and applies the given elaborator.
      Parameters:
      nodeElaborator - The elaborator to apply to each node.
      level - The current level in the DAG.
      Throws:
      Exception - if an error occurs during elaboration.