Class StandardNetwork<N,E>
- Type Parameters:
N
- Node parameter typeE
- Edge parameter type
- All Implemented Interfaces:
Network<N,
,E> PredecessorsFunction<N>
,SuccessorsFunction<N>
- Direct Known Subclasses:
ImmutableNetwork
,StandardMutableNetwork
Network
that supports the options supplied by NetworkBuilder
.
This class maintains a map of nodes to NetworkConnections
. This class also maintains a
map of edges to reference nodes. The reference node is defined to be the edge's source node on
directed graphs, and an arbitrary endpoint of the edge on undirected graphs.
Collection-returning accessors return unmodifiable views: the view returned will reflect changes to the graph (if the graph is mutable) but may not be modified by the user.
The time complexity of all collection-returning accessors is O(1), since views are returned.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final boolean
private final boolean
private final ElementOrder
<E> (package private) final MapIteratorCache
<E, N> private final boolean
(package private) final MapIteratorCache
<N, NetworkConnections<N, E>> private final ElementOrder
<N> -
Constructor Summary
ConstructorsConstructorDescriptionStandardNetwork
(NetworkBuilder<? super N, ? super E> builder) Constructs a graph with the properties specified inbuilder
.StandardNetwork
(NetworkBuilder<? super N, ? super E> builder, Map<N, NetworkConnections<N, E>> nodeConnections, Map<E, N> edgeToReferenceNode) Constructs a graph with the properties specified inbuilder
, initialized with the given node and edge maps. -
Method Summary
Modifier and TypeMethodDescriptionadjacentNodes
(N node) Returns a live view of the nodes which have an incident edge in common withnode
in this graph.boolean
Returns true if this network allows parallel edges.boolean
Returns true if this network allows self-loops (edges that connect a node to itself).(package private) final NetworkConnections
<N, E> checkedConnections
(N node) (package private) final N
checkedReferenceNode
(E edge) (package private) final boolean
containsEdge
(E edge) (package private) final boolean
containsNode
(N node) Returns the order of iteration for the elements ofNetwork.edges()
.edges()
Returns all edges in this network, in the order specified byNetwork.edgeOrder()
.edgesConnecting
(N nodeU, N nodeV) Returns a live view of the set of edges that each directly connectnodeU
tonodeV
.incidentEdges
(N node) Returns a live view of the edges whoseincident nodes
in this network includenode
.incidentNodes
(E edge) Returns the nodes which are the endpoints ofedge
in this network.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
.boolean
Returns true if the edges in this network are directed.Returns the order of iteration for the elements ofNetwork.nodes()
.nodes()
Returns all nodes in this network, in the order specified byNetwork.nodeOrder()
.Returns a live view of all edges in this network which can be traversed in the direction (if any) of the edge starting fromnode
.predecessors
(N node) Returns a live view of all nodes in this network adjacent tonode
which can be reached by traversingnode
's incoming edges against the direction (if any) of the edge.successors
(N node) Returns a live view of 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, asGraph, degree, edgeConnecting, edgeConnecting, edgeConnectingOrNull, edgeConnectingOrNull, edgeInvalidatableSet, edgesConnecting, equals, hasEdgeConnecting, hasEdgeConnecting, hashCode, inDegree, isOrderingCompatible, nodeInvalidatableSet, nodePairInvalidatableSet, outDegree, toString, validateEndpoints
-
Field Details
-
isDirected
private final boolean isDirected -
allowsParallelEdges
private final boolean allowsParallelEdges -
allowsSelfLoops
private final boolean allowsSelfLoops -
nodeOrder
-
edgeOrder
-
nodeConnections
-
edgeToReferenceNode
-
-
Constructor Details
-
StandardNetwork
StandardNetwork(NetworkBuilder<? super N, ? super E> builder) Constructs a graph with the properties specified inbuilder
. -
StandardNetwork
StandardNetwork(NetworkBuilder<? super N, ? super E> builder, Map<N, NetworkConnections<N, E>> nodeConnections, Map<E, N> edgeToReferenceNode) Constructs a graph with the properties specified inbuilder
, initialized with the given node and edge maps.
-
-
Method Details
-
nodes
Description copied from interface:Network
Returns all nodes in this network, in the order specified byNetwork.nodeOrder()
. -
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
Description copied from interface:Network
Returns the order of iteration for the elements ofNetwork.nodes()
. -
edgeOrder
Description copied from interface:Network
Returns the order of iteration for the elements ofNetwork.edges()
. -
incidentEdges
Description copied from interface:Network
Returns a live view of the edges whoseincident nodes
in this network includenode
.This is equal to the union of
Network.inEdges(Object)
andNetwork.outEdges(Object)
.If
node
is removed from the network after this method is called, theSet
view
returned by this method will be invalidated, and will throwIllegalStateException
if it is accessed in any way, with the following exceptions:view.equals(view)
evaluates totrue
(but any other `equals()` expression involvingview
will throw)hashCode()
does not throw- if
node
is re-added to the network after having been removed,view
's behavior is undefined
-
incidentNodes
Description copied from interface:Network
Returns the nodes which are the endpoints ofedge
in this network. -
adjacentNodes
Description copied from interface:Network
Returns a live view of the nodes which have an incident edge in common withnode
in this graph.This is equal to the union of
Network.predecessors(Object)
andNetwork.successors(Object)
.If
node
is removed from the network after this method is called, theSet
view
returned by this method will be invalidated, and will throwIllegalStateException
if it is accessed in any way, with the following exceptions:view.equals(view)
evaluates totrue
(but any other `equals()` expression involvingview
will throw)hashCode()
does not throw- if
node
is re-added to the network after having been removed,view
's behavior is undefined
-
edgesConnecting
Description copied from interface:Network
Returns a live view of 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()
).If either
nodeU
ornodeV
are removed from the network after this method is called, theSet
view
returned by this method will be invalidated, and will throwIllegalStateException
if it is accessed in any way, with the following exceptions:view.equals(view)
evaluates totrue
(but any other `equals()` expression involvingview
will throw)hashCode()
does not throw- if
nodeU
ornodeV
are re-added to the network after having been removed,view
's behavior is undefined
- Specified by:
edgesConnecting
in interfaceNetwork<N,
E> - Overrides:
edgesConnecting
in classAbstractNetwork<N,
E>
-
inEdges
Description copied from interface:Network
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
.In a directed network, an incoming edge's
EndpointPair.target()
equalsnode
.In an undirected network, this is equivalent to
Network.incidentEdges(Object)
.If
node
is removed from the network after this method is called, theSet
view
returned by this method will be invalidated, and will throwIllegalStateException
if it is accessed in any way, with the following exceptions:view.equals(view)
evaluates totrue
(but any other `equals()` expression involvingview
will throw)hashCode()
does not throw- if
node
is re-added to the network after having been removed,view
's behavior is undefined
-
outEdges
Description copied from interface:Network
Returns 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
node
is removed from the network after this method is called, theSet
view
returned by this method will be invalidated, and will throwIllegalStateException
if it is accessed in any way, with the following exceptions:view.equals(view)
evaluates totrue
(but any other `equals()` expression involvingview
will throw)hashCode()
does not throw- if
node
is re-added to the network after having been removed,view
's behavior is undefined
-
predecessors
Description copied from interface:Network
Returns a live view of 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)
.If
node
is removed from the network after this method is called, the `Set` returned by this method will be invalidated, and will throw `IllegalStateException` if it is accessed in any way. -
successors
Description copied from interface:Network
Returns a live view of 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)
.If
node
is removed from the network after this method is called, theSet
view
returned by this method will be invalidated, and will throwIllegalStateException
if it is accessed in any way, with the following exceptions:view.equals(view)
evaluates totrue
(but any other `equals()` expression involvingview
will throw)hashCode()
does not throw- if
node
is re-added to the network after having been removed,view
's behavior is undefined
-
checkedConnections
-
checkedReferenceNode
-
containsNode
-
containsEdge
-