Package com.google.common.graph
Class AbstractValueGraph<N,V>
- java.lang.Object
-
- com.google.common.graph.AbstractValueGraph<N,V>
-
- Type Parameters:
N- Node parameter typeV- Value parameter type
- All Implemented Interfaces:
PredecessorsFunction<N>,SuccessorsFunction<N>,ValueGraph<N,V>
- Direct Known Subclasses:
ImmutableValueGraph
@Beta public abstract class AbstractValueGraph<N,V> extends java.lang.Object implements ValueGraph<N,V>
This class provides a skeletal implementation ofValueGraph. It is recommended to extend this class rather than implementValueGraphdirectly.The methods implemented in this class should not be overridden unless the subclass admits a more efficient implementation.
- Since:
- 20.0
- Author:
- James Sexton
-
-
Constructor Summary
Constructors Constructor Description AbstractValueGraph()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Graph<N>asGraph()Returns a live view of this graph as aGraph.intdegree(N node)protected longedgeCount()Returns the number of edges in this graph; used to calculate the size ofGraph.edges().java.util.Set<EndpointPair<N>>edges()An implementation ofBaseGraph.edges()defined in terms ofGraph.nodes()andSuccessorsFunction.successors(Object).java.util.Optional<V>edgeValue(EndpointPair<N> endpoints)Returns the value of the edge that connectsendpoints(in the order, if any, specified byendpoints), if one is present; otherwise, returnsOptional.empty().java.util.Optional<V>edgeValue(N nodeU, N nodeV)Returns the value of the edge that connectsnodeUtonodeV(in the order, if any, specified byendpoints), if one is present; otherwise, returnsOptional.empty().booleanequals(java.lang.Object obj)Returnstrueiffobjectis aValueGraphthat has the same elements and the same structural relationships as those in this graph.booleanhasEdgeConnecting(EndpointPair<N> endpoints)booleanhasEdgeConnecting(N nodeU, N nodeV)inthashCode()Returns the hash code for this graph.ElementOrder<N>incidentEdgeOrder()java.util.Set<EndpointPair<N>>incidentEdges(N node)intinDegree(N node)protected booleanisOrderingCompatible(EndpointPair<?> endpoints)Returnstrueiffendpoints' ordering is compatible with the directionality of this graph.intoutDegree(N node)java.lang.StringtoString()Returns a string representation of this graph.protected voidvalidateEndpoints(EndpointPair<?> endpoints)ThrowsIllegalArgumentExceptionif the ordering ofendpointsis not compatible with the directionality of this graph.-
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface com.google.common.graph.ValueGraph
adjacentNodes, allowsSelfLoops, degree, edges, edgeValueOrDefault, edgeValueOrDefault, hasEdgeConnecting, hasEdgeConnecting, incidentEdgeOrder, incidentEdges, inDegree, isDirected, nodeOrder, nodes, outDegree, predecessors, successors
-
-
-
-
Constructor Detail
-
AbstractValueGraph
public AbstractValueGraph()
-
-
Method Detail
-
asGraph
public Graph<N> asGraph()
Description copied from interface:ValueGraphReturns a live view of this graph as aGraph. The resultingGraphwill have an edge connecting node A to node B if thisValueGraphhas an edge connecting A to B.- Specified by:
asGraphin interfaceValueGraph<N,V>
-
edgeValue
public java.util.Optional<V> edgeValue(N nodeU, N nodeV)
Description copied from interface:ValueGraphReturns the value of the edge that connectsnodeUtonodeV(in the order, if any, specified byendpoints), if one is present; otherwise, returnsOptional.empty().- Specified by:
edgeValuein interfaceValueGraph<N,V>
-
edgeValue
public java.util.Optional<V> edgeValue(EndpointPair<N> endpoints)
Description copied from interface:ValueGraphReturns the value of the edge that connectsendpoints(in the order, if any, specified byendpoints), if one is present; otherwise, returnsOptional.empty().If this graph is directed, the endpoints must be ordered.
- Specified by:
edgeValuein interfaceValueGraph<N,V>
-
equals
public final boolean equals(@CheckForNull java.lang.Object obj)
Description copied from interface:ValueGraphReturnstrueiffobjectis aValueGraphthat has the same elements and the same structural relationships as those in this graph.Thus, two value graphs 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. - The
valueof a given edge is the same in both A and B.
Graph properties besides
directednessdo not affect equality. For example, two graphs may be considered equal even if one allows self-loops and the other doesn't. Additionally, the order in which nodes or edges are added to the graph, and the order in which they are iterated over, are irrelevant.A reference implementation of this is provided by
equals(Object).- Specified by:
equalsin interfaceValueGraph<N,V>- Overrides:
equalsin classjava.lang.Object
- A and B have equal
-
hashCode
public final int hashCode()
Description copied from interface:ValueGraphReturns the hash code for this graph. The hash code of a graph is defined as the hash code of a map from each of itsedgesto the associatededge value.A reference implementation of this is provided by
hashCode().- Specified by:
hashCodein interfaceValueGraph<N,V>- Overrides:
hashCodein classjava.lang.Object
-
toString
public java.lang.String toString()
Returns a string representation of this graph.- Overrides:
toStringin classjava.lang.Object
-
edgeCount
protected long edgeCount()
Returns the number of edges in this graph; used to calculate the size ofGraph.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.
-
edges
public java.util.Set<EndpointPair<N>> edges()
An implementation ofBaseGraph.edges()defined in terms ofGraph.nodes()andSuccessorsFunction.successors(Object).
-
incidentEdgeOrder
public ElementOrder<N> incidentEdgeOrder()
-
incidentEdges
public java.util.Set<EndpointPair<N>> incidentEdges(N node)
-
degree
public int degree(N node)
-
inDegree
public int inDegree(N node)
-
outDegree
public int outDegree(N node)
-
hasEdgeConnecting
public boolean hasEdgeConnecting(N nodeU, N nodeV)
-
hasEdgeConnecting
public boolean hasEdgeConnecting(EndpointPair<N> endpoints)
-
validateEndpoints
protected final void validateEndpoints(EndpointPair<?> endpoints)
ThrowsIllegalArgumentExceptionif the ordering ofendpointsis not compatible with the directionality of this graph.
-
isOrderingCompatible
protected final boolean isOrderingCompatible(EndpointPair<?> endpoints)
Returnstrueiffendpoints' ordering is compatible with the directionality of this graph.
-
-