Top Description Inners Fields Constructors Methods
com.google.common.graph

public Class ImmutableGraph<N>

extends ForwardingGraph<N>
Class Inheritance
Annotations
@Beta
@Immutable
containerOf:N
@ElementTypesAreNonnullByDefault
Type Parameters
<N>
Node parameter type
Static Imports
com.google.common.base.Preconditions.checkNotNull

A Graph whose elements and structural relationships will never change. Instances of this class may be obtained with copyOf(Graph).

See the Guava User's Guide's discussion of the Immutable* types for more information on the properties and guarantees provided by this class.

Authors
James Sexton, Joshua O'Madadhain, Omar Darwish, Jens Nyman
Since
20.0

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static class
ImmutableGraph.Builder<N>

A builder for creating ImmutableGraph instances, especially static final graphs.

Field Summary

Modifier and TypeField and Description
private final BaseGraph<N>

Constructor Summary

AccessConstructor and Description
pack-priv
ImmutableGraph(BaseGraph<N> backingGraph)

Method Summary

Modifier and TypeMethod and Description
private static <N> GraphConnections<N, GraphConstants.Presence>
connectionsOf(Graph<N> graph, N node)

public static <N> ImmutableGraph<N>
copyOf(Graph<N> graph)

Returns an immutable copy of graph.

public static <N> ImmutableGraph<N>
copyOf(ImmutableGraph<N> graph)

Deprecated no need to use this
Simply returns its argument.
pack-priv BaseGraph<N>
private static <N> ImmutableMap<N, GraphConnections<N, GraphConstants.Presence>>
public ElementOrder<N>
Inherited from com.google.common.graph.ForwardingGraph:
adjacentNodesallowsSelfLoopsdegreeedgeCounthasEdgeConnectinghasEdgeConnectingincidentEdgesinDegreeisDirectednodeOrdernodesoutDegreepredecessorssuccessors

Field Detail

backingGraphback to summary
private final BaseGraph<N> backingGraph
Annotations
@SuppressWarnings:Immutable

Constructor Detail

ImmutableGraphback to summary
pack-priv ImmutableGraph(BaseGraph<N> backingGraph)

Method Detail

connectionsOfback to summary
private static <N> GraphConnections<N, GraphConstants.Presence> connectionsOf(Graph<N> graph, N node)
Annotations
@SuppressWarnings:unchecked
copyOfback to summary
public static <N> ImmutableGraph<N> copyOf(Graph<N> graph)

Returns an immutable copy of graph.

copyOfback to summary
public static <N> ImmutableGraph<N> copyOf(ImmutableGraph<N> graph)

Deprecated

no need to use this

Simply returns its argument.

Annotations
@Deprecated
delegateback to summary
pack-priv BaseGraph<N> delegate()

Implements abstract com.google.common.graph.ForwardingGraph.delegate.

Annotations
@Override
getNodeConnectionsback to summary
private static <N> ImmutableMap<N, GraphConnections<N, GraphConstants.Presence>> getNodeConnections(Graph<N> graph)
incidentEdgeOrderback to summary
public ElementOrder<N> incidentEdgeOrder()

Overrides com.google.common.graph.ForwardingGraph.incidentEdgeOrder.

Implements com.google.common.graph.Graph.incidentEdgeOrder, com.google.common.graph.BaseGraph.incidentEdgeOrder.

Doc from com.google.common.graph.Graph.incidentEdgeOrder.

Returns an ElementOrder that specifies the order of iteration for the elements of edges(), adjacentNodes(Object), predecessors(Object), successors(Object) and incidentEdges(Object).

Annotations
@Override
com.google.common.graph back to summary

public Class ImmutableGraph.Builder<N>

extends Object
Class Inheritance

A builder for creating 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.

Since
28.0

Field Summary

Modifier and TypeField and Description
private final MutableGraph<N>

Constructor Summary

AccessConstructor and Description
pack-priv
Builder(GraphBuilder<N> graphBuilder)

Method Summary

Modifier and TypeMethod and Description
public ImmutableGraph.Builder<N>

Returns:

this Builder object
addNode
(N node)

Adds node if it is not already present.

public ImmutableGraph<N>
build()

Returns a newly-created ImmutableGraph based on the contents of this Builder.

public ImmutableGraph.Builder<N>

Returns:

this Builder object
putEdge
(N nodeU, N nodeV)

Adds an edge connecting nodeU to nodeV if one is not already present.

public ImmutableGraph.Builder<N>

Returns:

this Builder object
putEdge
(EndpointPair<N> endpoints)

Adds an edge connecting endpoints (in the order, if any, specified by endpoints) if one is not already present.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

mutableGraphback to summary
private final MutableGraph<N> mutableGraph

Constructor Detail

Builderback to summary
pack-priv Builder(GraphBuilder<N> graphBuilder)

Method Detail

addNodeback to summary
public ImmutableGraph.Builder<N> addNode(N node)

Adds node if it is not already present.

Nodes must be unique, just as Map keys must be. They must also be non-null.

Returns:ImmutableGraph.Builder<N>

this Builder object

Annotations
@CanIgnoreReturnValue
buildback to summary
public ImmutableGraph<N> build()

Returns a newly-created ImmutableGraph based on the contents of this Builder.

putEdgeback to summary
public ImmutableGraph.Builder<N> putEdge(N nodeU, N nodeV)

Adds an edge connecting 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.

Returns:ImmutableGraph.Builder<N>

this Builder object

Annotations
@CanIgnoreReturnValue
Exceptions
IllegalArgumentException:
if the introduction of the edge would violate allowsSelfLoops()
putEdgeback to summary
public 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.

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.

Returns:ImmutableGraph.Builder<N>

this Builder object

Annotations
@CanIgnoreReturnValue
Exceptions
IllegalArgumentException:
  • if the introduction of the edge would violate allowsSelfLoops()
  • if the endpoints are unordered and the graph is directed