Top Description Constructors Methods
com.google.common.graph

public abstract Class AbstractNetwork<N, E>

extends Object
implements Network<N, E>
Class Inheritance
All Implemented Interfaces
com.google.common.graph.Network, com.google.common.graph.PredecessorsFunction, com.google.common.graph.SuccessorsFunction
Known Direct Subclasses
com.google.common.graph.ForwardingNetwork, com.google.common.graph.StandardNetwork
Annotations
@Beta
@ElementTypesAreNonnullByDefault
Type Parameters
<N>
Node parameter type
<E>
Edge parameter type
Static Imports
com.google.common.base.Preconditions.checkArgument, .Preconditions.checkNotNull, com.google.common.graph.GraphConstants.ENDPOINTS_MISMATCH, .GraphConstants.MULTIPLE_EDGES_CONNECTING, java.util.Collections.unmodifiableSet

This class provides a skeletal implementation of Network. It is recommended to extend this class rather than implement Network directly.

The methods implemented in this class should not be overridden unless the subclass admits a more efficient implementation.

Author
James Sexton
Since
20.0

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public Set<E>
adjacentEdges(E edge)

Implements com.google.common.graph.Network.adjacentEdges.

Returns the edges which have an incident node in common with edge.
public Graph<N>
asGraph()

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

Returns a live view of this network as a Graph.
private Predicate<E>
connectedPredicate(final N nodePresent, final N nodeToCheck)

public int
degree(N node)

Implements com.google.common.graph.Network.degree.

Returns the count of node's incident edges, counting self-loops twice (equivalently, the number of times an edge touches node).
public Optional<E>
edgeConnecting(N nodeU, N nodeV)

Implements com.google.common.graph.Network.edgeConnecting.

Returns the single edge that directly connects nodeU to nodeV, if one is present, or Optional.empty() if no such edge exists.
public Optional<E>
edgeConnecting(EndpointPair<N> endpoints)

Implements com.google.common.graph.Network.edgeConnecting.

Returns the single edge that directly connects endpoints (in the order, if any, specified by endpoints), if one is present, or Optional.empty() if no such edge exists.
public E
edgeConnectingOrNull(N nodeU, N nodeV)

Implements com.google.common.graph.Network.edgeConnectingOrNull.

Returns the single edge that directly connects nodeU to nodeV, if one is present, or null if no such edge exists.
public E
edgeConnectingOrNull(EndpointPair<N> endpoints)

Implements com.google.common.graph.Network.edgeConnectingOrNull.

Returns the single edge that directly connects endpoints (in the order, if any, specified by endpoints), if one is present, or null if no such edge exists.
private static <N, E> Map<E, EndpointPair<N>>
edgeIncidentNodesMap(final Network<N, E> network)

public Set<E>
edgesConnecting(N nodeU, N nodeV)

Implements com.google.common.graph.Network.edgesConnecting.

Returns the set of edges that each directly connect nodeU to nodeV.
public Set<E>
edgesConnecting(EndpointPair<N> endpoints)

Implements com.google.common.graph.Network.edgesConnecting.

Returns the set of edges that each directly connect endpoints (in the order, if any, specified by endpoints).
public final boolean
equals(Object
the reference object with which to compare.
obj
)

Overrides java.lang.Object.equals.

Implements com.google.common.graph.Network.equals.

Returns true iff object is a Network that has the same elements and the same structural relationships as those in this network.
public boolean
hasEdgeConnecting(N nodeU, N nodeV)

Implements com.google.common.graph.Network.hasEdgeConnecting.

Returns true if there is an edge that directly connects nodeU to nodeV.
public boolean
hasEdgeConnecting(EndpointPair<N> endpoints)

Implements com.google.common.graph.Network.hasEdgeConnecting.

Returns true if there is an edge that directly connects endpoints (in the order, if any, specified by endpoints).
public final int
hashCode()

Overrides java.lang.Object.hashCode.

