class UndirectedGraphImpl implements UndirectedGraph<V, E> {

    @Override
    public int addEdge(int v1, int v2, E obj) {
        checkVertex(v1);
        checkVertex(v2);
        int e;
        Edge<E> edge = new Edge<>(v1, v2, obj);
        if (removedEdges.isEmpty()) {
            e = edges.size();
            edges.add(edge);
        } else {
            e = removedEdges.removeAt(0);
            edges.set(e, edge);
        }
        invalidateAdjacencyList();
        notifyListener();
        return e;
    }

}