DAGImpl implements DAG<V> { @Override public boolean removeVertex(final V v) { final Set<V> neighbors = adjacent.remove(v); if (neighbors != null) { inDegrees.remove(v); for (final V neighbor : neighbors) { final int inDegree = inDegrees.get(neighbor) - 1; inDegrees.put(neighbor, inDegree); if (inDegree == 0) { rootVertices.add(neighbor); } } rootVertices.remove(v); numVertices--; return true; } else { LOG.log(Level.WARNING, "The vertex {0} does exists", v); return false; } }  @Override Set<V> getRootVertices(); @Override boolean isAdjacent(final V v, final V w); @Override Set<V> getNeighbors(final V v); @Override boolean addVertex(final V v); @Override boolean removeVertex(final V v); @Override boolean addEdge(final V v, final V w); @Override boolean removeEdge(final V v, final V w); @Override int getInDegree(final V v); @Override int getNumVertices(); @Override String toString(); @Override String toJSON();  }
@Test public void removeVertexTest() { final List<Integer> expected = ImmutableList.of(1, 3); final DAG<Integer> dag = new DAGImpl<>(); dag.addVertex(1); dag.addVertex(2); dag.addVertex(3); dag.addVertex(4); dag.removeVertex(2); dag.removeVertex(4); assertEquals(new HashSet<>(expected), dag.getRootVertices()); }