Class ImmutableNetwork.Builder<N,E>
- java.lang.Object
-
- com.google.common.graph.ImmutableNetwork.Builder<N,E>
-
- Enclosing class:
- ImmutableNetwork<N,E>
public static class ImmutableNetwork.Builder<N,E> extends java.lang.Object
A builder for creatingImmutableNetworkinstances, especiallystatic finalnetworks. 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.- Since:
- 28.0
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description ImmutableNetwork.Builder<N,E>addEdge(EndpointPair<N> endpoints, E edge)Addsedgeconnectingendpoints.ImmutableNetwork.Builder<N,E>addEdge(N nodeU, N nodeV, E edge)AddsedgeconnectingnodeUtonodeV.ImmutableNetwork.Builder<N,E>addNode(N node)Addsnodeif it is not already present.ImmutableNetwork<N,E>build()Returns a newly-createdImmutableNetworkbased on the contents of thisBuilder.
-
-
-
Method Detail
-
addNode
@CanIgnoreReturnValue public ImmutableNetwork.Builder<N,E> addNode(N node)
Addsnodeif it is not already present.Nodes must be unique, just as
Mapkeys must be. They must also be non-null.- Returns:
- this
Builderobject
-
addEdge
@CanIgnoreReturnValue public ImmutableNetwork.Builder<N,E> addEdge(N nodeU, N nodeV, E edge)
AddsedgeconnectingnodeUtonodeV.If the network is directed,
edgewill be directed in this network; otherwise, it will be undirected.edgemust be unique to this network, just as aMapkey must be. It must also be non-null.If
nodeUandnodeVare not already present in this network, this method will silentlyaddnodeUandnodeVto the network.If
edgealready connectsnodeUtonodeV(in the specified order if this networkNetwork.isDirected(), else in any order), then this method will have no effect.- Returns:
- this
Builderobject - Throws:
java.lang.IllegalArgumentException- ifedgealready exists in the network and does not connectnodeUtonodeVjava.lang.IllegalArgumentException- if the introduction of the edge would violateNetwork.allowsParallelEdges()orNetwork.allowsSelfLoops()
-
addEdge
@CanIgnoreReturnValue public ImmutableNetwork.Builder<N,E> addEdge(EndpointPair<N> endpoints, E edge)
Addsedgeconnectingendpoints. In an undirected network,edgewill also connectnodeVtonodeU.If this network is directed,
edgewill be directed in this network; if it is undirected,edgewill be undirected in this network.If this network is directed,
endpointsmust be ordered.edgemust be unique to this network, just as aMapkey must be. It must also be non-null.If either or both endpoints are not already present in this network, this method will silently
addeach missing endpoint to the network.If
edgealready connects an endpoint pair equal toendpoints, then this method will have no effect.- Returns:
- this
Builderobject - Throws:
java.lang.IllegalArgumentException- ifedgealready exists in the network and connects some other endpoint pair that is not equal toendpointsjava.lang.IllegalArgumentException- if the introduction of the edge would violateNetwork.allowsParallelEdges()orNetwork.allowsSelfLoops()java.lang.IllegalArgumentException- if the endpoints are unordered and the network is directed
-
build
public ImmutableNetwork<N,E> build()
Returns a newly-createdImmutableNetworkbased on the contents of thisBuilder.
-
-