Class JSONExporter<V,​E>

  • Type Parameters:
    V - the graph vertex type
    E - the graph edge type
    All Implemented Interfaces:
    GraphExporter<V,​E>

    public class JSONExporter<V,​E>
    extends BaseExporter<V,​E>
    implements GraphExporter<V,​E>
    Exports a graph using JSON.

    The output is one object which contains:

    • A member named nodes whose value is an array of nodes.
    • A member named edges whose value is an array of edges.
    • Two members named creator and version for 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.

    Author:
    Dimitrios Michail
    • Field Detail

      • DEFAULT_VERTICES_COLLECTION_NAME

        public static final String DEFAULT_VERTICES_COLLECTION_NAME
        Default name for the vertices collection
        See Also:
        Constant Field Values
      • DEFAULT_EDGES_COLLECTION_NAME

        public static final String DEFAULT_EDGES_COLLECTION_NAME
        Default name for the edges collection
        See Also:
        Constant Field Values
    • Constructor Detail

      • JSONExporter

        public JSONExporter()
        Creates a new exporter with integers for the vertex identifiers.
      • JSONExporter

        public JSONExporter​(Function<V,​String> vertexIdProvider)
        Creates a new exporter.
        Parameters:
        vertexIdProvider - for generating vertex identifiers. Must not be null.
    • Method Detail

      • getVerticesCollectionName

        public String getVerticesCollectionName()
        Get the name used for the vertices collection in the file.
        Returns:
        the name used for the vertices collection in the file.
      • setVerticesCollectionName

        public void setVerticesCollectionName​(String verticesCollectionName)
        Set the name used for the vertices collection in the file.
        Parameters:
        verticesCollectionName - the name
      • getEdgesCollectionName

        public String getEdgesCollectionName()
        Get the name used for the edges collection in the file.
        Returns:
        the name used for the edges collection in the file.
      • setEdgesCollectionName

        public void setEdgesCollectionName​(String edgesCollectionName)
        Set the name used for the edges collection in the file.
        Parameters:
        edgesCollectionName - the name
      • exportGraph

        public void exportGraph​(Graph<V,​E> g,
                                Writer writer)
        Description copied from interface: GraphExporter
        Export a graph using the given Writer.

        It is the callers responsibility to ensure the Writer is closed after this method returned.

        Specified by:
        exportGraph in interface GraphExporter<V,​E>
        Parameters:
        g - the graph to export
        writer - the output writer