Package com.jgalgo.io

Class GexfGraphWriter<V,E>

java.lang.Object
com.jgalgo.io.GexfGraphWriter<V,E>
Type Parameters:
V - the vertices type
E - the edges type
All Implemented Interfaces:
GraphWriter<V,E>

public final class GexfGraphWriter<V,E> extends Object
Write a graph in 'GEXF' format.

GEXF is an XML-based format for graphs. Both directed and undirected graphs are supported, along with mixed graphs (some edges are directed while others are undirected) although the Graph does not supported mixed graphs (therefore the writer also doesn't support it). The format support graphs with vertices and edges of any type, as long as they can be written as an XML attribute string. The format also support multiple weights for vertices and edges, of any primitive Java type (int, long, double, boolean, ect.), String, Date, URI, BigInteger, BigDecimal, along with 'list' (arrays) of any of the above except Date and URI.

When the writer writes a graph with weights, it will try to identify the type of weights and write them accordingly. For any of the primitive type weights containers such as WeightsInt, WeightsLong, WeightsDouble, WeightsBool, ect., the writer will easily identify the primitive types. On the other hand, for WeightsObj, the writer will try to identify the type of the weights by checking the type of the default value and the actual weights of the vertices/edges. If all weights (and default value if exists) are a boxed type of any primitive type, the writer will write the weights as the corresponding primitive type. If all weights are String, Date, URI, BigInteger, BigDecimal, the writer will be able to identify the type of the weights and write them accordingly. If all weights are arrays of primitive types (such as int[], long[], double[], boolean[], ect.), or fastutil lists of primitive types (such as IntList, LongList, DoubleList, BooleanList, ect.), or List of boxed primitive types (such as List<Integer>, List<Long>, List<Double>, List<Boolean>, ect.), the writer will write the weights 'list' (array) type of the primitive type (the reader will read them as arrays of primitives). If all weights are arrays of String, BigInteger, BigDecimal, or List of String, BigInteger, BigDecimal, the writer will write the weights as 'list' (array) of String, BigInteger, BigDecimal respectively (the reader will read them as arrays of objects). Note that null weights are not supported and will cause an exception to be thrown.

The GEXF format support both self edges and parallel edges. The format documentation can be found here.

Author:
Barak Ugav
See Also:
  • Constructor Details

    • GexfGraphWriter

      public GexfGraphWriter()
      Create a new writer.
  • Method Details

    • writeGraph

      public final void writeGraph(Graph<V,E> graph, Writer writer)
      Description copied from interface: GraphWriter
      Write a graph to an I/O writer.
      Specified by:
      writeGraph in interface GraphWriter<V,E>
      Parameters:
      graph - a graph
      writer - an I/O writer to which the graph description will be written to