public static class ImmutableNetwork.Builder<N,E> extends Object
ImmutableNetwork
instances, especially static final
networks. Example:
static final ImmutableNetwork<City, Train> TRAIN_NETWORK =
NetworkBuilder.undirected()
.allowsParallelEdges(true)
.<City, Train>immutable()
.addEdge(PARIS, BRUSSELS, Thalys.trainNumber("1111"))
.addEdge(PARIS, BRUSSELS, RegionalTrain.trainNumber("2222"))
.addEdge(LONDON, PARIS, Eurostar.trainNumber("3333"))
.addEdge(LONDON, BRUSSELS, Eurostar.trainNumber("4444"))
.addNode(REYKJAVIK)
.build();
Builder instances can be reused; it is safe to call build()
multiple times to build
multiple networks in series. Each new network contains all the elements of the ones created
before it.
Modifier and Type | Method and Description |
---|---|
ImmutableNetwork.Builder<N,E> |
addEdge(EndpointPair<N> endpoints,
E edge)
Adds
edge connecting endpoints . |
ImmutableNetwork.Builder<N,E> |
addEdge(N nodeU,
N nodeV,
E edge)
Adds
edge connecting nodeU to nodeV . |
ImmutableNetwork.Builder<N,E> |
addNode(N node)
Adds
node if it is not already present. |
ImmutableNetwork<N,E> |
build()
Returns a newly-created
ImmutableNetwork based on the contents of this Builder . |
@CanIgnoreReturnValue public ImmutableNetwork.Builder<N,E> 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 ImmutableNetwork.Builder<N,E> addEdge(N nodeU, N nodeV, E edge)
edge
connecting nodeU
to nodeV
.
If the network is directed, edge
will be directed in this network; otherwise, it
will be undirected.
edge
must be unique to this network, just as a Map
key must be. It
must also be non-null.
If nodeU
and nodeV
are not already present in this network, this method
will silently add
nodeU
and nodeV
to the network.
If edge
already connects nodeU
to nodeV
(in the specified order if
this network isDirected()
, else in any order), then this method will have no effect.
Builder
objectIllegalArgumentException
- if edge
already exists in the network and does not
connect nodeU
to nodeV
IllegalArgumentException
- if the introduction of the edge would violate allowsParallelEdges()
or allowsSelfLoops()
@CanIgnoreReturnValue public ImmutableNetwork.Builder<N,E> addEdge(EndpointPair<N> endpoints, E edge)
edge
connecting endpoints
. In an undirected network, edge
will
also connect nodeV
to nodeU
.
If this network is directed, edge
will be directed in this network; if it is
undirected, edge
will be undirected in this network.
If this network is directed, endpoints
must be ordered.
edge
must be unique to this network, just as a Map
key must be. It
must also be non-null.
If either or both endpoints are not already present in this network, this method will
silently add
each missing endpoint to the network.
If edge
already connects an endpoint pair equal to endpoints
, then this
method will have no effect.
Builder
objectIllegalArgumentException
- if edge
already exists in the network and connects
some other endpoint pair that is not equal to endpoints
IllegalArgumentException
- if the introduction of the edge would violate allowsParallelEdges()
or allowsSelfLoops()
IllegalArgumentException
- if the endpoints are unordered and the network is directedpublic ImmutableNetwork<N,E> build()
ImmutableNetwork
based on the contents of this Builder
.Copyright © 2010–2020. All rights reserved.