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>
@Beta @Immutable(containerOf={"N","E"}) public final class ImmutableNetwork<N,E> extends AbstractNetwork<N,E>
ANetwork
whose 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 class
ImmutableNetwork.Builder<N,E>
A builder for creatingImmutableNetwork
instances, especiallystatic final
networks.
-
Field Summary
Fields Modifier and Type Field Description protected com.google.common.graph.MapIteratorCache<E,N>
edgeToReferenceNode
protected com.google.common.graph.MapIteratorCache<N,com.google.common.graph.NetworkConnections<N,E>>
nodeConnections
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description Set<N>
adjacentNodes(N node)
Returns the nodes which have an incident edge in common withnode
in this network.boolean
allowsParallelEdges()
Returns true if this network allows parallel edges.boolean
allowsSelfLoops()
Returns true if this network allows self-loops (edges that connect a node to itself).ImmutableGraph<N>
asGraph()
Returns a live view of this network as aGraph
.protected com.google.common.graph.NetworkConnections<N,E>
checkedConnections(N node)
protected N
checkedReferenceNode(E edge)
protected boolean
containsEdge(@Nullable E edge)
protected boolean
containsNode(@Nullable N node)
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()
.Set<E>
edges()
Returns all edges in this network, in the order specified byNetwork.edgeOrder()
.Set<E>
edgesConnecting(N nodeU, N nodeV)
Returns the set of edges that each directly connectnodeU
tonodeV
.Set<E>
incidentEdges(N node)
Returns the edges whoseincident nodes
in this network includenode
.EndpointPair<N>
incidentNodes(E edge)
Returns the nodes which are the endpoints ofedge
in this network.Set<E>
inEdges(N node)
Returns all edges in this network which can be traversed in the direction (if any) of the edge to end atnode
.boolean
isDirected()
Returns true if the edges in this network are directed.ElementOrder<N>
nodeOrder()
Returns the order of iteration for the elements ofNetwork.nodes()
.Set<N>
nodes()
Returns all nodes in this network, in the order specified byNetwork.nodeOrder()
.Set<E>
outEdges(N node)
Returns all edges in this network which can be traversed in the direction (if any) of the edge starting fromnode
.Set<N>
predecessors(N node)
Returns all nodes in this network adjacent tonode
which can be reached by traversingnode
's incoming edges against the direction (if any) of the edge.Set<N>
successors(N node)
Returns all nodes in this network adjacent tonode
which 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, edgesConnecting, equals, hasEdgeConnecting, hasEdgeConnecting, hashCode, inDegree, isOrderingCompatible, outDegree, toString, validateEndpoints
-
-
-
-
Method Detail
-
copyOf
public static <N,E> ImmutableNetwork<N,E> copyOf(Network<N,E> network)
Returns an immutable copy ofnetwork
.
-
copyOf
@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:Network
Returns a live view of this network as aGraph
. The resultingGraph
will have an edge connecting node A to node B if thisNetwork
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, theNetwork.degree(Object)
of a node in theGraph
view may be less than the degree of the same node in thisNetwork
.
-
nodes
public Set<N> nodes()
Description copied from interface:Network
Returns all nodes in this network, in the order specified byNetwork.nodeOrder()
.
-
edges
public Set<E> edges()
Description copied from interface:Network
Returns all edges in this network, in the order specified byNetwork.edgeOrder()
.
-
isDirected
public boolean isDirected()
Description copied from interface:Network
Returns true if the edges in this network are directed. Directed edges connect asource node
to atarget node
, while undirected edges connect a pair of nodes to each other.
-
allowsParallelEdges
public boolean allowsParallelEdges()
Description copied from interface:Network
Returns 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()
Description copied from interface:Network
Returns true if this network allows self-loops (edges that connect a node to itself). Attempting to add a self-loop to a network that does not allow them will throw anIllegalArgumentException
.
-
nodeOrder
public ElementOrder<N> nodeOrder()
Description copied from interface:Network
Returns the order of iteration for the elements ofNetwork.nodes()
.
-
edgeOrder
public ElementOrder<E> edgeOrder()
Description copied from interface:Network
Returns the order of iteration for the elements ofNetwork.edges()
.
-
incidentEdges
public Set<E> incidentEdges(N node)
Description copied from interface:Network
Returns the edges whoseincident nodes
in this network includenode
.This is equal to the union of
Network.inEdges(Object)
andNetwork.outEdges(Object)
.
-
incidentNodes
public EndpointPair<N> incidentNodes(E edge)
Description copied from interface:Network
Returns the nodes which are the endpoints ofedge
in this network.
-
adjacentNodes
public Set<N> adjacentNodes(N node)
Description copied from interface:Network
Returns the nodes which have an incident edge in common withnode
in this network.This is equal to the union of
Network.predecessors(Object)
andNetwork.successors(Object)
.
-
edgesConnecting
public Set<E> edgesConnecting(N nodeU, N nodeV)
Description copied from interface:Network
Returns the set of edges that each directly connectnodeU
tonodeV
.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()
).- Specified by:
edgesConnecting
in interfaceNetwork<N,E>
- Overrides:
edgesConnecting
in classAbstractNetwork<N,E>
-
inEdges
public Set<E> inEdges(N node)
Description copied from interface:Network
Returns 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)
.
-
outEdges
public Set<E> outEdges(N node)
Description copied from interface:Network
Returns 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)
.
-
predecessors
public Set<N> predecessors(N node)
Description copied from interface:Network
Returns all nodes in this network adjacent tonode
which can be reached by traversingnode
's incoming edges against the direction (if any) of the edge.In an undirected network, this is equivalent to
Network.adjacentNodes(Object)
.
-
successors
public Set<N> successors(N node)
Description copied from interface:Network
Returns all nodes in this network adjacent tonode
which can be reached by traversingnode
's outgoing edges in the direction (if any) of the edge.In an undirected network, this is equivalent to
Network.adjacentNodes(Object)
.This is not the same as "all nodes reachable from
node
by following outgoing edges". For that functionality, seeGraphs.reachableNodes(Graph, Object)
.
-
checkedConnections
protected final com.google.common.graph.NetworkConnections<N,E> checkedConnections(N node)
-
checkedReferenceNode
protected final N checkedReferenceNode(E edge)
-
containsNode
protected final boolean containsNode(@Nullable N node)
-
containsEdge
protected final boolean containsEdge(@Nullable E edge)
-
-