Implements com.google.common.graph.Network.hashCode.

Returns the hash code for this network.
public int
inDegree(N node)

Implements com.google.common.graph.Network.inDegree.

Returns the count of node's incoming edges in a directed network.
protected final boolean
public int
outDegree(N node)

Implements com.google.common.graph.Network.outDegree.

Returns the count of node's outgoing edges in a directed network.
public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of this network.
protected final void
validateEndpoints(EndpointPair<?> endpoints)

Throws an IllegalArgumentException if the ordering of endpoints is not compatible with the directionality of this graph.

Inherited from java.lang.Object:
clonefinalizegetClassnotifynotifyAllwaitwaitwait

Constructor Detail

AbstractNetworkback to summary
public AbstractNetwork()

Method Detail

adjacentEdgesback to summary
public Set<E> adjacentEdges(E edge)

Implements com.google.common.graph.Network.adjacentEdges.

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

Returns the edges which have an incident node in common with edge. An edge is not considered adjacent to itself.

Annotations
@Override
asGraphback to summary
public Graph<N> 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
connectedPredicateback to summary
private Predicate<E> connectedPredicate(final N nodePresent, final N nodeToCheck)
degreeback to summary
public int degree(N node)

Implements com.google.common.graph.Network.degree.

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

Returns the count of node's incident edges, counting self-loops twice (equivalently, the number of times an edge touches node).

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 to node).

If the count is greater than Integer.MAX_VALUE, returns Integer.MAX_VALUE.

Annotations
@Override
edgeConnectingback to summary
public Optional<E> edgeConnecting(N nodeU, N nodeV)

Implements com.google.common.graph.Network.edgeConnecting.

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

Returns the single edge that directly connects nodeU to nodeV, if one is present, or Optional.empty() if no such edge exists.

In an undirected network, this is equal to edgeConnecting(nodeV, nodeU).

Annotations
@Override
edgeConnectingback to summary
public Optional<E> edgeConnecting(EndpointPair<N> endpoints)

Implements com.google.common.graph.Network.edgeConnecting.

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

Returns the single edge that directly connects endpoints (in the order, if any, specified by endpoints), if one is present, or Optional.empty() if no such edge exists.

If this graph is directed, the endpoints must be ordered.

Annotations
@Override
edgeConnectingOrNullback to summary
public E edgeConnectingOrNull(N nodeU, N nodeV)

Implements com.google.common.graph.Network.edgeConnectingOrNull.

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

Returns the single edge that directly connects nodeU to nodeV, if one is present, or null if no such edge exists.

In an undirected network, this is equal to edgeConnectingOrNull(nodeV, nodeU).

Annotations
@Override
@CheckForNull
edgeConnectingOrNullback to summary
public E edgeConnectingOrNull(EndpointPair<N> endpoints)

Implements com.google.common.graph.Network.edgeConnectingOrNull.

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

Returns the single edge that directly connects endpoints (in the order, if any, specified by endpoints), if one is present, or null if no such edge exists.

If this graph is directed, the endpoints must be ordered.

Annotations
@Override
@CheckForNull
edgeIncidentNodesMapback to summary
private static <N, E> Map<E, EndpointPair<N>> edgeIncidentNodesMap(final Network<N, E> network)
edgesConnectingback to summary
public Set<E> edgesConnecting(N nodeU, N nodeV)

Implements com.google.common.graph.Network.edgesConnecting.

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

Returns the set of edges that each directly connect nodeU to nodeV.

In an undirected network, this is equal to edgesConnecting(nodeV, nodeU).

The resulting set of edges will be parallel (i.e. have equal incidentNodes(Object)). If this network does not allow parallel edges, the resulting set will contain at most one edge (equivalent to edgeConnecting(nodeU, nodeV).asSet()).

Annotations
@Override
edgesConnectingback to summary
public Set<E> edgesConnecting(EndpointPair<N> endpoints)

Implements com.google.common.graph.Network.edgesConnecting.

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

