Top Description Fields Constructors Methods
com.google.common.graph

pack-priv Class StandardNetwork<N, E>

extends AbstractNetwork<N, E>
Class Inheritance
Known Direct Subclasses
com.google.common.graph.ImmutableNetwork, com.google.common.graph.StandardMutableNetwork
Annotations
@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.DEFAULT_EDGE_COUNT, .GraphConstants.DEFAULT_NODE_COUNT, .GraphConstants.EDGE_NOT_IN_GRAPH, .GraphConstants.NODE_NOT_IN_GRAPH, java.util.Objects.requireNonNull

Standard implementation of 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.

Authors
James Sexton, Joshua O'Madadhain, Omar Darwish

Field Summary

Modifier and TypeField and Description
private final boolean
private final boolean
private final ElementOrder<E>
pack-priv final MapIteratorCache<E, N>
private final boolean
pack-priv final MapIteratorCache<N, NetworkConnections<N, E>>
private final ElementOrder<N>

Constructor Summary

AccessConstructor and Description
pack-priv
StandardNetwork(NetworkBuilder<? super N, ? super E> builder)

Constructs a graph with the properties specified in builder.

pack-priv
StandardNetwork(NetworkBuilder<? super N, ? super E> builder, Map<N, NetworkConnections<N, E>> nodeConnections, Map<E, N> edgeToReferenceNode)

Constructs a graph with the properties specified in builder, initialized with the given node and edge maps.

Method Summary

Modifier and TypeMethod and Description
public Set<N>
adjacentNodes(N node)

Implements com.google.common.graph.Network.adjacentNodes.

Returns a live view of the nodes which have an incident edge in common with node in this graph.
public boolean
allowsParallelEdges()

Implements com.google.common.graph.Network.allowsParallelEdges.

Returns true if this network allows parallel edges.
public boolean
allowsSelfLoops()

Implements com.google.common.graph.Network.allowsSelfLoops.

Returns true if this network allows self-loops (edges that connect a node to itself).
pack-priv final NetworkConnections<N, E>
pack-priv final N
pack-priv final boolean
containsEdge(E edge)

pack-priv final boolean
containsNode(N node)

public ElementOrder<E>
edgeOrder()

Implements com.google.common.graph.Network.edgeOrder.

Returns the order of iteration for the elements of edges().
public Set<E>
edges()

Implements com.google.common.graph.Network.edges.

Returns all edges in this network, in the order specified by edgeOrder().
public Set<E>
edgesConnecting(N nodeU, N nodeV)

Overrides com.google.common.graph.AbstractNetwork.edgesConnecting.

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

Returns a live view of the set of edges that each directly connect nodeU to nodeV.
public Set<E>
incidentEdges(N node)

Implements com.google.common.graph.Network.incidentEdges.

Returns a live view of the edges whose incident nodes in this network include node.
public EndpointPair<N>
incidentNodes(E edge)

Implements com.google.common.graph.Network.incidentNodes.

Returns the nodes which are the endpoints of edge in this network.
public Set<E>
inEdges(N node)

Implements com.google.common.graph.Network.inEdges.

Returns a live view of all edges in this network which can be traversed in the direction (if any) of the edge to end at node.
public boolean
isDirected()

Implements com.google.common.graph.Network.isDirected.

Returns true if the edges in this network are directed.
public ElementOrder<N>
nodeOrder()

Implements com.google.common.graph.Network.nodeOrder.

Returns the order of iteration for the elements of nodes().
public Set<N>
nodes()

Implements com.google.common.graph.Network.nodes.

Returns all nodes in this network, in the order specified by nodeOrder().
public Set<E>
outEdges(N node)

Implements com.google.common.graph.Network.outEdges.

Returns a live view of all edges in this network which can be traversed in the direction (if any) of the edge starting from node.
public Set<N>
predecessors(N node)

Implements com.google.common.graph.Network.predecessors.

Returns a live view of all nodes in this network adjacent to node which can be reached by traversing node's incoming edges against the direction (if any) of the edge.
public Set<N>
successors(N node)

Implements com.google.common.graph.Network.successors.

