class UndirectedGraphImpl implements UndirectedGraph<V, E> {

    @Override
    public int addVertex() {
        int v;
        if (availableVertices.isEmpty()) {
            v = vertices.size();
            vertices.add(new Vertex<>());
        } else {
            v = availableVertices.iterator().next();
            availableVertices.remove(v);
        }
        invalidateAdjacencyList();
        notifyListener();
        return v;
    }

}