java.lang.Object
org.jgrapht.graph.builder.GraphTypeBuilder<V,E>
- Type Parameters:
V
- the graph vertex typeE
- the graph edge type
A builder class for the hierarchy of
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();
- Author:
- Dimitrios Michail
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionallowingMultipleEdges
(boolean allowingMultipleEdges) Set whether the graph will allow multiple (parallel) edges between the same two vertices.allowingSelfLoops
(boolean allowingSelfLoops) Set whether the graph will allow self loops (edges with same source and target vertices).Build the actual graph.Build the graph and acquire aGraphBuilder
in order to add vertices and edges.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> Set the edge class.<E1 extends E>
GraphTypeBuilder<V,E1> edgeSupplier
(Supplier<E1> edgeSupplier) Set the edge supplier.static <V,
E> GraphTypeBuilder<V, E> 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> 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.weighted
(boolean weighted) Set whether the graph will be weighted or not.
-
Method Details
-
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
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
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
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
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
Set whether the graph will be weighted or not.- Parameters:
weighted
- if true the graph will be weighted- Returns:
- the graph type builder
-
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
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
Set the vertex supplier.- Type Parameters:
V1
- the graph vertex type- Parameters:
vertexSupplier
- the vertex supplier to use- Returns:
- the graph type builder
-
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
Set the vertex class.- Type Parameters:
V1
- the graph vertex type- Parameters:
vertexClass
- the vertex class- Returns:
- the graph type builder
-
edgeClass
Set the edge class.- Type Parameters:
E1
- the graph edge type- Parameters:
edgeClass
- the edge class- Returns:
- the graph type builder
-
buildType
Build the graph type.- Returns:
- a graph type
-
buildGraphBuilder
Build the graph and acquire aGraphBuilder
in order to add vertices and edges.- Returns:
- a graph builder
-
buildGraph
Build the actual graph.- Returns:
- the graph
- Throws:
UnsupportedOperationException
- in case a graph type is not supported
-