Returns a live view of all nodes in this network adjacent to node which can be reached by traversing node's outgoing edges in the direction (if any) of the edge.
Inherited from com.google.common.graph.AbstractNetwork:
adjacentEdgesasGraphdegreeedgeConnectingedgeConnectingedgeConnectingOrNulledgeConnectingOrNulledgeInvalidatableSetedgesConnectingequalshasEdgeConnectinghasEdgeConnectinghashCodeinDegreeisOrderingCompatiblenodeInvalidatableSetnodePairInvalidatableSetoutDegreetoStringvalidateEndpoints

Field Detail

allowsParallelEdgesback to summary
private final boolean allowsParallelEdges
allowsSelfLoopsback to summary
private final boolean allowsSelfLoops
edgeOrderback to summary
private final ElementOrder<E> edgeOrder
edgeToReferenceNodeback to summary
pack-priv final MapIteratorCache<E, N> edgeToReferenceNode
isDirectedback to summary
private final boolean isDirected
nodeConnectionsback to summary
pack-priv final MapIteratorCache<N, NetworkConnections<N, E>> nodeConnections
nodeOrderback to summary
private final ElementOrder<N> nodeOrder

Constructor Detail

StandardNetworkback to summary
pack-priv StandardNetwork(NetworkBuilder<? super N, ? super E> builder)

Constructs a graph with the properties specified in builder.

StandardNetworkback to summary
pack-priv StandardNetwork(NetworkBuilder<? super N, ? super E> builder, Map<N, NetworkConnections<N, E>> nodeConnections, Map<E, N> edgeToReferenceNode)

Constructs a graph with the properties specified in builder, initialized with the given node and edge maps.

Method Detail

adjacentNodesback to summary
public Set<N> adjacentNodes(N node)

Implements com.google.common.graph.Network.adjacentNodes.

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

Returns a live view of the nodes which have an incident edge in common with node in this graph.

This is equal to the union of predecessors(Object) and successors(Object).

If node is removed from the network after this method is called, the Set view returned by this method will be invalidated, and will throw IllegalStateException if it is accessed in any way, with the following exceptions:

  • view.equals(view) evaluates to true (but any other `equals()` expression involving view will throw)
  • hashCode() does not throw
  • if node is re-added to the network after having been removed, view's behavior is undefined
Annotations
@Override
allowsParallelEdgesback to summary
public boolean allowsParallelEdges()

Implements com.google.common.graph.Network.allowsParallelEdges.

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

Returns true if this network allows parallel edges. Attempting to add a parallel edge to a network that does not allow them will throw an IllegalArgumentException.

Annotations
@Override
allowsSelfLoopsback to summary
public boolean allowsSelfLoops()

Implements com.google.common.graph.Network.allowsSelfLoops.

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

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 an IllegalArgumentException.

Annotations
@Override
checkedConnectionsback to summary
pack-priv final NetworkConnections<N, E> checkedConnections(N node)
checkedReferenceNodeback to summary
pack-priv final N checkedReferenceNode(E edge)
containsEdgeback to summary
pack-priv final boolean containsEdge(E edge)
containsNodeback to summary
pack-priv final boolean containsNode(N node)
edgeOrderback to summary
public ElementOrder<E> edgeOrder()

Implements com.google.common.graph.Network.edgeOrder.

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

Returns the order of iteration for the elements of edges().

Annotations
@Override
edgesback to summary
public Set<E> edges()

Implements com.google.common.graph.Network.edges.

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

Returns all edges in this network, in the order specified by edgeOrder().

Annotations
@Override
edgesConnectingback to summary
public Set<E> edgesConnecting(N nodeU, N nodeV)

Overrides com.google.common.graph.AbstractNetwork.edgesConnecting.

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

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

Returns a live view of 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()).

If either nodeU or nodeV are removed from the network after this method is called, the Set view returned by this method will be invalidated, and will throw IllegalStateException if it is accessed in any way, with the following exceptions:

  • view.equals(view) evaluates to true (but any other `equals()` expression involving view will throw)
  • hashCode() does not throw
  • if nodeU or nodeV are re-added to the network after having been removed, view's behavior is undefined
