Networks { public static <N, E> Set<N> topologicalOrder(Network<N, E> network) { checkArgument(network.isDirected(), "Only directed networks are supported, given %s", network); checkArgument( !network.allowsSelfLoops(), "Only networks without self loops are supported, given %s", network); LinkedHashSet<N> nodes = new LinkedHashSet<>(network.nodes().size()); Queue<N> processingOrder = new ArrayDeque<>(); for (N node : network.nodes()) { if (network.inDegree(node) == 0) { processingOrder.add(node); } } while (!processingOrder.isEmpty()) { N current = processingOrder.remove(); if (nodes.containsAll(network.predecessors(current))) { nodes.add(current); processingOrder.addAll(network.successors(current)); } else { processingOrder.add(current); } } return nodes; } private  Networks(); static void replaceDirectedNetworkNodes(
      MutableNetwork<N, E> network, Function<N, N> function); static Set<N> reachableNodes(
      Network<N, E> network, Set<N> startNodes, Set<N> endNodes); static Set<N> topologicalOrder(Network<N, E> network); static String toDot(Network<N, E> network); static List<List<NodeT>> allPathsFromRootsToLeaves(
      Network<NodeT, EdgeT> network);  }
@Test public void testTopologicalSortWithEmptyNetwork() { assertThat(Networks.topologicalOrder(createEmptyNetwork()), empty()); }