Class GraphMlGraphReader<V,E>
- java.lang.Object
-
- com.jgalgo.io.GraphMlGraphReader<V,E>
-
- Type Parameters:
V
- the vertices typeE
- the edges type
- All Implemented Interfaces:
GraphReader<V,E>
public final class GraphMlGraphReader<V,E> extends Object
Read a graph in 'GraphML' format.GraphML 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 typeint
,long
,float
,double
,boolean
andString
, and a default value for each weight type.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)
).The GraphML format support both self edges and parallel edges.
- Author:
- Barak Ugav
- See Also:
GraphMlGraphWriter
-
-
Constructor Summary
Constructors Constructor Description GraphMlGraphReader()
Create a new reader.GraphMlGraphReader(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
-
GraphMlGraphReader
public GraphMlGraphReader()
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.
-
GraphMlGraphReader
public GraphMlGraphReader(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 exists 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 constructorGraphMlGraphReader()
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
-
-