DagChecker { public boolean isDag() { DirectedGraph<T, Pair> graph = new DefaultDirectedGraph<>(Pair.class); Set<? extends T> initialNodes = initialNodes(); Set<T> knownNodes = new HashSet<>(initialNodes.size() * 10); Deque<T> nodePath = new ArrayDeque<>(20); boolean isDag = tryAdd(initialNodes, graph, knownNodes, new CycleDetector<>(graph), nodePath); if (!isDag) { this.badNodes = nodePath; } return isDag; }  boolean isDag(); List<T> getBadNodePath();  }
@Test public void empty() { new GraphFactory().isDag(); }
@Test public void line() { new GraphFactory().connect("a", "b").connect("b", "c").isDag(); }
@Test public void split() { new GraphFactory() .connect("a", "b1").connect("b1", "c") .connect("a", "b2").connect("b2", "c") .isDag(); }