(C) Copyright 2003-2020, by Barak Naveh and Contributors.
*
* JGraphT : a free Java graph-theory library
*
* See the CONTRIBUTORS.md file distributed with this work for additional
* information regarding copyright ownership.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0, or the
* GNU Lesser General Public License v2.1 or later
* which is available at
* http://www.gnu.org/licenses/old-licenses/lgpl-2.1-standalone.html.
*
* SPDX-License-Identifier: EPL-2.0 OR LGPL-2.1-or-later
*/
package org.jgrapht.graph;

import org.jgrapht.*;
import org.jgrapht.graph.specifics.*;
import org.jgrapht.util.*;

import java.io.*;
import java.util.*;
import java.util.function.*;

/**
* The most general implementation of the {@link org.jgrapht.Graph} interface.
*
* <p>
* Its subclasses add various restrictions to get more specific graphs. The decision whether it is
* directed or undirected is decided at construction time and cannot be later modified (see
* constructor for details).
*
* <p>
* The behavior of this class can be adjusted by changing the {@link GraphSpecificsStrategy} that is
* provided from the constructor. All implemented strategies guarantee deterministic vertex and edge
* set ordering (via {@link LinkedHashMap} and {@link LinkedHashSet}). The defaults are reasonable
* for most use-cases, only change if you know what you are doing.
*
* @param <V> the graph vertex type
* @param <E> the graph edge type
*
* @author Barak Naveh
* @author Dimitrios Michail
*/
public abstract class AbstractBaseGraph<V, E>
extends
AbstractGraph<V, E>
implements
Graph<V, E>,
Cloneable,
Serializable
{
private static final long serialVersionUID = -3582386521833998627L;

private static final String LOOPS_NOT_ALLOWED = "loops not allowed";
private static final String GRAPH_SPECIFICS_MUST_NOT_BE_NULL =
"Graph specifics must not be null";
private static final String INVALID_VERTEX_SUPPLIER_DOES_NOT_RETURN_UNIQUE_VERTICES_ON_EACH_CALL =
"Invalid vertex supplier (does not return unique vertices on each call).";
private static final String MIXED_GRAPH_NOT_SUPPORTED = "Mixed graph not supported";
private static final String GRAPH_SPECIFICS_STRATEGY_REQUIRED =
"Graph specifics strategy required";
private static final String THE_GRAPH_CONTAINS_NO_VERTEX_SUPPLIER =
"The graph contains no vertex supplier";
private static final String THE_GRAPH_CONTAINS_NO_EDGE_SUPPLIER =
"The graph contains no edge supplier";

private transient Set<V> unmodifiableVertexSet = null;

private Supplier<V> vertexSupplier;
private Supplier<E> edgeSupplier;
private GraphType type;

private Specifics<V, E> specifics;
private IntrusiveEdgesSpecifics<V, E> intrusiveEdgesSpecifics;
private GraphSpecificsStrategy<V, E> graphSpecificsStrategy;

/**
* Construct a new graph.
*
* @param vertexSupplier the vertex supplier, can be null
* @param edgeSupplier the edge supplier, can be null
* @param type the graph type
*
* @throws IllegalArgumentException if the graph type is mixed
*/
protected AbstractBaseGraph(
Supplier<V> vertexSupplier, Supplier<E> edgeSupplier, GraphType type)
{
this(vertexSupplier, edgeSupplier, type, new FastLookupGraphSpecificsStrategy<>());



