/** * @param label The label of the Vertex to remove * @return Vertex The removed Vertex object */ public Vertex removeVertex(String label) { Vertex v = vertices.remove(label); while (v.getNeighborCount() > 0) { this.removeEdge(v.getNeighbor((0))); } return v; }
/** * This method adds a Vertex to the graph. If a Vertex with the same label as the parameter exists * in the Graph, the existing Vertex is overwritten only if overwriteExisting is true. If the * existing Vertex is overwritten, the Edges incident to it are all removed from the Graph. * * @param vertex * @param overwriteExisting * @return true iff vertex was added to the Graph */ public boolean addVertex(Vertex vertex, boolean overwriteExisting) { Vertex current = this.vertices.get(vertex.getLabel()); if (current != null) { if (!overwriteExisting) { return false; } while (current.getNeighborCount() > 0) { this.removeEdge(current.getNeighbor(0)); } } vertices.put(vertex.getLabel(), vertex); return true; }