AdjacentListConcurrentMapDAG implements DAG<V, I> { @Override public boolean removeVertex(final V v) { final Map<V, I> edges = adjacent.remove(v); if (edges != null) { numVertices -= 1; final int inDegreeEdges = inDegrees.remove(v); numEdges -= inDegreeEdges; numEdges -= edges.size(); for (final Map.Entry<V, I> edge : edges.entrySet()) { final V neighbor = edge.getKey(); final int inDegree = inDegrees.get(neighbor) - 1; inDegrees.put(neighbor, inDegree); } for (Map.Entry<V, Map<V, I>> entry : adjacent.entrySet()) { entry.getValue().remove(v); } return true; } else { LOG.log(Level.WARNING, "The vertex {0} does exists", new Object[]{v}); return false; } } AdjacentListConcurrentMapDAG(); @Override int numberOfVertices(); @Override int numberOfEdges(); @Override Set<V> getRootVertices(); @Override Collection<V> getVertices(); @Override boolean hasVertex(final V v); @Override boolean isAdjacent(final V v1, final V v2); @Override Map<V, I> getEdges(final V v); @Override boolean addVertex(final V v); @Override boolean removeVertex(final V v); @Override boolean addEdge(final V v1, final V v2, final I i); @Override boolean removeEdge(final V v1, final V v2); @Override int getInDegree(final V v);  }
@Test public void removeVertexTest() { final List<Integer> expected = ImmutableList.of(1, 3); final DAG<Integer, Direction> dag = new AdjacentListConcurrentMapDAG<>(); dag.addVertex(1); dag.addVertex(2); dag.addVertex(3); dag.addVertex(4); dag.removeVertex(2); dag.removeVertex(4); Assert.assertEquals(new HashSet<>(expected), dag.getRootVertices()); }