org.jtrim2.taskgraph.basic.DependencyDag Maven / Gradle / Ivy
package org.jtrim2.taskgraph.basic;
import java.util.Objects;
/**
* Defines a directed acyclic graph (DAG). {@code DependencyDag} allows
* requesting the edges in both direction for easy traversal.
*
* Thread safety
* Instances of {@code DependencyDag} are immutable (assuming the nodes themselves
* are immutable) and so can be used safely by multiple threads concurrently.
*
* Synchronization transparency
* The methods of {@code DependencyDag} are synchronization transparent.
*
* @param the type of the node. The nodes are distinguished based on their
* {@code equals}.
*/
public final class DependencyDag {
private final DirectedGraph dependencyGraph;
private final DirectedGraph forwardGraph;
/**
* Creates a {@code DependencyDag} from a directed graph where the edges point
* from dependent node to their dependencies.
*
* @param dependencyGraph the directed graph where the edges point
* from dependent node to their dependencies. This argument cannot be
* {@code null}. The passed graph must be acyclic.
*/
public DependencyDag(DirectedGraph dependencyGraph) {
Objects.requireNonNull(dependencyGraph, "dependencyGraph");
dependencyGraph.checkNotCyclic();
this.dependencyGraph = dependencyGraph;
this.forwardGraph = dependencyGraph.reverseGraph();
}
/**
* Returns the directed graph where the edges point from dependent node to their dependencies.
*
* @return the directed graph where the edges point from dependent node to their dependencies.
* This method never returns {@code null}.
*/
public DirectedGraph getDependencyGraph() {
return dependencyGraph;
}
/**
* Returns the directed graph where the edges point from the dependency to dependent node.
*
* @return the directed graph where the edges point from the dependency to dependent node.
* This method never returns {@code null}.
*/
public DirectedGraph getForwardGraph() {
return forwardGraph;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy