Class ImmutableGraph.Builder<N>
- Enclosing class:
ImmutableGraph<N>
ImmutableGraph
instances, especially static final
graphs. Example:
static final ImmutableGraph<Country> COUNTRY_ADJACENCY_GRAPH =
GraphBuilder.undirected()
.<Country>immutable()
.putEdge(FRANCE, GERMANY)
.putEdge(FRANCE, BELGIUM)
.putEdge(GERMANY, BELGIUM)
.addNode(ICELAND)
.build();
Builder instances can be reused; it is safe to call build()
multiple times to build
multiple graphs in series. Each new graph contains all the elements of the ones created before
it.
- Since:
- 28.0
- Author:
- James Sexton, Joshua O'Madadhain, Omar Darwish, Jens Nyman
-
Method Summary
Modifier and TypeMethodDescriptionAddsnode
if it is not already present.build()
Returns a newly-createdImmutableGraph
based on the contents of thisBuilder
.putEdge
(EndpointPair<N> endpoints) Adds an edge connectingendpoints
(in the order, if any, specified byendpoints
) if one is not already present.Adds an edge connectingnodeU
tonodeV
if one is not already present.
-
Method Details
-
addNode
Addsnode
if it is not already present.Nodes must be unique, just as
Map
keys must be. They must also be non-null.- Returns:
- this
Builder
object
-
putEdge
Adds an edge connectingnodeU
tonodeV
if one is not already present.If the graph is directed, the resultant edge will be directed; otherwise, it will be undirected.
If
nodeU
andnodeV
are not already present in this graph, this method will silentlyadd
nodeU
andnodeV
to the graph.- Returns:
- this
Builder
object - Throws:
IllegalArgumentException
- if the introduction of the edge would violateGraph.allowsSelfLoops()
-
putEdge
Adds an edge connectingendpoints
(in the order, if any, specified byendpoints
) if one is not already present.If this graph is directed,
endpoints
must be ordered and the added edge will be directed; if it is undirected, the added edge will be undirected.If this graph is directed,
endpoints
must be ordered.If either or both endpoints are not already present in this graph, this method will silently
add
each missing endpoint to the graph.- Returns:
- this
Builder
object - Throws:
IllegalArgumentException
- if the introduction of the edge would violateGraph.allowsSelfLoops()
IllegalArgumentException
- if the endpoints are unordered and the graph is directed
-
build
Returns a newly-createdImmutableGraph
based on the contents of thisBuilder
.
-