N - Node parameter typeV - Value parameter type@Beta @Immutable(containerOf={"N","V"}) public final class ImmutableValueGraph<N,V> extends AbstractValueGraph<N,V>
ValueGraph whose elements and structural relationships will never change. Instances of
this class may be obtained with copyOf(ValueGraph).
See the Guava User's Guide's discussion
of the Immutable* types for more information on the properties and guarantees
provided by this class.
| Modifier and Type | Field and Description |
|---|---|
protected long |
edgeCount |
protected com.google.common.graph.MapIteratorCache<N,com.google.common.graph.GraphConnections<N,V>> |
nodeConnections |
| Modifier and Type | Method and Description |
|---|---|
Set<N> |
adjacentNodes(N node)
Returns the nodes which have an incident edge in common with
node in this graph. |
boolean |
allowsSelfLoops()
Returns true if this graph allows self-loops (edges that connect a node to itself).
|
ImmutableGraph<N> |
asGraph()
Returns a live view of this graph as a
Graph. |
protected com.google.common.graph.GraphConnections<N,V> |
checkedConnections(N node) |
protected boolean |
containsNode(N node) |
static <N,V> ImmutableValueGraph<N,V> |
copyOf(ImmutableValueGraph<N,V> graph)
Deprecated.
no need to use this
|
static <N,V> ImmutableValueGraph<N,V> |
copyOf(ValueGraph<N,V> graph)
Returns an immutable copy of
graph. |
int |
degree(N node)
Returns the count of
node's incident edges, counting self-loops twice (equivalently,
the number of times an edge touches node). |
protected long |
edgeCount()
Returns the number of edges in this graph; used to calculate the size of
edges(). |
Set<EndpointPair<N>> |
edges()
|
protected V |
edgeValueOrDefault_internal(N nodeU,
N nodeV,
V defaultValue) |
V |
edgeValueOrDefault(EndpointPair<N> endpoints,
V defaultValue)
Returns the value of the edge that connects
endpoints (in the order, if any, specified
by endpoints), if one is present; otherwise, returns defaultValue. |
V |
edgeValueOrDefault(N nodeU,
N nodeV,
V defaultValue)
Returns the value of the edge that connects
nodeU to nodeV, if one is present;
otherwise, returns defaultValue. |
protected boolean |
hasEdgeConnecting_internal(N nodeU,
N nodeV) |
boolean |
hasEdgeConnecting(EndpointPair<N> endpoints)
Returns true if there is an edge that directly connects
endpoints (in the order, if
any, specified by endpoints). |
boolean |
hasEdgeConnecting(N nodeU,
N nodeV)
Returns true if there is an edge that directly connects
nodeU to nodeV. |
Set<EndpointPair<N>> |
incidentEdges(N node)
Returns the edges in this graph whose endpoints include
node. |
int |
inDegree(N node)
Returns the count of
node's incoming edges (equal to predecessors(node).size())
in a directed graph. |
boolean |
isDirected()
Returns true if the edges in this graph are directed.
|
protected boolean |
isOrderingCompatible(EndpointPair<?> endpoints) |
ElementOrder<N> |
nodeOrder()
Returns the order of iteration for the elements of
ValueGraph.nodes(). |
Set<N> |
nodes()
Returns all nodes in this graph, in the order specified by
ValueGraph.nodeOrder(). |
int |
outDegree(N node)
Returns the count of
node's outgoing edges (equal to successors(node).size())
in a directed graph. |
Set<N> |
predecessors(N node)
Returns all nodes in this graph adjacent to
node which can be reached by traversing
node's incoming edges against the direction (if any) of the edge. |
Set<N> |
successors(N node)
Returns all nodes in this graph adjacent to
node which can be reached by traversing
node's outgoing edges in the direction (if any) of the edge. |
protected void |
validateEndpoints(EndpointPair<?> endpoints)
Throws
IllegalArgumentException if the ordering of endpoints is not compatible
with the directionality of this graph. |
equals, hashCode, toStringclone, finalize, getClass, notify, notifyAll, wait, wait, waitdegree, edges, incidentEdges, inDegree, outDegreeprotected final com.google.common.graph.MapIteratorCache<N,com.google.common.graph.GraphConnections<N,V>> nodeConnections
protected long edgeCount
public static <N,V> ImmutableValueGraph<N,V> copyOf(ValueGraph<N,V> graph)
graph.@Deprecated public static <N,V> ImmutableValueGraph<N,V> copyOf(ImmutableValueGraph<N,V> graph)
public ImmutableGraph<N> asGraph()
ValueGraphGraph. The resulting Graph will have an
edge connecting node A to node B if this ValueGraph has an edge connecting A to B.asGraph in interface ValueGraph<N,V>asGraph in class AbstractValueGraph<N,V>public Set<N> nodes()
ValueGraphValueGraph.nodeOrder().public boolean isDirected()
ValueGraphsource node to a target node, while
undirected edges connect a pair of nodes to each other.public boolean allowsSelfLoops()
ValueGraphIllegalArgumentException.public ElementOrder<N> nodeOrder()
ValueGraphValueGraph.nodes().public Set<N> adjacentNodes(N node)
ValueGraphnode in this graph.public Set<N> predecessors(N node)
ValueGraphnode which can be reached by traversing
node's incoming edges against the direction (if any) of the edge.
In an undirected graph, this is equivalent to ValueGraph.adjacentNodes(Object).
public Set<N> successors(N node)
ValueGraphnode which can be reached by traversing
node's outgoing edges in the direction (if any) of the edge.
In an undirected graph, this is equivalent to ValueGraph.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).
public boolean hasEdgeConnecting(N nodeU, N nodeV)
nodeU to nodeV. This is
equivalent to nodes().contains(nodeU) && successors(nodeU).contains(nodeV).
In an undirected graph, this is equal to hasEdgeConnecting(nodeV, nodeU).
hasEdgeConnecting in interface ValueGraph<N,V>public boolean hasEdgeConnecting(EndpointPair<N> endpoints)
endpoints (in the order, if
any, specified by endpoints). This is equivalent to edges().contains(endpoints).
Unlike the other EndpointPair-accepting methods, this method does not throw if the
endpoints are unordered; it simply returns false. This is for consistency with the behavior of
Collection#contains(Object) (which does not generally throw if the object cannot be
present in the collection), and the desire to have this method's behavior be compatible with
edges().contains(endpoints).
hasEdgeConnecting in interface ValueGraph<N,V>@NullableDecl public V edgeValueOrDefault(N nodeU, N nodeV, @NullableDecl V defaultValue)
ValueGraphnodeU to nodeV, if one is present;
otherwise, returns defaultValue.
In an undirected graph, this is equal to edgeValueOrDefault(nodeV, nodeU,
defaultValue).
@NullableDecl public V edgeValueOrDefault(EndpointPair<N> endpoints, @NullableDecl V defaultValue)
ValueGraphendpoints (in the order, if any, specified
by endpoints), if one is present; otherwise, returns defaultValue.
If this graph is directed, the endpoints must be ordered.
protected long edgeCount()
edges(). This
implementation requires O(|N|) time. Classes extending this one may manually keep track of the
number of edges as the graph is updated, and override this method for better performance.protected final com.google.common.graph.GraphConnections<N,V> checkedConnections(N node)
protected final boolean containsNode(@NullableDecl N node)
protected final boolean hasEdgeConnecting_internal(N nodeU, N nodeV)
protected final V edgeValueOrDefault_internal(N nodeU, N nodeV, V defaultValue)
public Set<EndpointPair<N>> edges()
public Set<EndpointPair<N>> incidentEdges(N node)
node.public int degree(N node)
node's incident edges, counting self-loops twice (equivalently,
the number of times an edge touches node).
For directed graphs, this is equal to inDegree(node) + outDegree(node).
For undirected graphs, 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.
public int inDegree(N node)
node's incoming edges (equal to predecessors(node).size())
in a directed graph. In an undirected graph, returns the degree(Object).
If the count is greater than Integer.MAX_VALUE, returns Integer.MAX_VALUE.
public int outDegree(N node)
node's outgoing edges (equal to successors(node).size())
in a directed graph. In an undirected graph, returns the degree(Object).
If the count is greater than Integer.MAX_VALUE, returns Integer.MAX_VALUE.
protected final void validateEndpoints(EndpointPair<?> endpoints)
IllegalArgumentException if the ordering of endpoints is not compatible
with the directionality of this graph.protected final boolean isOrderingCompatible(EndpointPair<?> endpoints)
Copyright © 2010–2019. All rights reserved.