void () { // dependencies Map<String, Iterable<String>> nodes = new HashMap<>(); nodes.put("A", List.of("B", "C", "D")); nodes.put("B", List.of("E", "F")); nodes.put("C", List.of("E", "G")); nodes.put("D", List.of("H")); nodes.put("E", List.of("I")); nodes.put("I", List.of("A")); runTraversal("Recurse including head", "A,B,C,D,E,F,I,G,H", Iterators.recurse("A", n -> Iterators.filter(nodes.get(n), Objects::nonNull), true)); runTraversal("Recurse without head", "B,C,D,E,F,I,G,H", Iterators.recurse("A", n -> Iterators.filter(nodes.get(n), Objects::nonNull), false)); runTraversal("RecurseDeep including head", "A,B,E,I,F,C,G,D,H", Iterators.recurseDepth("A", n -> Iterators.filter(nodes.get(n), Objects::nonNull), true)); runTraversal("RecurseDeep without head", "B,E,I,F,C,G,D,H", Iterators.recurseDepth("A", n -> Iterators.filter(nodes.get(n), Objects::nonNull), false)); }