N
- Node parameter typeV
- Value parameter type@Beta 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()
|
V |
edgeValueOrDefault(N nodeU,
N nodeV,
V defaultValue)
Returns the value of the edge connecting
nodeU to nodeV , if one is present;
otherwise, returns defaultValue . |
boolean |
hasEdgeConnecting(N nodeU,
N nodeV)
Returns true if there is an edge directly connecting
nodeU to nodeV . |
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.
|
ElementOrder<N> |
nodeOrder()
Returns the order of iteration for the elements of
nodes() . |
Set<N> |
nodes()
Returns all nodes in this graph, in the order specified by
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. |
equals, hashCode, toString
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
degree, edges, inDegree, outDegree
protected 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()
ValueGraph
Graph
. 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()
ValueGraph
nodeOrder()
.public boolean isDirected()
ValueGraph
source node
to a target node
, while
undirected edges connect a pair of nodes to each other.public boolean allowsSelfLoops()
ValueGraph
IllegalArgumentException
.public ElementOrder<N> nodeOrder()
ValueGraph
nodes()
.public Set<N> adjacentNodes(N node)
ValueGraph
node
in this graph.public Set<N> predecessors(N node)
ValueGraph
node
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 adjacentNodes(Object)
.
public Set<N> successors(N node)
ValueGraph
node
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 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>
@Nullable public V edgeValueOrDefault(N nodeU, N nodeV, @Nullable V defaultValue)
ValueGraph
nodeU
to nodeV
, if one is present;
otherwise, returns defaultValue
.
In an undirected graph, this is equal to edgeValueOrDefault(nodeV, nodeU,
defaultValue)
.
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(@Nullable N node)
public Set<EndpointPair<N>> edges()
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 adjacentNodes(node).size()
+ (1 if node
has an incident self-loop, 0 otherwise).
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
.
Copyright © 2010–2017. All rights reserved.