Package org.infinispan.util
Class DependencyGraph<T>
java.lang.Object
org.infinispan.util.DependencyGraph<T>
Graph to track dependencies between objects
- Since:
- 7.0
- Author:
- gustavonalle
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidaddDependency(T from, T to) Add a dependency between two elementsvoidclearAll()getDependents(T element) Return the dependentsbooleanhasDependent(T element) Check if an element is depended onvoidRemove element from the graphvoidremoveDependency(T from, T to) Remove a dependencyCalculates a topological sort of the graph, in linear time
-
Constructor Details
-
DependencyGraph
public DependencyGraph()
-
-
Method Details
-
topologicalSort
Calculates a topological sort of the graph, in linear time- Returns:
- List
elements sorted respecting dependencies - Throws:
CyclicDependencyException- if cycles are present in the graph and thus no topological sort is possible
-
addDependency
Add a dependency between two elements- Parameters:
from- From elementto- To element
-
removeDependency
Remove a dependency- Parameters:
from- From elementto- To element- Throws:
IllegalArgumentException- if either to or from don't exist
-
clearAll
public void clearAll() -
hasDependent
Check if an element is depended on- Parameters:
element- Element stored in the graph- Returns:
- true if exists any dependency on element
- Throws:
IllegalArgumentException- if element is not present in the graph
-
getDependents
Return the dependents- Parameters:
element- Element contained in the graph- Returns:
- list of elements depending on element
-
remove
Remove element from the graph- Parameters:
element- the element
-