Networks { public static <N, E> Set<N> reachableNodes( Network<N, E> network, Set<N> startNodes, Set<N> endNodes) { Set<N> visitedNodes = new HashSet<>(); Queue<N> queuedNodes = new ArrayDeque<>(); queuedNodes.addAll(startNodes); while (!queuedNodes.isEmpty()) { N currentNode = queuedNodes.remove(); if (!visitedNodes.add(currentNode) || endNodes.contains(currentNode)) { continue; } queuedNodes.addAll(network.successors(currentNode)); } return visitedNodes; } 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 testReachableNodesWithEmptyNetwork() { assertThat( Networks.reachableNodes( createEmptyNetwork(), Collections.<String>emptySet(), Collections.<String>emptySet()), empty()); }
@Test public void testReachableNodesFromAllRoots() { assertEquals( createNetwork().nodes(), Networks.reachableNodes( createNetwork(), ImmutableSet.of("A", "D", "I", "M", "O"), Collections.<String>emptySet())); }
@Test public void testReachableNodesFromAllRootsToAllRoots() { assertEquals( ImmutableSet.of("A", "D", "I", "M", "O"), Networks.reachableNodes( createNetwork(), ImmutableSet.of("A", "D", "I", "M", "O"), ImmutableSet.of("A", "D", "I", "M", "O"))); }
@Test public void testReachableNodesWithPathAroundBoundaryNode() { assertEquals( ImmutableSet.of("I", "J", "E", "G", "H", "K", "L"), Networks.reachableNodes(createNetwork(), ImmutableSet.of("I"), ImmutableSet.of("J"))); }