Package org.gcube.informationsystem.dag
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 aDag.- Author:
- Luca Frosini (ISTI - CNR)
-
-
Field Summary
Fields Modifier and Type Field Description protected Set<Node<T>>childrenThe children of this node.protected Set<T>childrenElementsThe elements of the children of this node.protected Dag<T>dagThe DAG to which this node belongs.protected Set<T>descendantElementsThe elements of all descendants of this node.protected Set<Node<T>>descendantsAll descendants of this node.static StringINDENTATIONThe string used for indentation when printing the DAG.protected Set<Node<T>>parentsThe parents of this node -- aSet, not a single value: a node can legitimately have more than one (e.g.protected TtThe element stored in this node.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Node<T>addChild(Node<T> child)Adds a child to this node.intcompareTo(Node<T> other)voidelaborate(NodeElaborator<T> nodeElaborator)Traverses the sub-DAG rooted at this node and applies the given elaborator.protected voidelaborate(NodeElaborator<T> nodeElaborator, int level)Traverses the sub-DAG rooted at this node and applies the given elaborator.Set<Node<T>>getChildren()Returns the children of this node.Set<T>getChildrenElements()Returns the elements of the children of this node.Dag<T>getDag()Returns the DAG to which this node belongs.Set<T>getDescendantElements()Returns the elements of all descendants of this node.Set<Node<T>>getDescendants()Returns all descendants of this node.StringgetIdentifier()Returns the identifier of this node's element.TgetNodeElement()Returns the element stored in this node.Set<Node<T>>getParents()Returns the parents of this node -- more than one for a node with genuine multiple inheritance within this hierarchy (seeparents), empty if this is a root.StringtoString()
-
-
-
Field Detail
-
INDENTATION
public static String INDENTATION
The string used for indentation when printing the DAG.
-
t
protected T t
The element stored in 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 -- aSet, 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), andaddChild(Node)is called once per matching parent.
-
-
Constructor Detail
-
Node
public Node(T t)
Constructs a new node with the given element.- Parameters:
t- The element to store in the node.
-
-
Method Detail
-
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 (seeparents), 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.
-
compareTo
public int compareTo(Node<T> other)
- Specified by:
compareToin interfaceComparable<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.
-
-