class 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); // just a guess
        Deque<T> nodePath = new ArrayDeque<>(20); // should be plenty
        boolean isDag = tryAdd(initialNodes, graph, knownNodes, new CycleDetector<>(graph), nodePath);
        if (!isDag) {
            this.badNodes = nodePath;
        }
        return isDag;
    }

}