Interface GraphFactory<V,E>
-
- Type Parameters:
V
- the vertices typeE
- the edges type
- All Known Subinterfaces:
IndexGraphFactory
,IntGraphFactory
public interface GraphFactory<V,E>
A factory forGraph
objects.The factory can be used to create new empty graphs, with different options and capabilities. Few methods are available to optimize the graph implementation choice. The factory can also be used to create a copy of an existing graphs, with the same vertices and edges, with/without copying the vertices/edges weights.
Both the graph factory and
GraphBuilder
are used to create new graphs. The difference is that vertices and edges can be added to the builder, which is then used to construct non empty graphs, while the factory is only used to choose a graph implementation and create an empty graph.- Author:
- Barak Ugav
- See Also:
newDirected()
,newUndirected()
,Graph
,GraphBuilder
-
-
Nested Class Summary
Nested Classes Modifier and Type Interface Description static class
GraphFactory.Hint
Hints for a graph factory.
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description GraphFactory<V,E>
addHint(GraphFactory.Hint hint)
Add a hint to this factory.GraphFactory<V,E>
allowParallelEdges(boolean parallelEdges)
Determine if graphs built by this factory should be support parallel edges.GraphFactory<V,E>
allowSelfEdges(boolean selfEdges)
Determine if graphs built by this factory should be support self edges.GraphFactory<V,E>
expectedEdgesNum(int expectedEdgesNum)
Set the expected number of edges that will exist in the graph.GraphFactory<V,E>
expectedVerticesNum(int expectedVerticesNum)
Set the expected number of vertices that will exist in the graph.GraphBuilder<V,E>
newBuilder()
Create a new graph builder with the factory parameters.default Graph<V,E>
newCopyOf(Graph<V,E> g)
Create a copy of a given graph, with the same vertices and edges, without copying weights.Graph<V,E>
newCopyOf(Graph<V,E> g, boolean copyWeights)
Create a copy of a given graph, with the same vertices and edges, with/without copying weights.static <V,E>
GraphFactory<V,E>newDirected()
Create a directed graph factory.static <V,E>
GraphFactory<V,E>newFrom(Graph<V,E> g)
Create a new graph factory based on a given implementation.Graph<V,E>
newGraph()
Create a new empty graph.static <V,E>
GraphFactory<V,E>newUndirected()
Create an undirected graph factory.GraphFactory<V,E>
removeHint(GraphFactory.Hint hint)
Remove a hint from this factory.GraphFactory<V,E>
setDirected(boolean directed)
Determine if graphs built by this factory should be directed or not.default GraphFactory<V,E>
setOption(String key, Object value)
[TL;DR Don't call me!] Set an option.
-
-
-
Method Detail
-
newGraph
Graph<V,E> newGraph()
Create a new empty graph.- Returns:
- a new graph with the factory options
-
newCopyOf
default Graph<V,E> newCopyOf(Graph<V,E> g)
Create a copy of a given graph, with the same vertices and edges, without copying weights.An identical copy of the given graph will be created, with the same vertices and edges, without copying the vertices/edges weights. The returned Graph will always be modifiable, with no side affects on the original graph.
Differing from
Graph.copy()
, the capabilities of the new graph are determined by the factory configuration, rather than copied from the given graph. Note for example that if the factory chooses to use an implementation that does not (have to) support self edges (ifallowSelfEdges(boolean)
was not called withtrue
), attempting to create a copy of a graph that does contains self edges will result in an exception.- Parameters:
g
- the original graph to copy- Returns:
- an identical copy of the given graph, with the same vertices and edges, without the original graph weights
-
newCopyOf
Graph<V,E> newCopyOf(Graph<V,E> g, boolean copyWeights)
Create a copy of a given graph, with the same vertices and edges, with/without copying weights.An identical copy of the given graph will be created, with the same vertices and edges, with/without copying the vertices/edges weights. The returned Graph will always be modifiable, with no side affects on the original graph.
Differing from
Graph.copy(boolean)
, the capabilities of the new graph are determined by the factory configuration, rather than copied from the given graph. Note for example that if the factory chooses to use an implementation that does not (have to) support self edges (ifallowSelfEdges(boolean)
was not called withtrue
), attempting to create a copy of a graph that does contains self edges will result in an exception.- Parameters:
g
- the original graph to copycopyWeights
- iftrue
, the weights of the vertices and edges will be copied to the new graph- Returns:
- an identical copy of the given graph, with the same vertices and edges, with/without the original graph weights
-
newBuilder
GraphBuilder<V,E> newBuilder()
Create a new graph builder with the factory parameters.The created builder can be used to add vertices and edges, and then build a (mutable or immutable) non empty graph, differing from the factory which only builds empty graphs. The capabilities such as un/directed, support of self edges, support of parallel edges, and hints such as expected number of vertices and edges, other hints, etc. are copied from the factory to the builder.
- Returns:
- a new graph builder with the factory parameters
-
setDirected
GraphFactory<V,E> setDirected(boolean directed)
Determine if graphs built by this factory should be directed or not.- Parameters:
directed
- iftrue
, graphs built by this factory will be directed- Returns:
- this factory
-
allowSelfEdges
GraphFactory<V,E> allowSelfEdges(boolean selfEdges)
Determine if graphs built by this factory should be support self edges.- Parameters:
selfEdges
- iftrue
, graphs built by this factory will support self edges- Returns:
- this factory
-
allowParallelEdges
GraphFactory<V,E> allowParallelEdges(boolean parallelEdges)
Determine if graphs built by this factory should be support parallel edges.- Parameters:
parallelEdges
- iftrue
, graphs built by this factory will support parallel edges- Returns:
- this factory
-
expectedVerticesNum
GraphFactory<V,E> expectedVerticesNum(int expectedVerticesNum)
Set the expected number of vertices that will exist in the graph.- Parameters:
expectedVerticesNum
- the expected number of vertices in the graph- Returns:
- this factory
-
expectedEdgesNum
GraphFactory<V,E> expectedEdgesNum(int expectedEdgesNum)
Set the expected number of edges that will exist in the graph.- Parameters:
expectedEdgesNum
- the expected number of edges in the graph- Returns:
- this factory
-
addHint
GraphFactory<V,E> addHint(GraphFactory.Hint hint)
Add a hint to this factory.Hints do not change the behavior of the graphs built by this factory, by may affect performance.
- Parameters:
hint
- the hint to add- Returns:
- this factory
-
removeHint
GraphFactory<V,E> removeHint(GraphFactory.Hint hint)
Remove a hint from this factory.Hints do not change the behavior of the graphs built by this factory, by may affect performance.
- Parameters:
hint
- the hint to remove- Returns:
- this factory
-
newUndirected
static <V,E> GraphFactory<V,E> newUndirected()
Create an undirected graph factory.- Type Parameters:
V
- the vertices typeE
- the edges type- Returns:
- a new factory that can build undirected graphs
-
newDirected
static <V,E> GraphFactory<V,E> newDirected()
Create a directed graph factory.- Type Parameters:
V
- the vertices typeE
- the edges type- Returns:
- a new factory that can build directed graphs
-
newFrom
static <V,E> GraphFactory<V,E> newFrom(Graph<V,E> g)
Create a new graph factory based on a given implementation.The new factory will build graphs with the same capabilities (inclusive) as the given graph, possibly choosing to use a similar implementation. The factory will NOT copy the graph itself (the vertices, edges and weights), for such use case see
Graph.copy()
ornewCopyOf(Graph)
.- Type Parameters:
V
- the vertices typeE
- the edges type- Parameters:
g
- a graph from which the factory should copy its capabilities (inclusive)- Returns:
- a new graph factory that will create graphs with the same capabilities (inclusive) of the given graph
-
setOption
default GraphFactory<V,E> setOption(String key, Object value)
[TL;DR Don't call me!] Set an option.The builder might support different options to customize its implementation. These options never change the behavior of the algorithm, only its internal implementation. The possible options are not exposed as 'public' because they are not part of the API and may change in the future.
These options are mainly for debug and benchmark purposes.
- Parameters:
key
- the option keyvalue
- the option value- Returns:
- this builder
-
-