Networks { public static <NodeT, EdgeT> Set<NodeT> reachableNodes( Network<NodeT, EdgeT> network, Set<NodeT> startNodes, Set<NodeT> endNodes) { Set<NodeT> visitedNodes = new HashSet<>(); Queue<NodeT> queuedNodes = new ArrayDeque<>(); queuedNodes.addAll(startNodes); while (!queuedNodes.isEmpty()) { NodeT currentNode = queuedNodes.remove(); if (!visitedNodes.add(currentNode) || endNodes.contains(currentNode)) { continue; } queuedNodes.addAll(network.successors(currentNode)); } return visitedNodes; } private  Networks(); static void replaceDirectedNetworkNodes(
      MutableNetwork<NodeT, EdgeT> network, Function<NodeT, NodeT> function); static Set<NodeT> reachableNodes(
      Network<NodeT, EdgeT> network, Set<NodeT> startNodes, Set<NodeT> endNodes); static Iterable<NodeT> topologicalOrder(Network<NodeT, ?> network); static Iterable<NodeT> topologicalOrder(
      Network<NodeT, EdgeT> network, Comparator<NodeT> nodeOrder); static String toDot(Network<NodeT, EdgeT> network); static List<List<NodeT>> allPathsFromRootsToLeaves(
      Network<NodeT, EdgeT> network);  }
@Test public void testReachableNodesWithEmptyNetwork() { assertThat( Networks.reachableNodes( createEmptyNetwork(), Collections.emptySet(), Collections.emptySet()), empty()); }
@Test public void testReachableNodesFromAllRoots() { assertEquals( createNetwork().nodes(), Networks.reachableNodes( createNetwork(), ImmutableSet.of("A", "D", "I", "M", "O"), Collections.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"))); }