/** * Removes the vertex corresponding to the specified JGraph vertex from the JGraphT graph. If the * specified vertex is not contained in {@link #cellToVertex}, it is silently ignored. * * <p>If any edges are incident with this vertex, we first remove them from the both graphs, * because otherwise the JGraph graph would leave them intact and the JGraphT graph would throw * them out. TODO: Revise this behavior now that we gracefully tolerate dangling edges. It might * be possible to remove just the JGraphT edges. The JGraph edges will be left dangling, as a * result. * * <p>This method is to be called only for vertices that have already been removed from the JGraph * graph. * * @param jVertex the JGraph vertex that has been removed. */ void handleJGraphRemovedVertex(GraphCell jVertex) { if (cellToVertex.containsKey(jVertex)) { V jtVertex = cellToVertex.get(jVertex); Set<E> jtIncidentEdges = jtGraph.edgesOf(jtVertex); if (!jtIncidentEdges.isEmpty()) { // We can't just call removeAllEdges with this list: that // would throw a ConcurrentModificationException. So we create // a shallow copy. // This also triggers removal of the corresponding JGraph // edges. jtGraph.removeAllEdges(new ArrayList<E>(jtIncidentEdges)); } jtGraph.removeVertex(jtVertex); cellToVertex.remove(jVertex); vertexToCell.remove(jtVertex); } }