/*
* (C) Copyright 2016-2023, by Dimitrios Michail 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.nio.dot;
import org.jgrapht.*;
import org.jgrapht.alg.util.*;
import org.jgrapht.nio.*;
import java.io.*;
import java.util.*;
import java.util.function.*;
/**
* Import a graph from a DOT file.
*
*
* For a description of the format see
* http://en.wikipedia.org/wiki/DOT_language and
*
* http://www.graphviz.org/doc/info/lang.html
*
*
* The provided graph object, where the imported graph will be stored, must be able to support the
* features of the graph that is read. For example if the file contains self-loops then the graph
* provided must also support self-loops. The same for multiple edges. Whether edges are directed or
* not depends on the underlying implementation of the user provided graph object.
*
*
* The graph vertices and edges are build using the corresponding graph suppliers. The id of the
* vertices in the original dot file are reported as a vertex attribute named "ID". Thus, in case
* vertices in the dot file also contain an "ID" attribute, such an attribute will be reported
* multiple times.
*
*
* The default behavior of the importer is to use the graph vertex supplier in order to create
* vertices. The user can also bypass vertex creation by providing a custom vertex factory method
* using {@link #setVertexFactory(Function)}. The factory method is responsible to create a new
* graph vertex given the vertex identifier read from file. Additionally this importer also supports
* creating vertices with {@link #setVertexWithAttributesFactory(BiFunction)}. This factory method
* is responsible for creating a new graph vertex given the vertex identifier read from file
* together with all available attributes of the vertex at the location of the file where the vertex
* is first defined.
*
*
* The default behavior of the importer is to use the graph edge supplier in order to create edges.
* The user can also bypass edge creation by providing a custom edge factory method using
* {@link #setEdgeWithAttributesFactory(Function)}. The factory method is responsible to create a
* new graph edge given all available attributes of the edge at the location of the file where the
* edge is first defined.
*
* @author Dimitrios Michail
*
* @param the graph vertex type
* @param the graph edge type
*/
public class DOTImporter
extends BaseEventDrivenImporter
implements GraphImporter
{
/**
* Default key used for vertex ID.
*/
public static final String DEFAULT_VERTEX_ID_KEY = "ID";
private Function vertexFactory;
private BiFunction, V> vertexWithAttributesFactory;
private Function