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.
A single-rooted, directed, acyclic graph (DAG) -- typically a tree in practice (single
inheritance), but genuinely a DAG whenever
allowMultipleInheritance produces a node
with more than one parent (see Node.getParents()): each node has exactly one identity,
reachable through every parent that legitimately leads to it.- Author:
- Luca Frosini (ISTI - CNR)
-
Constructor Summary
ConstructorsConstructorDescriptionDag()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
Modifier and TypeMethodDescriptionAdds a new node to the DAG.voidelaborate(NodeElaborator<T> nodeElaborator) Traverses the DAG and applies the given elaborator to each node.getNodeByIdentifier(String identifier) Returns the node with the given identifier.Returns the node information provider for this DAG.Returns the root node of the DAG.booleanChecks 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.voidSets the node information provider for this DAG, if not already set.voidSets the root element of this DAG, if not already set.toString()
-
Constructor Details
-
Dag
public Dag()Constructs an empty DAG. -
Dag
Constructs a DAG with the given node information provider.- Parameters:
ni- The node information provider.
-
Dag
Constructs a DAG with the given root element and node information provider.- Parameters:
root- The root element.ni- The node information provider.
-
-
Method Details
-
setNodeInformation
Sets the node information provider for this DAG, if not already set.- Parameters:
ni- The node information provider.
-
setRoot
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
Returns the node information provider for this DAG.- Returns:
- The node information provider.
-
addNode
Adds a new node to the DAG.- Parameters:
t- The element to add.- Returns:
- The newly created or existing node for the element.
-
getRootNode
Returns the root node of the DAG.- Returns:
- The root node.
-
toString
-
elaborate
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
Returns the node with the given identifier.- Parameters:
identifier- The identifier of the node.- Returns:
- The node, or
nullif not found.
-
isChildOf
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
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.
-