public static class ImmutableGraph.Builder<N>
extends java.lang.Object
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.
| Modifier and Type | Field and Description |
|---|---|
private MutableGraph<N> |
mutableGraph |
| Constructor and Description |
|---|
Builder(GraphBuilder<N> graphBuilder) |
| Modifier and Type | Method and Description |
|---|---|
ImmutableGraph.Builder<N> |
addNode(N node)
Adds
node if it is not already present. |
ImmutableGraph<N> |
build()
Returns a newly-created
ImmutableGraph based on the contents of this Builder. |
ImmutableGraph.Builder<N> |
putEdge(EndpointPair<N> endpoints)
Adds an edge connecting
endpoints (in the order, if any, specified by endpoints) if one is not already present. |
ImmutableGraph.Builder<N> |
putEdge(N nodeU,
N nodeV)
Adds an edge connecting
nodeU to nodeV if one is not already present. |
private final MutableGraph<N> mutableGraph
Builder(GraphBuilder<N> graphBuilder)
public ImmutableGraph.Builder<N> 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 objectpublic ImmutableGraph.Builder<N> putEdge(N nodeU, N nodeV)
nodeU to nodeV if one is not already present.
If the graph is directed, the resultant edge will be directed; otherwise, it will be undirected.
If nodeU and nodeV are not already present in this graph, this method will
silently add nodeU and nodeV to the graph.
Builder objectjava.lang.IllegalArgumentException - if the introduction of the edge would violate ForwardingGraph.allowsSelfLoops()public ImmutableGraph.Builder<N> putEdge(EndpointPair<N> endpoints)
endpoints (in the order, if any, specified by endpoints) 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.
Builder objectjava.lang.IllegalArgumentException - if the introduction of the edge would violate ForwardingGraph.allowsSelfLoops()java.lang.IllegalArgumentException - if the endpoints are unordered and the graph is directedpublic ImmutableGraph<N> build()
ImmutableGraph based on the contents of this Builder.