List of usage examples for com.google.common.graph ElementOrder sorted
public static <S> ElementOrder<S> sorted(Comparator<S> comparator)
From source file:org.apache.beam.runners.core.construction.graph.Networks.java
/** * Return a set of nodes in sorted topological order. * * <p>Note that back edges within directed graphs are "broken" returning a topological order for a * directed acyclic network which approximates the original network. * * <p>Nodes will be considered in the order specified by the {@link * ElementOrder#sorted(Comparator) sorted ElementOrder} created with the provided comparator. *//*from ww w .j a v a2 s . co m*/ public static <NodeT, EdgeT> Iterable<NodeT> topologicalOrder(Network<NodeT, EdgeT> network, Comparator<NodeT> nodeOrder) { // Copy the characteristics of the network to ensure that the result network can represent the // original network, just with the provided suborder MutableNetwork<NodeT, EdgeT> orderedNetwork = NetworkBuilder.from(network) .nodeOrder(ElementOrder.sorted(nodeOrder)).build(); for (NodeT node : network.nodes()) { orderedNetwork.addNode(node); } for (EdgeT edge : network.edges()) { EndpointPair<NodeT> incident = network.incidentNodes(edge); orderedNetwork.addEdge(incident.source(), incident.target(), edge); } return computeTopologicalOrder(orderedNetwork); }