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
-
Method Summary
Modifier and TypeMethodDescriptionvoid
addDependency
(T from, T to) Add a dependency between two elementsvoid
clearAll()
getDependents
(T element) Return the dependentsboolean
hasDependent
(T element) Check if an element is depended onvoid
Remove element from the graphvoid
removeDependency
(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
-