K - type of key (usually identifier) of the sorted itemV - type of sorted itempublic final class TopoSorter<K,V> extends Object
X <-- Y (i.e. Y depends on X)
the algorithm generates a sorted list L where
L.indexOf(X) < L.indexOf(Y).
In case the input structure contain one or more cycles, the algorithm
does its best to sort the non-cyclic part but throws TopoCycleException
at the end. The sorted items as well as nodes found in cycles can be obtained from
the exception.
To allow a wide spectrum of applications, the algorithm assumes that every item is identified by a unique key. Dependencies of an item are subsequently defined as a set of other items' keys.
| Modifier and Type | Method and Description |
|---|---|
static <K,V> List<V> |
sort(Collection<? extends TopoNode<? extends K,? extends V>> sourceNodes)
Processes the given collection of
TopoNode nodes and returns the topologically
sorted list of items represented by input nodes or, if a cycle in dependency graph is detected,
throws TopoCycleException. |
static <K,V> void |
sortTo(Collection<? extends TopoNode<? extends K,? extends V>> sourceNodes,
List<? super V> target)
Processes the given collection of
TopoNode nodes and appends the topologically
sorted items represented by input nodes to the end of target list. |
public static <K,V> List<V> sort(Collection<? extends TopoNode<? extends K,? extends V>> sourceNodes) throws TopoCycleException
TopoNode nodes and returns the topologically
sorted list of items represented by input nodes or, if a cycle in dependency graph is detected,
throws TopoCycleException.K - type of key (usually identifier) of the sorted itemV - type of sorted itemsourceNodes - collection of source nodes encapsulating sorted items and their dependenciesTopoCycleException - if a cycle is detected in dependency relationspublic static <K,V> void sortTo(Collection<? extends TopoNode<? extends K,? extends V>> sourceNodes, List<? super V> target) throws TopoCycleException
TopoNode nodes and appends the topologically
sorted items represented by input nodes to the end of target list. If a cycle in dependency
graph is detected, throws TopoCycleException; the target list may or may not have
been modified.K - type of key (usually identifier) of the sorted itemV - type of sorted itemsourceNodes - collection of source nodes encapsulating sorted items and their dependenciestarget - target list to which the sorted items are appendedTopoCycleException - the topo cycle exceptionNullPointerException - if target list is nullCopyright © 2014 Boleslav Bobcik - Auderis. All rights reserved.