Class JSONExporter<V,E>
java.lang.Object
org.jgrapht.nio.BaseExporter<V,E>
org.jgrapht.nio.json.JSONExporter<V,E>
- Type Parameters:
V- the graph vertex typeE- the graph edge type
- All Implemented Interfaces:
GraphExporter<V,E>
Exports a graph using JSON.
The output is one object which contains:
- A member named
nodeswhose value is an array of nodes. - A member named
edgeswhose value is an array of edges. - Two members named
creatorandversionfor metadata.
Each node contains an identifier and possibly other attributes. Similarly each edge contains the
source and target vertices, a possible identifier and possible other attributes. All these can be
adjusted using the setters. The default constructor constructs integer identifiers using an
IntegerIdProvider for both vertices and edges and does not output any custom attributes.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final Stringstatic final StringDefault name for the edges collectionstatic final StringDefault name for the vertices collectionprivate Stringprivate static final Stringprivate StringFields inherited from class BaseExporter
edgeAttributeProvider, edgeIdProvider, graphAttributeProvider, graphIdProvider, vertexAttributeProvider, vertexIdProvider -
Constructor Summary
ConstructorsConstructorDescriptionCreates a new exporter with integers for the vertex identifiers.JSONExporter(Function<V, String> vertexIdProvider) Creates a new exporter. -
Method Summary
Modifier and TypeMethodDescriptionprivate voidexportEdge(PrintWriter out, Graph<V, E> g, E e) private voidexportEdgeAttributes(PrintWriter out, Graph<V, E> g, E e) voidexportGraph(Graph<V, E> g, Writer writer) Export a graph using the givenWriter.private voidexportVertex(PrintWriter out, Graph<V, E> g, V v) private voidexportVertexAttributes(PrintWriter out, Graph<V, E> g, V v) Get the name used for the edges collection in the file.Get the name used for the vertices collection in the file.private voidoutputValue(PrintWriter out, Attribute value) private StringvoidsetEdgesCollectionName(String edgesCollectionName) Set the name used for the edges collection in the file.voidsetVerticesCollectionName(String verticesCollectionName) Set the name used for the vertices collection in the file.Methods inherited from class BaseExporter
getEdgeAttribute, getEdgeAttributeProvider, getEdgeAttributes, getEdgeId, getEdgeIdProvider, getGraphAttribute, getGraphAttributeProvider, getGraphId, getGraphIdProvider, getVertexAttribute, getVertexAttributeProvider, getVertexAttributes, getVertexId, getVertexIdProvider, setEdgeAttributeProvider, setEdgeIdProvider, setGraphAttributeProvider, setGraphIdProvider, setVertexAttributeProvider, setVertexIdProviderMethods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface GraphExporter
exportGraph, exportGraph
-
Field Details
-
DEFAULT_VERTICES_COLLECTION_NAME
Default name for the vertices collection- See Also:
-
DEFAULT_EDGES_COLLECTION_NAME
Default name for the edges collection- See Also:
-
CREATOR
- See Also:
-
VERSION
- See Also:
-
verticesCollectionName
-
edgesCollectionName
-
-
Constructor Details
-
JSONExporter
public JSONExporter()Creates a new exporter with integers for the vertex identifiers. -
JSONExporter
-
-
Method Details
-
getVerticesCollectionName
Get the name used for the vertices collection in the file.- Returns:
- the name used for the vertices collection in the file.
-
setVerticesCollectionName
Set the name used for the vertices collection in the file.- Parameters:
verticesCollectionName- the name
-
getEdgesCollectionName
Get the name used for the edges collection in the file.- Returns:
- the name used for the edges collection in the file.
-
setEdgesCollectionName
Set the name used for the edges collection in the file.- Parameters:
edgesCollectionName- the name
-
exportGraph
Description copied from interface:GraphExporterExport a graph using the givenWriter.It is the callers responsibility to ensure the
Writeris closed after this method returned.- Specified by:
exportGraphin interfaceGraphExporter<V,E> - Parameters:
g- the graph to exportwriter- the output writer
-
exportVertex
-
exportEdge
-
exportVertexAttributes
-
exportEdgeAttributes
-
outputValue
-
quoted
-