Class GexfGraphReader<V,E>
- java.lang.Object
-
- com.jgalgo.io.GexfGraphReader<V,E>
-
- Type Parameters:
V
- the vertices typeE
- the edges type
- All Implemented Interfaces:
GraphReader<V,E>
public final class GexfGraphReader<V,E> extends Object
Read 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 reader 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 exceptDate
andURI
.Identifiers of vertices are mandatory, and must be unique. Identifiers of edges are optional, if not specified the reader will try generate them using a builder provided by the user, or a default builder for certain types (see
setEdgeBuilder(IdBuilder)
andsetEdgeBuilderDefault(Class)
). Vertices identifiers (and edges identifiers if specified) are parsed using a parser provided by the user, or a default parser for certain types (seesetVertexParserDefault(Class)
andsetEdgeParserDefault(Class)
).When the reader reads a graph with weights, it will create a
Weights
object for each type of weights. For any of the primitive types such asint
,long
,double
,boolean
, ect., the reader will create aWeights
object of the corresponding type, such asWeightsInt
,WeightsLong
,WeightsDouble
,WeightsBool
, ect. ForString
,Date
,URI
,BigInteger
,BigDecimal
, the reader will create aWeights
object of typeWeightsObj
. For 'list' types, which are supported for any primitive,String
,BigInteger
andBigDecimal
, the reader will create aWeights
object of typeWeightsObj
and will populate it with arrays of the corresponding type, such asint[]
,long[]
,String[]
,BigInteger[]
, ect. Default values are supported for all types of weights, and will be available after reading viaWeights.defaultWeightAsObj()
or any of the specific types weights such asWeightsInt.defaultWeight()
. Note that the default value of 'list' types is an array, which is shared between all vertices/edges that do not explicitly specify a value for the weight, and should not be modified.The GEXF format support both self edges and parallel edges. The format documentation can be found here.
- Author:
- Barak Ugav
- See Also:
GexfGraphWriter
-
-
Constructor Summary
Constructors Constructor Description GexfGraphReader()
Create a new reader.GexfGraphReader(Class<V> vertexType, Class<E> edgeType)
Create a new reader with default parsers and builders for the given vertex and edge types.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description GraphBuilder<V,E>
readIntoBuilder(Reader reader)
Read a graph from an I/O reader into aGraphBuilder
.void
setEdgeBuilder(IdBuilder<E> edgeBuilder)
Set the builder for the edges identifiers.void
setEdgeBuilderDefault(Class<E> edgeType)
Set the builder for the edges identifiers, using a default builder for the given edge type.void
setEdgeParser(Function<String,E> edgeParser)
Set the parser for the edges identifiers.void
setEdgeParserDefault(Class<E> edgeType)
Set the parser for the edges identifiers, using a default parser for the given edge type.void
setVertexParser(Function<String,V> vertexParser)
Set the parser for the vertices identifiers.void
setVertexParserDefault(Class<V> vertexType)
Set the parser for the vertices identifiers, using a default parser for the given vertex type.-
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface com.jgalgo.io.GraphReader
readGraph, readGraph, readGraph
-
-
-
-
Constructor Detail
-
GexfGraphReader
public GexfGraphReader()
Create a new reader.The user should set the vertex/edge parsers and edge builder manually using
setVertexParser(Function)
,setEdgeParser(Function)
andsetEdgeBuilder(IdBuilder)
. Setting the vertex parser is mandatory, while setting the edge parser is only required if edges identifiers are specified. Similarly, setting the edge builder is only required if edges identifiers are not specified.
-
GexfGraphReader
public GexfGraphReader(Class<V> vertexType, Class<E> edgeType)
Create a new reader with default parsers and builders for the given vertex and edge types.During the reading process, the reader will use the parser to convert the vertex identifiers from string to the given type, and similarly for edges if edges identifiers are specified. If edges identifiers are not specified, the reader will use the builder to generate them. Default parsers exist for types
byte
,short
,int
,long
,float
,double
andString
. Default edge builder is instantiated usingIdBuilder.defaultBuilder(Class)
, see it documentation for supported types. If the given types are not supported by the default parsers and builder, the reader will throw an exception. In such case, the constructorGexfGraphReader()
should be used, and the user should set the vertex/edge parsers and edge builder manually usingsetVertexParser(Function)
,setEdgeParser(Function)
andsetEdgeBuilder(IdBuilder)
.- Parameters:
vertexType
- the type of the verticesedgeType
- the type of the edges- Throws:
IllegalArgumentException
- if the given types are not supported by the default vertex/edge parsers and edge builder. The supported types arebyte
,short
,int
,long
,float
,double
andString
.- See Also:
setVertexParserDefault(Class)
,setEdgeParserDefault(Class)
,setEdgeBuilderDefault(Class)
-
-
Method Detail
-
setVertexParser
public void setVertexParser(Function<String,V> vertexParser)
Set the parser for the vertices identifiers.The parser is used to convert the vertex identifiers from string to the given vertex type. The parser is mandatory, and must be set before reading a graph. For default parsers for certain types, see
setVertexParserDefault(Class)
.- Parameters:
vertexParser
- a parser for the vertices identifiers
-
setVertexParserDefault
public void setVertexParserDefault(Class<V> vertexType)
Set the parser for the vertices identifiers, using a default parser for the given vertex type.The parser is used to convert the vertex identifiers from string to the given vertex type. The parser is mandatory, and must be set before reading a graph. The default parser exists for types
byte
,short
,int
,long
,float
,double
andString
. If the given type is not supported by the default parser, the reader will throw an exception. In such case, the methodsetVertexParser(Function)
should be used for custom parsing.- Parameters:
vertexType
- the type of the vertices- Throws:
IllegalArgumentException
- if the given type is not supported by the default parser. The supported types arebyte
,short
,int
,long
,float
,double
andString
.
-
setEdgeParser
public void setEdgeParser(Function<String,E> edgeParser)
Set the parser for the edges identifiers.The parser is used to convert the edges identifiers from string to the given edge type. The parser is mandatory if edges identifiers are specified. In case edge identifiers are not specified, an edge builder must be set (see
setEdgeBuilder(IdBuilder)
). For default parsers for certain types, seesetEdgeParserDefault(Class)
.- Parameters:
edgeParser
- a parser for the edges identifiers
-
setEdgeParserDefault
public void setEdgeParserDefault(Class<E> edgeType)
Set the parser for the edges identifiers, using a default parser for the given edge type.The parser is used to convert the edges identifiers from string to the given edge type. The parser is mandatory if edges identifiers are specified. In case edge identifiers are not specified, an edge builder must be set (see
setEdgeBuilder(IdBuilder)
). The default parser exists for typesbyte
,short
,int
,long
,float
,double
andString
. If the given type is not supported by the default parser, the reader will throw an exception. In such case, the methodsetEdgeParser(Function)
should be used for custom parsing.- Parameters:
edgeType
- the type of the edges- Throws:
IllegalArgumentException
- if the given type is not supported by the default parser. The supported types arebyte
,short
,int
,long
,float
,double
andString
.
-
setEdgeBuilder
public void setEdgeBuilder(IdBuilder<E> edgeBuilder)
Set the builder for the edges identifiers.The builder is used to generate edges identifiers if edges identifiers are not specified. The builder is mandatory if edges identifiers are not specified. In case edge identifiers are specified, an edge parser must be set (see
setEdgeParser(Function)
). For default builders for certain types, seesetEdgeBuilderDefault(Class)
.The edge builder accepts a set of existing edges, and should return a new edge identifier that is not in the set.
- Parameters:
edgeBuilder
- a builder for the edges identifiers
-
setEdgeBuilderDefault
public void setEdgeBuilderDefault(Class<E> edgeType)
Set the builder for the edges identifiers, using a default builder for the given edge type.The builder is used to generate edges identifiers if edges identifiers are not specified. The builder is mandatory if edges identifiers are not specified. In case edge identifiers are specified, an edge parser must be set (see
setEdgeParser(Function)
). The default builder is instantiated usingIdBuilder.defaultBuilder(Class)
, see it documentation for supported types. If the given type is not supported by the default builder, the reader will throw an exception. In such case, the methodsetEdgeBuilder(IdBuilder)
should be used for custom builder.- Parameters:
edgeType
- the type of the edges- Throws:
IllegalArgumentException
- if the given type is not supported by the default builder. SeeIdBuilder.defaultBuilder(Class)
for supported types
-
readIntoBuilder
public GraphBuilder<V,E> readIntoBuilder(Reader reader)
Description copied from interface:GraphReader
Read a graph from an I/O reader into aGraphBuilder
.- Specified by:
readIntoBuilder
in interfaceGraphReader<V,E>
- Parameters:
reader
- an I/O reader that contain a graph description- Returns:
- a graph builder containing the vertices and edge read from the reader
-
-