Package org.jtrim2.taskgraph.basic
Class DependencyDag<N>
java.lang.Object
org.jtrim2.taskgraph.basic.DependencyDag<N>
- Type Parameters:
N
- the type of the node. The nodes are distinguished based on theirequals
.
Defines a directed acyclic graph (DAG).
DependencyDag
allows
requesting the edges in both direction for easy traversal.
Thread safety
Instances ofDependencyDag
are immutable (assuming the nodes themselves
are immutable) and so can be used safely by multiple threads concurrently.
Synchronization transparency
The methods ofDependencyDag
are synchronization transparent.-
Constructor Summary
ConstructorDescriptionDependencyDag
(DirectedGraph<N> dependencyGraph) Creates aDependencyDag
from a directed graph where the edges point from dependent node to their dependencies. -
Method Summary
Modifier and TypeMethodDescriptiongetAllLeafToRootNodes
(Iterable<? extends N> rootNodes) Returns a map, mapping the leaf nodes (nodes having no children) to nodes they are reachable where the image of the mapping only contains nodes specified in the argument.getAllLeafToRootNodesOrdered
(Iterable<? extends N> rootNodes) Returns a map, mapping the leaf nodes (nodes having no children) to nodes they are reachable where the image of the mapping only contains nodes specified in the argument.Returns the directed graph where the edges point from dependent node to their dependencies.Returns the directed graph where the edges point from the dependency to dependent node.reverse()
Returns aDependencyDag
having edges in the opposite direction than thisDependencyDag
.
-
Constructor Details
-
DependencyDag
Creates aDependencyDag
from a directed graph where the edges point from dependent node to their dependencies.- Parameters:
dependencyGraph
- the directed graph where the edges point from dependent node to their dependencies. This argument cannot benull
. The passed graph must be acyclic.
-
-
Method Details
-
getDependencyGraph
Returns the directed graph where the edges point from dependent node to their dependencies.- Returns:
- the directed graph where the edges point from dependent node to their dependencies.
This method never returns
null
.
-
getForwardGraph
Returns the directed graph where the edges point from the dependency to dependent node.- Returns:
- the directed graph where the edges point from the dependency to dependent node.
This method never returns
null
.
-
getAllLeafToRootNodesOrdered
Returns a map, mapping the leaf nodes (nodes having no children) to nodes they are reachable where the image of the mapping only contains nodes specified in the argument. If multiple leaf nodes are reachable from a particular node, that particular node will be listed under all the reachable leaf nodes.The nodes from which a particular leaf is reachable are listed in the same order as they appear in the node list given in the argument.
There will not be entry in the map for leaf nodes not reachable from any of the given nodes.
- Parameters:
rootNodes
- the nodes to be considered from where leaf nodes are reachable from. This argument cannot benull
and may not containnull
elements.- Returns:
- a map, mapping the leaf nodes (nodes having no children) to nodes they are
reachable where the image of the mapping only contains nodes specified in the argument.
This method never returns
null
.
-
getAllLeafToRootNodes
Returns a map, mapping the leaf nodes (nodes having no children) to nodes they are reachable where the image of the mapping only contains nodes specified in the argument. If multiple leaf nodes are reachable from a particular node, that particular node will be listed under all the reachable leaf nodes.There will not be entry in the map for leaf nodes not reachable from any of the given nodes.
- Parameters:
rootNodes
- the nodes to be considered from where leaf nodes are reachable from. This argument cannot benull
and may not containnull
elements.- Returns:
- a map, mapping the leaf nodes (nodes having no children) to nodes they are
reachable where the image of the mapping only contains nodes specified in the argument.
This method never returns
null
.
-
reverse
Returns aDependencyDag
having edges in the opposite direction than thisDependencyDag
. That is, itsforward graph
anddependency graph
are reversed.- Returns:
- a
DependencyDag
having edges in the opposite direction than thisDependencyDag
. This method never returnsnull
.
-