class UndirectedGraphImpl implements UndirectedGraph<V, E> {

    @Override
    public V removeVertex(int v) {
        checkVertex(v);
        for (Edge<E> e : edges) {
            if (e != null && (e.getV1() == v || e.getV2() == v)) {
                throw new PowsyblException("An edge is connected to vertex " + v);
            }
        }
        V obj = vertices.get(v).getObject();
        if (v == vertices.size() - 1) {
            vertices.remove(v);
            cleanVertices(v - 1);
        } else {
            vertices.set(v, null);
            availableVertices.add(v);
        }
        invalidateAdjacencyList();
        notifyListener();
        return obj;
    }

}