Returns the set of edges that each directly connect endpoints (in the order, if any, specified by endpoints).

The resulting set of edges will be parallel (i.e. have equal incidentNodes(Object)). If this network does not allow parallel edges, the resulting set will contain at most one edge (equivalent to edgeConnecting(endpoints).asSet()).

If this network is directed, endpoints must be ordered.

Annotations
@Override
equalsback to summary
public final boolean equals(Object obj)

Overrides java.lang.Object.equals.

Implements com.google.common.graph.Network.equals.

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

Returns true iff object is a Network that has the same elements and the same structural relationships as those in this network.

Thus, two networks A and B are equal if all of the following are true:

  • A and B have equal directedness.
  • A and B have equal node sets.
  • A and B have equal edge sets.
  • Every edge in A and B connects the same nodes in the same direction (if any).

Network properties besides directedness do not affect equality. For example, two networks may be considered equal even if one allows parallel edges and the other doesn't. Additionally, the order in which nodes or edges are added to the network, and the order in which they are iterated over, are irrelevant.

A reference implementation of this is provided by AbstractNetwork#equals(Object).

Parameters
obj:Object

Doc from java.lang.Object.equals.

the reference object with which to compare.

Returns:boolean

Doc from java.lang.Object.equals.

true if this object is the same as the obj argument; false otherwise.

Annotations
@Override
hasEdgeConnectingback to summary
public boolean hasEdgeConnecting(N nodeU, N nodeV)

Implements com.google.common.graph.Network.hasEdgeConnecting.

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

Returns true if there is an edge that directly connects nodeU to nodeV. This is equivalent to nodes().contains(nodeU) && successors(nodeU).contains(nodeV), and to edgeConnectingOrNull(nodeU, nodeV) != null.

In an undirected graph, this is equal to hasEdgeConnecting(nodeV, nodeU).

Annotations
@Override
hasEdgeConnectingback to summary
public boolean hasEdgeConnecting(EndpointPair<N> endpoints)

Implements com.google.common.graph.Network.hasEdgeConnecting.

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

Returns true if there is an edge that directly connects endpoints (in the order, if any, specified by endpoints).

Unlike the other EndpointPair-accepting methods, this method does not throw if the endpoints are unordered and the graph is directed; it simply returns false. This is for consistency with Graph#hasEdgeConnecting(EndpointPair) and ValueGraph#hasEdgeConnecting(EndpointPair).

Annotations
@Override
hashCodeback to summary
public final int hashCode()

Overrides java.lang.Object.hashCode.

Implements com.google.common.graph.Network.hashCode.

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

Returns the hash code for this network. The hash code of a network is defined as the hash code of a map from each of its edges to their incident nodes.

A reference implementation of this is provided by AbstractNetwork#hashCode().

Returns:int

Doc from java.lang.Object.hashCode.

a hash code value for this object.

Annotations
@Override
inDegreeback to summary
public int inDegree(N node)

Implements com.google.common.graph.Network.inDegree.

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

Returns the count of node's incoming edges in a directed network. In an undirected network, returns the degree(Object).

If the count is greater than Integer.MAX_VALUE, returns Integer.MAX_VALUE.

Annotations
@Override
isOrderingCompatibleback to summary
protected final boolean isOrderingCompatible(EndpointPair<?> endpoints)
outDegreeback to summary
public int outDegree(N node)

Implements com.google.common.graph.Network.outDegree.

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

Returns the count of node's outgoing edges in a directed network. In an undirected network, returns the degree(Object).

If the count is greater than Integer.MAX_VALUE, returns Integer.MAX_VALUE.

Annotations
@Override
toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Returns a string representation of this network.

Returns:String

Doc from java.lang.Object.toString.

a string representation of the object.

Annotations
@Override
validateEndpointsback to summary
protected final void validateEndpoints(EndpointPair<?> endpoints)

Throws an IllegalArgumentException if the ordering of endpoints is not compatible with the directionality of this graph.