Class ImmutableGraph.Builder<N>
- java.lang.Object
- 
- com.google.common.graph.ImmutableGraph.Builder<N>
 
- 
- Enclosing class:
- ImmutableGraph<N>
 
 public static class ImmutableGraph.Builder<N> extends Object A builder for creatingImmutableGraphinstances, especiallystatic finalgraphs. 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
 
- 
- 
Method SummaryAll Methods Instance Methods Concrete Methods Modifier and Type Method Description ImmutableGraph.Builder<N>addNode(N node)Addsnodeif it is not already present.ImmutableGraph<N>build()Returns a newly-createdImmutableGraphbased on the contents of thisBuilder.ImmutableGraph.Builder<N>putEdge(EndpointPair<N> endpoints)Adds an edge connectingendpoints(in the order, if any, specified byendpoints) if one is not already present.ImmutableGraph.Builder<N>putEdge(N nodeU, N nodeV)Adds an edge connectingnodeUtonodeVif one is not already present.
 
- 
- 
- 
Method Detail- 
addNode@CanIgnoreReturnValue public ImmutableGraph.Builder<N> 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
 
 - 
putEdge@CanIgnoreReturnValue public ImmutableGraph.Builder<N> putEdge(N nodeU, N nodeV) Adds an edge connectingnodeUtonodeVif one is not already present.If the graph is directed, the resultant edge will be directed; otherwise, it will be undirected. If nodeUandnodeVare not already present in this graph, this method will silentlyaddnodeUandnodeVto the graph.- Returns:
- this Builderobject
- Throws:
- IllegalArgumentException- if the introduction of the edge would violate- Graph.allowsSelfLoops()
 
 - 
putEdge@CanIgnoreReturnValue public ImmutableGraph.Builder<N> putEdge(EndpointPair<N> endpoints) Adds an edge connectingendpoints(in the order, if any, specified byendpoints) if one is not already present.If this graph is directed, endpointsmust be ordered and the added edge will be directed; if it is undirected, the added edge will be undirected.If this graph is directed, endpointsmust be ordered.If either or both endpoints are not already present in this graph, this method will silently addeach missing endpoint to the graph.- Returns:
- this Builderobject
- Throws:
- IllegalArgumentException- if the introduction of the edge would violate- Graph.allowsSelfLoops()
- IllegalArgumentException- if the endpoints are unordered and the graph is directed
 
 - 
buildpublic ImmutableGraph<N> build() Returns a newly-createdImmutableGraphbased on the contents of thisBuilder.
 
- 
 
-