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 their equals.

public final class DependencyDag<N> extends Object
Defines a directed acyclic graph (DAG). DependencyDag allows requesting the edges in both direction for easy traversal.

Thread safety

Instances of DependencyDag are immutable (assuming the nodes themselves are immutable) and so can be used safely by multiple threads concurrently.

Synchronization transparency

The methods of DependencyDag are synchronization transparent.
  • Constructor Details

    • DependencyDag

      public DependencyDag(DirectedGraph<N> dependencyGraph)
      Creates a DependencyDag 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 be null. The passed graph must be acyclic.
  • Method Details

    • getDependencyGraph

      public DirectedGraph<N> 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

      public DirectedGraph<N> 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

      public Map<N,List<N>> 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. 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 be null and may not contain null 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

      public Map<N,Set<N>> getAllLeafToRootNodes(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. 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 be null and may not contain null 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

      public DependencyDag<N> reverse()
      Returns a DependencyDag having edges in the opposite direction than this DependencyDag. That is, its forward graph and dependency graph are reversed.
      Returns:
      a DependencyDag having edges in the opposite direction than this DependencyDag. This method never returns null.