public static class ImmutableValueGraph.Builder<N,V> extends Object
ImmutableValueGraph
instances, especially static final
graphs. Example:
static final ImmutableValueGraph<City, Distance> CITY_ROAD_DISTANCE_GRAPH =
ValueGraphBuilder.undirected()
.<City, Distance>immutable()
.putEdgeValue(PARIS, BERLIN, kilometers(1060))
.putEdgeValue(PARIS, BRUSSELS, kilometers(317))
.putEdgeValue(BERLIN, BRUSSELS, kilometers(764))
.addNode(REYKJAVIK)
.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.
Modifier and Type | Method and Description |
---|---|
ImmutableValueGraph.Builder<N,V> |
addNode(N node)
Adds
node if it is not already present. |
ImmutableValueGraph<N,V> |
build()
Returns a newly-created
ImmutableValueGraph based on the contents of this Builder . |
ImmutableValueGraph.Builder<N,V> |
putEdgeValue(EndpointPair<N> endpoints,
V value)
Adds an edge connecting
endpoints if one is not already present, and sets a value for
that edge to value (overwriting the existing value, if any). |
ImmutableValueGraph.Builder<N,V> |
putEdgeValue(N nodeU,
N nodeV,
V value)
Adds an edge connecting
nodeU to nodeV if one is not already present, and
sets a value for that edge to value (overwriting the existing value, if any). |
@CanIgnoreReturnValue public ImmutableValueGraph.Builder<N,V> addNode(N node)
node
if it is not already present.
Nodes must be unique, just as Map
keys must be. They must also be non-null.
Builder
object@CanIgnoreReturnValue public ImmutableValueGraph.Builder<N,V> putEdgeValue(N nodeU, N nodeV, V value)
nodeU
to nodeV
if one is not already present, and
sets a value for that edge to value
(overwriting the existing value, if any).
If the graph is directed, the resultant edge will be directed; otherwise, it will be undirected.
Values do not have to be unique. However, values must be non-null.
If nodeU
and nodeV
are not already present in this graph, this method will
silently add
nodeU
and nodeV
to the graph.
Builder
objectIllegalArgumentException
- if the introduction of the edge would violate allowsSelfLoops()
@CanIgnoreReturnValue public ImmutableValueGraph.Builder<N,V> putEdgeValue(EndpointPair<N> endpoints, V value)
endpoints
if one is not already present, and sets a value for
that edge to value
(overwriting the existing value, if any).
If the graph is directed, the resultant edge will be directed; otherwise, it will be undirected.
If this graph is directed, endpoints
must be ordered.
Values do not have to be unique. However, values must be non-null.
If either or both endpoints are not already present in this graph, this method will
silently add
each missing endpoint to the graph.
Builder
objectIllegalArgumentException
- if the introduction of the edge would violate allowsSelfLoops()
IllegalArgumentException
- if the endpoints are unordered and the graph is directedpublic ImmutableValueGraph<N,V> build()
ImmutableValueGraph
based on the contents of this Builder
.Copyright © 2010–2020. All rights reserved.