Annotations
@Override
incidentEdgesback to summary
public Set<E> incidentEdges(N node)

Implements com.google.common.graph.Network.incidentEdges.

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

Returns a live view of the edges whose incident nodes in this network include node.

This is equal to the union of inEdges(Object) and outEdges(Object).

If node is removed from the network after this method is called, the Set view returned by this method will be invalidated, and will throw IllegalStateException if it is accessed in any way, with the following exceptions:

  • view.equals(view) evaluates to true (but any other `equals()` expression involving view will throw)
  • hashCode() does not throw
  • if node is re-added to the network after having been removed, view's behavior is undefined
Annotations
@Override
incidentNodesback to summary
public EndpointPair<N> incidentNodes(E edge)

Implements com.google.common.graph.Network.incidentNodes.

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

Returns the nodes which are the endpoints of edge in this network.

Annotations
@Override
inEdgesback to summary
public Set<E> inEdges(N node)

Implements com.google.common.graph.Network.inEdges.

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

Returns a live view of all edges in this network which can be traversed in the direction (if any) of the edge to end at node.

In a directed network, an incoming edge's EndpointPair#target() equals node.

In an undirected network, this is equivalent to incidentEdges(Object).

If node is removed from the network after this method is called, the Set view returned by this method will be invalidated, and will throw IllegalStateException if it is accessed in any way, with the following exceptions:

  • view.equals(view) evaluates to true (but any other `equals()` expression involving view will throw)
  • hashCode() does not throw
  • if node is re-added to the network after having been removed, view's behavior is undefined
Annotations
@Override
isDirectedback to summary
public boolean isDirected()

Implements com.google.common.graph.Network.isDirected.

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

Returns true if the edges in this network are directed. Directed edges connect a source node to a target node, while undirected edges connect a pair of nodes to each other.

Annotations
@Override
nodeOrderback to summary
public ElementOrder<N> nodeOrder()

Implements com.google.common.graph.Network.nodeOrder.

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

Returns the order of iteration for the elements of nodes().

Annotations
@Override
nodesback to summary
public Set<N> nodes()

Implements com.google.common.graph.Network.nodes.

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

Returns all nodes in this network, in the order specified by nodeOrder().

Annotations
@Override
outEdgesback to summary
public Set<E> outEdges(N node)

Implements com.google.common.graph.Network.outEdges.

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

Returns a live view of all edges in this network which can be traversed in the direction (if any) of the edge starting from node.

In a directed network, an outgoing edge's EndpointPair#source() equals node.

In an undirected network, this is equivalent to incidentEdges(Object).

If node is removed from the network after this method is called, the Set view returned by this method will be invalidated, and will throw IllegalStateException if it is accessed in any way, with the following exceptions:

  • view.equals(view) evaluates to true (but any other `equals()` expression involving view will throw)
  • hashCode() does not throw
  • if node is re-added to the network after having been removed, view's behavior is undefined
Annotations
@Override
predecessorsback to summary
public Set<N> predecessors(N node)

Implements com.google.common.graph.Network.predecessors.

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

Returns a live view of all nodes in this network adjacent to node which can be reached by traversing node's incoming edges against the direction (if any) of the edge.

In an undirected network, this is equivalent to 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.

Annotations
@Override
successorsback to summary
public Set<N> successors(N node)

Implements com.google.common.graph.Network.successors.

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

Returns a live view of all nodes in this network adjacent to node which can be reached by traversing node's outgoing edges in the direction (if any) of the edge.

In an undirected network, this is equivalent to adjacentNodes(Object).

This is not the same as "all nodes reachable from node by following outgoing edges". For that functionality, see Graphs#reachableNodes(Graph, Object).

If node is removed from the network after this method is called, the Set view returned by this method will be invalidated, and will throw IllegalStateException if it is accessed in any way, with the following exceptions:

  • view.equals(view) evaluates to true (but any other `equals()` expression involving view will throw)
  • hashCode() does not throw
  • if node is re-added to the network after having been removed, view's behavior is undefined
Annotations
@Override