Package org.jgrapht.graph.builder
Class GraphTypeBuilder<V,E>
- java.lang.Object
-
- org.jgrapht.graph.builder.GraphTypeBuilder<V,E>
-
- Type Parameters:
V
- the graph vertex typeE
- the graph edge type
public final class GraphTypeBuilder<V,E> extends Object
A builder class for the hierarchy ofGraph
s that the library provides.The following example creates a directed graph which allows multiple (parallel) edges and self-loops:
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();
- Author:
- Dimitrios Michail
- See Also:
GraphType
,GraphBuilder
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method 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 aGraphBuilder
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>
GraphTypeBuilder<V,E1>edgeClass(Class<E1> edgeClass)
Set the edge class.<E1 extends E>
GraphTypeBuilder<V,E1>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>
GraphTypeBuilder<V1,E>vertexClass(Class<V1> vertexClass)
Set the vertex class.<V1 extends V>
GraphTypeBuilder<V1,E>vertexSupplier(Supplier<V1> vertexSupplier)
Set the vertex supplier.GraphTypeBuilder<V,E>
weighted(boolean weighted)
Set whether the graph will be weighted or not.
-
-
-
Method Detail
-
directed
public static <V,E> GraphTypeBuilder<V,E> directed()
Create a graph type builder for a directed graph.- Type Parameters:
V
- the graph vertex typeE
- the graph edge type- Returns:
- the graph type builder
-
undirected
public static <V,E> GraphTypeBuilder<V,E> undirected()
Create a graph type builder for an undirected graph.- Type Parameters:
V
- the graph vertex typeE
- the graph edge type- Returns:
- the graph type builder
-
mixed
public static <V,E> GraphTypeBuilder<V,E> mixed()
Create a graph type builder for a mixed graph.- Type Parameters:
V
- the graph vertex typeE
- the graph edge type- Returns:
- the graph type builder
-
forGraphType
public 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.- Type Parameters:
V
- the graph vertex typeE
- the graph edge type- Parameters:
type
- the graph type- Returns:
- the graph type builder
-
forGraph
public 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. The new graph will use the same vertex and edge suppliers as the input graph.- Type Parameters:
V
- the graph vertex typeE
- the graph edge type- Parameters:
graph
- a graph- Returns:
- a type builder
-
weighted
public GraphTypeBuilder<V,E> weighted(boolean weighted)
Set whether the graph will be weighted or not.- Parameters:
weighted
- if true the graph will be weighted- Returns:
- the graph type builder
-
allowingSelfLoops
public GraphTypeBuilder<V,E> allowingSelfLoops(boolean allowingSelfLoops)
Set whether the graph will allow self loops (edges with same source and target vertices).- Parameters:
allowingSelfLoops
- if true the graph will allow self-loops- Returns:
- the graph type builder
-
allowingMultipleEdges
public GraphTypeBuilder<V,E> allowingMultipleEdges(boolean allowingMultipleEdges)
Set whether the graph will allow multiple (parallel) edges between the same two vertices.- Parameters:
allowingMultipleEdges
- if true the graph will allow multiple (parallel) edges- Returns:
- the graph type builder
-
vertexSupplier
public <V1 extends V> GraphTypeBuilder<V1,E> vertexSupplier(Supplier<V1> vertexSupplier)
Set the vertex supplier.- Type Parameters:
V1
- the graph vertex type- Parameters:
vertexSupplier
- the vertex supplier to use- Returns:
- the graph type builder
-
edgeSupplier
public <E1 extends E> GraphTypeBuilder<V,E1> edgeSupplier(Supplier<E1> edgeSupplier)
Set the edge supplier.- Type Parameters:
E1
- the graph edge type- Parameters:
edgeSupplier
- the edge supplier to use- Returns:
- the graph type builder
-
vertexClass
public <V1 extends V> GraphTypeBuilder<V1,E> vertexClass(Class<V1> vertexClass)
Set the vertex class.- Type Parameters:
V1
- the graph vertex type- Parameters:
vertexClass
- the vertex class- Returns:
- the graph type builder
-
edgeClass
public <E1 extends E> GraphTypeBuilder<V,E1> edgeClass(Class<E1> edgeClass)
Set the edge class.- Type Parameters:
E1
- the graph edge type- Parameters:
edgeClass
- the edge class- Returns:
- the graph type builder
-
buildType
public GraphType buildType()
Build the graph type.- Returns:
- a graph type
-
buildGraphBuilder
public GraphBuilder<V,E,Graph<V,E>> buildGraphBuilder()
Build the graph and acquire aGraphBuilder
in order to add vertices and edges.- Returns:
- a graph builder
-
buildGraph
public Graph<V,E> buildGraph()
Build the actual graph.- Returns:
- the graph
- Throws:
UnsupportedOperationException
- in case a graph type is not supported
-
-