private void recomputeRootAndLeavesIfDirty() { if (isDirty) { root = null; leaves = new HashSet<V>(); isDirty = false; for (V vertex : tree.vertexSet()) { if (tree.inDegreeOf(vertex)==0) { Verify.verify(root==null, "More than one root in tree."); root = vertex; } if (tree.outDegreeOf(vertex)==0) { leaves.add(vertex); } } } }