V
- the graph vertex typeE
- the graph edge typepublic final class GraphTypeBuilder<V,E> extends Object
Graph
s that the library provides.
The following example creates a directed graph which allows multiple (parallel) edges and self-loops:
Similarly one could get a weighted multigraph by using:Graph<Integer, DefaultEdge> g = GraphTypeBuilder .<Integer, DefaultEdge> directed().allowingMultipleEdges(true).allowingSelfLoops(true) .edgeClass(DefaultEdge.class).buildGraph();
Graph<Integer, DefaultWeightedEdge> g = GraphTypeBuilder .<Integer, DefaultWeightedEdge> undirected().allowingMultipleEdges(true) .allowingSelfLoops(false).edgeClass(DefaultWeightedEdge.class).weighted(true).buildGraph();
The builder also provides the ability to construct a graph from another graph such as:
Graph<Integer, DefaultWeightedEdge> g1 = GraphTypeBuilder .<Integer, DefaultWeightedEdge> undirected().allowingMultipleEdges(true) .allowingSelfLoops(false).edgeClass(DefaultWeightedEdge.class).weighted(true).buildGraph(); Graph<Integer, DefaultWeightedEdge> g2 = GraphTypeBuilder.asGraph(g1).buildGraph();
GraphType
,
GraphBuilder
Modifier and Type | Method and Description |
---|---|
GraphTypeBuilder<V,E> |
allowingMultipleEdges(boolean allowingMultipleEdges)
Set whether the graph will allow multiple (parallel) edges between the same two vertices.
|
GraphTypeBuilder<V,E> |
allowingSelfLoops(boolean allowingSelfLoops)
Set whether the graph will allow self loops (edges with same source and target vertices).
|
Graph<V,E> |
buildGraph()
Build the actual graph.
|
GraphBuilder<V,E,Graph<V,E>> |
buildGraphBuilder()
Build the graph and acquire a
GraphBuilder in order to add vertices and edges. |
GraphType |
buildType()
Build the graph type.
|
static <V,E> GraphTypeBuilder<V,E> |
directed()
Create a graph type builder for a directed graph.
|
<E1 extends E> |
edgeClass(Class<E1> edgeClass)
Set the edge class.
|
<E1 extends E> |
edgeSupplier(Supplier<E1> edgeSupplier)
Set the edge supplier.
|
static <V,E> GraphTypeBuilder<V,E> |
forGraph(Graph<V,E> graph)
Create a graph type builder which will create the same graph type as the parameter graph.
|
static <V,E> GraphTypeBuilder<V,E> |
forGraphType(GraphType type)
Create a graph type builder which will create a graph with the same type as the one provided.
|
static <V,E> GraphTypeBuilder<V,E> |
mixed()
Create a graph type builder for a mixed graph.
|
static <V,E> GraphTypeBuilder<V,E> |
undirected()
Create a graph type builder for an undirected graph.
|
<V1 extends V> |
vertexClass(Class<V1> vertexClass)
Set the vertex class.
|
<V1 extends V> |
vertexSupplier(Supplier<V1> vertexSupplier)
Set the vertex supplier.
|
GraphTypeBuilder<V,E> |
weighted(boolean weighted)
Set whether the graph will be weighted or not.
|
public static <V,E> GraphTypeBuilder<V,E> directed()
V
- the graph vertex typeE
- the graph edge typepublic static <V,E> GraphTypeBuilder<V,E> undirected()
V
- the graph vertex typeE
- the graph edge typepublic static <V,E> GraphTypeBuilder<V,E> mixed()
V
- the graph vertex typeE
- the graph edge typepublic static <V,E> GraphTypeBuilder<V,E> forGraphType(GraphType type)
V
- the graph vertex typeE
- the graph edge typetype
- the graph typepublic static <V,E> GraphTypeBuilder<V,E> forGraph(Graph<V,E> graph)
V
- the graph vertex typeE
- the graph edge typegraph
- a graphpublic GraphTypeBuilder<V,E> weighted(boolean weighted)
weighted
- if true the graph will be weightedpublic GraphTypeBuilder<V,E> allowingSelfLoops(boolean allowingSelfLoops)
allowingSelfLoops
- if true the graph will allow self-loopspublic GraphTypeBuilder<V,E> allowingMultipleEdges(boolean allowingMultipleEdges)
allowingMultipleEdges
- if true the graph will allow multiple (parallel) edgespublic <V1 extends V> GraphTypeBuilder<V1,E> vertexSupplier(Supplier<V1> vertexSupplier)
V1
- the graph vertex typevertexSupplier
- the vertex supplier to usepublic <E1 extends E> GraphTypeBuilder<V,E1> edgeSupplier(Supplier<E1> edgeSupplier)
E1
- the graph edge typeedgeSupplier
- the edge supplier to usepublic <V1 extends V> GraphTypeBuilder<V1,E> vertexClass(Class<V1> vertexClass)
V1
- the graph vertex typevertexClass
- the vertex classpublic <E1 extends E> GraphTypeBuilder<V,E1> edgeClass(Class<E1> edgeClass)
E1
- the graph edge typeedgeClass
- the edge classpublic GraphType buildType()
public GraphBuilder<V,E,Graph<V,E>> buildGraphBuilder()
GraphBuilder
in order to add vertices and edges.public Graph<V,E> buildGraph()
UnsupportedOperationException
- in case a graph type is not supportedCopyright © 2018. All rights reserved.