Package org.infinispan.util
Class DependencyGraph<T>
- java.lang.Object
-
- org.infinispan.util.DependencyGraph<T>
-
@ThreadSafe public final class DependencyGraph<T> extends Object
Graph to track dependencies between objects- Since:
- 7.0
- Author:
- gustavonalle
-
-
Constructor Summary
Constructors Constructor Description DependencyGraph()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addDependency(T from, T to)
Add a dependency between two elementsvoid
clearAll()
Set<T>
getDependents(T element)
Return the dependentsboolean
hasDependent(T element)
Check if an element is depended onvoid
remove(T element)
Remove element from the graphvoid
removeDependency(T from, T to)
Remove a dependencyList<T>
topologicalSort()
Calculates a topological sort of the graph, in linear time
-
-
-
Method Detail
-
topologicalSort
public List<T> topologicalSort() throws CyclicDependencyException
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
public void addDependency(T from, T to)
Add a dependency between two elements- Parameters:
from
- From elementto
- To element
-
removeDependency
public void removeDependency(T from, T to)
Remove a dependency- Parameters:
from
- From elementto
- To element- Throws:
IllegalArgumentException
- if either to or from don't exist
-
clearAll
public void clearAll()
-
hasDependent
public boolean hasDependent(T element)
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
public Set<T> getDependents(T element)
Return the dependents- Parameters:
element
- Element contained in the graph- Returns:
- list of elements depending on element
-
remove
public void remove(T element)
Remove element from the graph- Parameters:
element
- the element
-
-