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

public final Class ImmutableNetwork<N, E>

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

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

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
ImmutableNetwork.Builder<N, E>

A builder for creating ImmutableNetwork instances, especially static final networks.

Field Summary

Inherited from com.google.common.graph.StandardNetwork:
edgeToReferenceNodenodeConnections

Constructor Summary

AccessConstructor and Description
private
ImmutableNetwork(Network<N, E> network)

Method Summary

Modifier and TypeMethod and Description
private static <N, E> Function<E, N>
adjacentNodeFn(Network<N, E> network, N node)

public ImmutableGraph<N>
asGraph()

Overrides com.google.common.graph.AbstractNetwork.asGraph.

Implements com.google.common.graph.Network.asGraph.

Returns a live view of this network as a Graph.
private static <N, E> NetworkConnections<N, E>
connectionsOf(Network<N, E> network, N node)

public static <N, E> ImmutableNetwork<N, E>
copyOf(Network<N, E> network)

Returns an immutable copy of network.

public static <N, E> ImmutableNetwork<N, E>
copyOf(ImmutableNetwork<N, E> network)

Deprecated no need to use this
Simply returns its argument.
private static <N, E> Map<E, N>
private static <N, E> Map<N, NetworkConnections<N, E>>
getNodeConnections(Network<N, E> network)

private static <N, E> Function<E, N>
sourceNodeFn(Network<N, E> network)

private static <N, E> Function<E, N>
targetNodeFn(Network<N, E> network)

Inherited from com.google.common.graph.StandardNetwork:
adjacentNodesallowsParallelEdgesallowsSelfLoopscheckedConnectionscheckedReferenceNodecontainsEdgecontainsNodeedgeOrderedgesedgesConnectingincidentEdgesincidentNodesinEdgesisDirectednodeOrdernodesoutEdgespredecessorssuccessors

Constructor Detail

ImmutableNetworkback to summary
private ImmutableNetwork(Network<N, E> network)

Method Detail

adjacentNodeFnback to summary
private static <N, E> Function<E, N> adjacentNodeFn(Network<N, E> network, N node)
asGraphback to summary
public ImmutableGraph<N> asGraph()

Overrides com.google.common.graph.AbstractNetwork.asGraph.

Implements com.google.common.graph.Network.asGraph.

Doc from com.google.common.graph.Network.asGraph.

Returns a live view of this network as a Graph. The resulting Graph will have an edge connecting node A to node B if this Network has an edge connecting A to B.

If this network allows parallel edges, parallel edges will be treated as if collapsed into a single edge. For example, the degree(Object) of a node in the Graph view may be less than the degree of the same node in this Network.

Annotations
@Override
connectionsOfback to summary
private static <N, E> NetworkConnections<N, E> connectionsOf(Network<N, E> network, N node)
copyOfback to summary
public static <N, E> ImmutableNetwork<N, E> copyOf(Network<N, E> network)

Returns an immutable copy of network.

copyOfback to summary
public static <N, E> ImmutableNetwork<N, E> copyOf(ImmutableNetwork<N, E> network)

Deprecated

no need to use this

Simply returns its argument.

Annotations
@Deprecated
getEdgeToReferenceNodeback to summary
private static <N, E> Map<E, N> getEdgeToReferenceNode(Network<N, E> network)
getNodeConnectionsback to summary
private static <N, E> Map<N, NetworkConnections<N, E>> getNodeConnections(Network<N, E> network)
sourceNodeFnback to summary
private static <N, E> Function<E, N> sourceNodeFn(Network<N, E> network)
targetNodeFnback to summary
private static <N, E> Function<E, N> targetNodeFn(Network<N, E> network)
com.google.common.graph back to summary

public Class ImmutableNetwork.Builder<N, E>

extends Object
Class Inheritance

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

Since
28.0

Field Summary

Modifier and TypeField and Description
private final MutableNetwork<N, E>

Constructor Summary

AccessConstructor and Description
pack-priv
Builder(NetworkBuilder<N, E> networkBuilder)

Method Summary

Modifier and TypeMethod and Description
public ImmutableNetwork.Builder<N, E>

Returns:

this Builder object
addEdge
(N nodeU, N nodeV, E edge)

Adds edge connecting nodeU to nodeV.

public ImmutableNetwork.Builder<N, E>

Returns:

this Builder object
addEdge
(EndpointPair<N> endpoints, E edge)

Adds edge connecting endpoints.

public ImmutableNetwork.Builder<N, E>

Returns:

this Builder object
addNode
(N node)

Adds node if it is not already present.

public ImmutableNetwork<N, E>
build()

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

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

mutableNetworkback to summary
private final MutableNetwork<N, E> mutableNetwork

Constructor Detail

Builderback to summary
pack-priv Builder(NetworkBuilder<N, E> networkBuilder)

Method Detail

addEdgeback to summary
public ImmutableNetwork.Builder<N, E> addEdge(N nodeU, N nodeV, E edge)

Adds 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.

Returns:ImmutableNetwork.Builder<N, E>

this Builder object

Annotations
@CanIgnoreReturnValue
Exceptions
IllegalArgumentException:
addEdgeback to summary
public ImmutableNetwork.Builder<N, E> addEdge(EndpointPair<N> endpoints, E edge)

Adds 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.

Returns:ImmutableNetwork.Builder<N, E>

this Builder object

Annotations
@CanIgnoreReturnValue
Exceptions
IllegalArgumentException:
  • if edge already exists in the network and connects some other endpoint pair that is not equal to endpoints
  • if the introduction of the edge would violate allowsParallelEdges() or allowsSelfLoops()
  • if the endpoints are unordered and the network is directed
addNodeback to summary
public ImmutableNetwork.Builder<N, E> 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:ImmutableNetwork.Builder<N, E>

this Builder object

Annotations
@CanIgnoreReturnValue
buildback to summary
public ImmutableNetwork<N, E> build()

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