Class ForwardingNetwork<N,E>
- java.lang.Object
-
- com.google.common.graph.AbstractNetwork<N,E>
-
- com.google.common.graph.ForwardingNetwork<N,E>
-
- All Implemented Interfaces:
Network<N,E>
,PredecessorsFunction<N>
,SuccessorsFunction<N>
- Direct Known Subclasses:
Graphs.TransposedNetwork
abstract class ForwardingNetwork<N,E> extends AbstractNetwork<N,E>
A class to allowNetwork
implementations to be backed by a provided delegate. This is not currently planned to be released as a general-purpose forwarding class.
-
-
Constructor Summary
Constructors Constructor Description ForwardingNetwork()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description java.util.Set<E>
adjacentEdges(E edge)
Returns the edges which have anincident node
in common withedge
.java.util.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).int
degree(N node)
Returns the count ofnode
'sincident edges
, counting self-loops twice (equivalently, the number of times an edge touchesnode
).(package private) abstract Network<N,E>
delegate()
java.util.Optional<E>
edgeConnecting(EndpointPair<N> endpoints)
Returns the single edge that directly connectsendpoints
(in the order, if any, specified byendpoints
), if one is present, orOptional.empty()
if no such edge exists.java.util.Optional<E>
edgeConnecting(N nodeU, N nodeV)
Returns the single edge that directly connectsnodeU
tonodeV
, if one is present, orOptional.empty()
if no such edge exists.E
edgeConnectingOrNull(EndpointPair<N> endpoints)
Returns the single edge that directly connectsendpoints
(in the order, if any, specified byendpoints
), if one is present, ornull
if no such edge exists.E
edgeConnectingOrNull(N nodeU, N nodeV)
Returns the single edge that directly connectsnodeU
tonodeV
, if one is present, ornull
if no such edge exists.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(EndpointPair<N> endpoints)
Returns the set of edges that each directly connectendpoints
(in the order, if any, specified byendpoints
).java.util.Set<E>
edgesConnecting(N nodeU, N nodeV)
Returns the set of edges that each directly connectnodeU
tonodeV
.boolean
hasEdgeConnecting(EndpointPair<N> endpoints)
Returns true if there is an edge that directly connectsendpoints
(in the order, if any, specified byendpoints
).boolean
hasEdgeConnecting(N nodeU, N nodeV)
Returns true if there is an edge that directly connectsnodeU
tonodeV
.java.util.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.int
inDegree(N node)
Returns the count ofnode
'sincoming edges
in a directed network.java.util.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()
.java.util.Set<N>
nodes()
Returns all nodes in this network, in the order specified byNetwork.nodeOrder()
.int
outDegree(N node)
Returns the count ofnode
'soutgoing edges
in a directed network.java.util.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
.java.util.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.java.util.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
asGraph, equals, hashCode, isOrderingCompatible, toString, validateEndpoints
-
-
-
-
Method Detail
-
nodes
public java.util.Set<N> nodes()
Description copied from interface:Network
Returns all nodes in this network, in the order specified byNetwork.nodeOrder()
.
-
edges
public java.util.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()
.
-
adjacentNodes
public java.util.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)
.
-
predecessors
public java.util.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 java.util.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)
.
-
incidentEdges
public java.util.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)
.
-
inEdges
public java.util.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 java.util.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)
.
-
incidentNodes
public EndpointPair<N> incidentNodes(E edge)
Description copied from interface:Network
Returns the nodes which are the endpoints ofedge
in this network.
-
adjacentEdges
public java.util.Set<E> adjacentEdges(E edge)
Description copied from interface:Network
Returns the edges which have anincident node
in common withedge
. An edge is not considered adjacent to itself.- Specified by:
adjacentEdges
in interfaceNetwork<N,E>
- Overrides:
adjacentEdges
in classAbstractNetwork<N,E>
-
degree
public int degree(N node)
Description copied from interface:Network
Returns the count ofnode
'sincident edges
, counting self-loops twice (equivalently, the number of times an edge touchesnode
).For directed networks, this is equal to
inDegree(node) + outDegree(node)
.For undirected networks, this is equal to
incidentEdges(node).size()
+ (number of self-loops incident tonode
).If the count is greater than
Integer.MAX_VALUE
, returnsInteger.MAX_VALUE
.
-
inDegree
public int inDegree(N node)
Description copied from interface:Network
Returns the count ofnode
'sincoming edges
in a directed network. In an undirected network, returns theNetwork.degree(Object)
.If the count is greater than
Integer.MAX_VALUE
, returnsInteger.MAX_VALUE
.
-
outDegree
public int outDegree(N node)
Description copied from interface:Network
Returns the count ofnode
'soutgoing edges
in a directed network. In an undirected network, returns theNetwork.degree(Object)
.If the count is greater than
Integer.MAX_VALUE
, returnsInteger.MAX_VALUE
.
-
edgesConnecting
public java.util.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>
-
edgesConnecting
public java.util.Set<E> edgesConnecting(EndpointPair<N> endpoints)
Description copied from interface:Network
Returns the set of edges that each directly connectendpoints
(in the order, if any, specified byendpoints
).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(endpoints).asSet()
).If this network is directed,
endpoints
must be ordered.- Specified by:
edgesConnecting
in interfaceNetwork<N,E>
- Overrides:
edgesConnecting
in classAbstractNetwork<N,E>
-
edgeConnecting
public java.util.Optional<E> edgeConnecting(N nodeU, N nodeV)
Description copied from interface:Network
Returns the single edge that directly connectsnodeU
tonodeV
, if one is present, orOptional.empty()
if no such edge exists.In an undirected network, this is equal to
edgeConnecting(nodeV, nodeU)
.- Specified by:
edgeConnecting
in interfaceNetwork<N,E>
- Overrides:
edgeConnecting
in classAbstractNetwork<N,E>
-
edgeConnecting
public java.util.Optional<E> edgeConnecting(EndpointPair<N> endpoints)
Description copied from interface:Network
Returns the single edge that directly connectsendpoints
(in the order, if any, specified byendpoints
), if one is present, orOptional.empty()
if no such edge exists.If this graph is directed, the endpoints must be ordered.
- Specified by:
edgeConnecting
in interfaceNetwork<N,E>
- Overrides:
edgeConnecting
in classAbstractNetwork<N,E>
-
edgeConnectingOrNull
@CheckForNull public E edgeConnectingOrNull(N nodeU, N nodeV)
Description copied from interface:Network
Returns the single edge that directly connectsnodeU
tonodeV
, if one is present, ornull
if no such edge exists.In an undirected network, this is equal to
edgeConnectingOrNull(nodeV, nodeU)
.- Specified by:
edgeConnectingOrNull
in interfaceNetwork<N,E>
- Overrides:
edgeConnectingOrNull
in classAbstractNetwork<N,E>
-
edgeConnectingOrNull
@CheckForNull public E edgeConnectingOrNull(EndpointPair<N> endpoints)
Description copied from interface:Network
Returns the single edge that directly connectsendpoints
(in the order, if any, specified byendpoints
), if one is present, ornull
if no such edge exists.If this graph is directed, the endpoints must be ordered.
- Specified by:
edgeConnectingOrNull
in interfaceNetwork<N,E>
- Overrides:
edgeConnectingOrNull
in classAbstractNetwork<N,E>
-
hasEdgeConnecting
public boolean hasEdgeConnecting(N nodeU, N nodeV)
Description copied from interface:Network
Returns true if there is an edge that directly connectsnodeU
tonodeV
. This is equivalent tonodes().contains(nodeU) && successors(nodeU).contains(nodeV)
, and toedgeConnectingOrNull(nodeU, nodeV) != null
.In an undirected graph, this is equal to
hasEdgeConnecting(nodeV, nodeU)
.- Specified by:
hasEdgeConnecting
in interfaceNetwork<N,E>
- Overrides:
hasEdgeConnecting
in classAbstractNetwork<N,E>
-
hasEdgeConnecting
public boolean hasEdgeConnecting(EndpointPair<N> endpoints)
Description copied from interface:Network
Returns true if there is an edge that directly connectsendpoints
(in the order, if any, specified byendpoints
).Unlike the other
EndpointPair
-accepting methods, this method does not throw if the endpoints are unordered and the graph is directed; it simply returnsfalse
. This is for consistency withGraph.hasEdgeConnecting(EndpointPair)
andValueGraph.hasEdgeConnecting(EndpointPair)
.- Specified by:
hasEdgeConnecting
in interfaceNetwork<N,E>
- Overrides:
hasEdgeConnecting
in classAbstractNetwork<N,E>
-
-