public class TopologicalSort
extends java.lang.Object
To be used to sort a list of interdependent nodes, or to find out that this
is impossible because the dependencies are cyclic.
Applications need to wrap each of their nodes with a Vertex object,
set up the directed dependencies between any two such vertex objects
(see addAdjacentVertex), run the sort algorithm,
and then extract the original nodes from the sorted vertices.
Expected use is to detangle component dependencies etc.
| Constructor and Description |
|---|
TopologicalSort(java.util.Collection<Vertex> vertices)
Constructor that takes the nodes, which we hope form a directed acyclic graph
|
| Modifier and Type | Method and Description |
|---|---|
java.util.Map |
getCyclicVertices()
Returns the vertices (graph nodes) that form a back edge in the graph.
|
boolean |
hasCycles()
States whether the graph contains cyclic dependencies,
which implies that it could not be sorted.
|
java.util.List |
sort()
Tries to sort the vertices and to return them in a list.
|
public TopologicalSort(java.util.Collection<Vertex> vertices)
vertices - public java.util.List sort()
hasCycles().public boolean hasCycles()
sort() was called.public java.util.Map getCyclicVertices()