Package org.gcube.informationsystem.dag
Class Dag<T>
- java.lang.Object
-
- org.gcube.informationsystem.dag.Dag<T>
-
- Type Parameters:
T- The type of the elements stored in the graph.
public class Dag<T> extends Object
A single-rooted, directed, acyclic graph (DAG) -- typically a tree in practice (single inheritance), but genuinely a DAG wheneverallowMultipleInheritanceproduces a node with more than one parent (seeNode.getParents()): each node has exactly one identity, reachable through every parent that legitimately leads to it.- Author:
- Luca Frosini (ISTI - CNR)
-
-
Constructor Summary
Constructors Constructor Description Dag()Constructs an empty DAG.Dag(NodeInformation<T> ni)Constructs a DAG with the given node information provider.Dag(T root, NodeInformation<T> ni)Constructs a DAG with the given root element and node information provider.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Node<T>addNode(T t)Adds a new node to the DAG.voidelaborate(NodeElaborator<T> nodeElaborator)Traverses the DAG and applies the given elaborator to each node.Node<T>getNodeByIdentifier(String identifier)Returns the node with the given identifier.NodeInformation<T>getNodeInformation()Returns the node information provider for this DAG.Node<T>getRootNode()Returns the root node of the DAG.booleanisChildOf(String referenceIdentifier, String requiredChild)Checks if a node is a child of another node.booleanisParentOf(String referenceIdentifier, String requiredParent)Checks if a node is a parent of another node.voidsetAllowMultipleInheritance(boolean allowMultipleInheritance)Sets whether multiple inheritance is allowed in this DAG.voidsetNodeInformation(NodeInformation<T> ni)Sets the node information provider for this DAG, if not already set.voidsetRoot(T root)Sets the root element of this DAG, if not already set.StringtoString()
-
-
-
Constructor Detail
-
Dag
public Dag()
Constructs an empty DAG.
-
Dag
public Dag(NodeInformation<T> ni)
Constructs a DAG with the given node information provider.- Parameters:
ni- The node information provider.
-
Dag
public Dag(T root, NodeInformation<T> ni)
Constructs a DAG with the given root element and node information provider.- Parameters:
root- The root element.ni- The node information provider.
-
-
Method Detail
-
setNodeInformation
public void setNodeInformation(NodeInformation<T> ni)
Sets the node information provider for this DAG, if not already set.- Parameters:
ni- The node information provider.
-
setRoot
public void setRoot(T root) throws RuntimeException
Sets the root element of this DAG, if not already set.- Parameters:
root- The root element.- Throws:
RuntimeException- if the node information provider has not been set.
-
setAllowMultipleInheritance
public void setAllowMultipleInheritance(boolean allowMultipleInheritance)
Sets whether multiple inheritance is allowed in this DAG.- Parameters:
allowMultipleInheritance-trueto allow multiple inheritance.
-
getNodeInformation
public NodeInformation<T> getNodeInformation()
Returns the node information provider for this DAG.- Returns:
- The node information provider.
-
addNode
public Node<T> addNode(T t)
Adds a new node to the DAG.- Parameters:
t- The element to add.- Returns:
- The newly created or existing node for the element.
-
elaborate
public void elaborate(NodeElaborator<T> nodeElaborator) throws Exception
Traverses the DAG and applies the given elaborator to each node.- Parameters:
nodeElaborator- The elaborator to apply.- Throws:
Exception- if an error occurs during elaboration.
-
getNodeByIdentifier
public Node<T> getNodeByIdentifier(String identifier)
Returns the node with the given identifier.- Parameters:
identifier- The identifier of the node.- Returns:
- The node, or
nullif not found.
-
isChildOf
public boolean isChildOf(String referenceIdentifier, String requiredChild)
Checks if a node is a child of another node.- Parameters:
referenceIdentifier- The identifier of the potential parent node.requiredChild- The identifier of the potential child node.- Returns:
trueif the second node is a child of the first.
-
isParentOf
public boolean isParentOf(String referenceIdentifier, String requiredParent)
Checks if a node is a parent of another node.- Parameters:
referenceIdentifier- The identifier of the potential child node.requiredParent- The identifier of the potential parent node.- Returns:
trueif the second node is a parent of the first.
-
-