@Test(expected = IllegalStateException.class) public void testWithCycle() { Map<String, Collection<String>> g = UtilMisc.toMap( "a", asList("b"), "b", asList("c"), "c", asList("a")); Digraph<String> dg = new Digraph<>(g); dg.sort(); }
public List<T> sort() throws IllegalStateException { Set<T> permanents = new HashSet<>(); Set<T> temporaries = new HashSet<>(); List<T> result = new ArrayList<>(); for (T node : nodes) { if (!permanents.contains(node)) { visit(result, node, permanents, temporaries); } } return result; }
Digraph { public List<T> sort() throws IllegalStateException { Set<T> permanents = new HashSet<>(); Set<T> temporaries = new HashSet<>(); List<T> result = new ArrayList<>(); for (T node : nodes) { if (!permanents.contains(node)) { visit(result, node, permanents, temporaries); } } return result; } }
Digraph { public List<T> sort() throws IllegalStateException { Set<T> permanents = new HashSet<>(); Set<T> temporaries = new HashSet<>(); List<T> result = new ArrayList<>(); for (T node : nodes) { if (!permanents.contains(node)) { visit(result, node, permanents, temporaries); } } return result; } Digraph(Map<T, Collection<T>> spec); }
Digraph { public List<T> sort() throws IllegalStateException { Set<T> permanents = new HashSet<>(); Set<T> temporaries = new HashSet<>(); List<T> result = new ArrayList<>(); for (T node : nodes) { if (!permanents.contains(node)) { visit(result, node, permanents, temporaries); } } return result; } Digraph(Map<T, Collection<T>> spec); List<T> sort(); }
Digraph { public List<T> sort() throws IllegalStateException { Set<T> permanents = new HashSet<>(); Set<T> temporaries = new HashSet<>(); List<T> result = new ArrayList<>(); for (T node : nodes) { if (!permanents.contains(node)) { visit(result, node, permanents, temporaries); } } return result; } Digraph(Map<T, Collection<T>> spec); List<T> sort();  }