/** * Adds to the underlying JGraphT graph a vertex corresponding to the specified JGraph vertex. In * JGraph, two vertices with the same user object are in principle allowed; in JGraphT, this would * lead to duplicate vertices, which is not allowed. So if such vertex already exists, the * specified vertex is REMOVED from the JGraph graph and a a warning is printed. * * <p>This method is to be called only for vertices that have already been added to the JGraph * graph. * * @param jVertex the JGraph vertex that has been added. */ @SuppressWarnings("unchecked") void handleJGraphInsertedVertex(GraphCell jVertex) { V jtVertex; if (jVertex instanceof DefaultGraphCell) { // FIXME hb 28-nov-05: waiting for jgraph to go generic jtVertex = (V) ((DefaultGraphCell) jVertex).getUserObject(); } else { // FIXME: Why toString? Explain if for a good reason otherwise fix. jtVertex = (V) jVertex.toString(); } if (vertexToCell.containsKey(jtVertex)) { // We have to remove the new vertex, because it would lead to // duplicate vertices. We can't use ShieldedGraph.removeVertex for // that, because it would remove the wrong (existing) vertex. System.err.println( "Warning: detected two JGraph vertices with " + "the same JGraphT vertex as user object. It is an " + "indication for a faulty situation that should NOT happen." + "Removing vertex: " + jVertex); internalRemoveCell(jVertex); } else { jtGraph.addVertex(jtVertex); cellToVertex.put(jVertex, jtVertex); vertexToCell.put(jtVertex, jVertex); } }