Class ImmutableNetwork<N,E>
- java.lang.Object
-
- com.google.common.graph.AbstractNetwork<N,E>
-
- com.google.common.graph.ImmutableNetwork<N,E>
-
- Type Parameters:
N- Node parameter typeE- Edge parameter type
- All Implemented Interfaces:
Network<N,E>,PredecessorsFunction<N>,SuccessorsFunction<N>
@Immutable(containerOf={"N","E"}) public final class ImmutableNetwork<N,E> extends AbstractNetwork<N,E>ANetworkwhose elements and structural relationships will never change. Instances of this class may be obtained withcopyOf(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.- Since:
- 20.0
- Author:
- James Sexton, Joshua O'Madadhain, Omar Darwish, Jens Nyman
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classImmutableNetwork.Builder<N,E>A builder for creatingImmutableNetworkinstances, especiallystatic finalnetworks.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description java.util.Set<N>adjacentNodes(N node)booleanallowsParallelEdges()Returns true if this network allows parallel edges.booleanallowsSelfLoops()ImmutableGraph<N>asGraph()Returns a live view of this network as aGraph.static <N,E>
ImmutableNetwork<N,E>copyOf(ImmutableNetwork<N,E> network)Deprecated.no need to use thisstatic <N,E>
ImmutableNetwork<N,E>copyOf(Network<N,E> network)Returns an immutable copy ofnetwork.ElementOrder<E>edgeOrder()Returns the order of iteration for the elements ofNetwork.edges().java.util.Set<E>edges()Returns all edges in this network, in the order specified byNetwork.edgeOrder().java.util.Set<E>edgesConnecting(N nodeU, N nodeV)Returns a live view of the set of edges that each directly connectnodeUtonodeV.java.util.Set<E>incidentEdges(N node)Returns a live view of the edges whoseincident nodesin this network includenode.EndpointPair<N>incidentNodes(E edge)Returns the nodes which are the endpoints ofedgein this network.java.util.Set<E>inEdges(N node)Returns a live view of all edges in this network which can be traversed in the direction (if any) of the edge to end atnode.booleanisDirected()ElementOrder<N>nodeOrder()java.util.Set<N>nodes()java.util.Set<E>outEdges(N node)Returns a live view of all edges in this network which can be traversed in the direction (if any) of the edge starting fromnode.java.util.Set<N>predecessors(N node)Returns all nodes in this graph adjacent tonodewhich can be reached by traversingnode's incoming edges against the direction (if any) of the edge.java.util.Set<N>successors(N node)Returns all nodes in this graph adjacent tonodewhich can be reached by traversingnode's outgoing edges in the direction (if any) of the edge.-
Methods inherited from class com.google.common.graph.AbstractNetwork
adjacentEdges, degree, edgeConnecting, edgeConnecting, edgeConnectingOrNull, edgeConnectingOrNull, edgeInvalidatableSet, edgesConnecting, equals, hasEdgeConnecting, hasEdgeConnecting, hashCode, inDegree, isOrderingCompatible, nodeInvalidatableSet, nodePairInvalidatableSet, outDegree, toString, validateEndpoints
-
-
-
-
Method Detail
-
copyOf
public static <N,E> ImmutableNetwork<N,E> copyOf(Network<N,E> network)
Returns an immutable copy ofnetwork.
-
copyOf
@InlineMe(replacement="checkNotNull(network)", staticImports="com.google.common.base.Preconditions.checkNotNull") @Deprecated public static <N,E> ImmutableNetwork<N,E> copyOf(ImmutableNetwork<N,E> network)Deprecated.no need to use thisSimply returns its argument.
-
asGraph
public ImmutableGraph<N> asGraph()
Description copied from interface:NetworkReturns a live view of this network as aGraph. The resultingGraphwill have an edge connecting node A to node B if thisNetworkhas 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, theNetwork.degree(Object)of a node in theGraphview may be less than the degree of the same node in thisNetwork.
-
nodes
public java.util.Set<N> nodes()
-
edges
public java.util.Set<E> edges()
Description copied from interface:NetworkReturns all edges in this network, in the order specified byNetwork.edgeOrder().
-
isDirected
public boolean isDirected()
-
allowsParallelEdges
public boolean allowsParallelEdges()
Description copied from interface:NetworkReturns true if this network allows parallel edges. Attempting to add a parallel edge to a network that does not allow them will throw anIllegalArgumentException.
-
allowsSelfLoops
public boolean allowsSelfLoops()
-
nodeOrder
public ElementOrder<N> nodeOrder()
-
edgeOrder
public ElementOrder<E> edgeOrder()
Description copied from interface:NetworkReturns the order of iteration for the elements ofNetwork.edges().
-
incidentEdges
public java.util.Set<E> incidentEdges(N node)
Description copied from interface:NetworkReturns a live view of the edges whoseincident nodesin this network includenode.This is equal to the union of
Network.inEdges(Object)andNetwork.outEdges(Object).If
nodeis removed from the network after this method is called, theSetviewreturned by this method will be invalidated, and will throwIllegalStateExceptionif it is accessed in any way, with the following exceptions:view.equals(view)evaluates totrue(but any otherequals()expression involvingviewwill throw)hashCode()does not throw- if
nodeis re-added to the network after having been removed,view's behavior is undefined
-
incidentNodes
public EndpointPair<N> incidentNodes(E edge)
Description copied from interface:NetworkReturns the nodes which are the endpoints ofedgein this network.
-
adjacentNodes
public java.util.Set<N> adjacentNodes(N node)
-
edgesConnecting
public java.util.Set<E> edgesConnecting(N nodeU, N nodeV)Description copied from interface:NetworkReturns a live view of the set of edges that each directly connectnodeUtonodeV.In an undirected network, this is equal to
edgesConnecting(nodeV, nodeU).The resulting set of edges will be parallel (i.e. have equal
Network.incidentNodes(Object)). If this network does notallow parallel edges, the resulting set will contain at most one edge (equivalent toedgeConnecting(nodeU, nodeV).asSet()).If either
nodeUornodeVare removed from the network after this method is called, theSetviewreturned by this method will be invalidated, and will throwIllegalStateExceptionif it is accessed in any way, with the following exceptions:view.equals(view)evaluates totrue(but any otherequals()expression involvingviewwill throw)hashCode()does not throw- if
nodeUornodeVare re-added to the network after having been removed,view's behavior is undefined
- Specified by:
edgesConnectingin interfaceNetwork<N,E>- Overrides:
edgesConnectingin classAbstractNetwork<N,E>
-
inEdges
public java.util.Set<E> inEdges(N node)
Description copied from interface:NetworkReturns a live view of all edges in this network which can be traversed in the direction (if any) of the edge to end atnode.In a directed network, an incoming edge's
EndpointPair.target()equalsnode.In an undirected network, this is equivalent to
Network.incidentEdges(Object).If
nodeis removed from the network after this method is called, theSetviewreturned by this method will be invalidated, and will throwIllegalStateExceptionif it is accessed in any way, with the following exceptions:view.equals(view)evaluates totrue(but any otherequals()expression involvingviewwill throw)hashCode()does not throw- if
nodeis re-added to the network after having been removed,view's behavior is undefined
-
outEdges
public java.util.Set<E> outEdges(N node)
Description copied from interface:NetworkReturns a live view of all edges in this network which can be traversed in the direction (if any) of the edge starting fromnode.In a directed network, an outgoing edge's
EndpointPair.source()equalsnode.In an undirected network, this is equivalent to
Network.incidentEdges(Object).If
nodeis removed from the network after this method is called, theSetviewreturned by this method will be invalidated, and will throwIllegalStateExceptionif it is accessed in any way, with the following exceptions:view.equals(view)evaluates totrue(but any otherequals()expression involvingviewwill throw)hashCode()does not throw- if
nodeis re-added to the network after having been removed,view's behavior is undefined
-
predecessors
public java.util.Set<N> predecessors(N node)
Description copied from interface:PredecessorsFunctionReturns all nodes in this graph adjacent tonodewhich can be reached by traversingnode's incoming edges against the direction (if any) of the edge.Some algorithms that operate on a
PredecessorsFunctionmay produce undesired results if the returnedIterablecontains duplicate elements. Implementations of such algorithms should document their behavior in the presence of duplicates.The elements of the returned
Iterablemust each be:- Non-null
- Usable as
Mapkeys (see the Guava User Guide's section on graph elements for details)
-
successors
public java.util.Set<N> successors(N node)
Description copied from interface:SuccessorsFunctionReturns all nodes in this graph adjacent tonodewhich can be reached by traversingnode's outgoing edges in the direction (if any) of the edge.This is not the same as "all nodes reachable from
nodeby following outgoing edges". For that functionality, seeGraphs.reachableNodes(Graph, Object).Some algorithms that operate on a
SuccessorsFunctionmay produce undesired results if the returnedIterablecontains duplicate elements. Implementations of such algorithms should document their behavior in the presence of duplicates.The elements of the returned
Iterablemust each be:- Non-null
- Usable as
Mapkeys (see the Guava User Guide's section on graph elements for details)
-
-