Creates a new traverser for a directed acyclic graph that has at most one path from the start node(s) to any node reachable from the start node(s), and has no paths from any start node to any other start node, such as a tree or forest. <p>{@code forTree()} is especially useful (versus {@code forGra
(SuccessorsFunction<N> tree)
| 176 | * one path between any two nodes |
| 177 | */ |
| 178 | public static <N> Traverser<N> forTree(SuccessorsFunction<N> tree) { |
| 179 | if (tree instanceof BaseGraph) { |
| 180 | checkArgument(((BaseGraph<?>) tree).isDirected(), "Undirected graphs can never be trees."); |
| 181 | } |
| 182 | if (tree instanceof Network) { |
| 183 | checkArgument(((Network<?, ?>) tree).isDirected(), "Undirected networks can never be trees."); |
| 184 | } |
| 185 | return new Traverser<N>(tree) { |
| 186 | @Override |
| 187 | Traversal<N> newTraversal() { |
| 188 | return Traversal.inTree(tree); |
| 189 | } |
| 190 | }; |
| 191 | } |
| 192 | |
| 193 | /** |
| 194 | * Returns an unmodifiable {@code Iterable} over the nodes reachable from {@code startNode}, in |