Class AbstractValueGraph<N,V>

java.lang.Object
com.google.common.graph.AbstractBaseGraph<N>
com.google.common.graph.AbstractValueGraph<N,V>
Type Parameters:
N - Node parameter type
V - Value parameter type
All Implemented Interfaces:
BaseGraph<N>, PredecessorsFunction<N>, SuccessorsFunction<N>, ValueGraph<N,V>
Direct Known Subclasses:
ForwardingValueGraph, StandardValueGraph

public abstract class AbstractValueGraph<N,V> extends AbstractBaseGraph<N> implements ValueGraph<N,V>
This class provides a skeletal implementation of ValueGraph. It is recommended to extend this class rather than implement ValueGraph directly.

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

Since:
20.0
  • Constructor Details

    • AbstractValueGraph

      public AbstractValueGraph()
  • Method Details

    • asGraph

      public Graph<N> asGraph()
      Description copied from interface: ValueGraph
      Returns a live view of this graph as a Graph. The resulting Graph will have an edge connecting node A to node B if this ValueGraph has an edge connecting A to B.
      Specified by:
      asGraph in interface ValueGraph<N,V>
    • edgeValue

      public Optional<V> edgeValue(N nodeU, N nodeV)
      Description copied from interface: ValueGraph
      Returns the value of the edge that connects nodeU to nodeV (in the order, if any, specified by endpoints), if one is present; otherwise, returns Optional.empty().
      Specified by:
      edgeValue in interface ValueGraph<N,V>
    • edgeValue

      public Optional<V> edgeValue(EndpointPair<N> endpoints)
      Description copied from interface: ValueGraph
      Returns the value of the edge that connects endpoints (in the order, if any, specified by endpoints), if one is present; otherwise, returns Optional.empty().

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

      Specified by:
      edgeValue in interface ValueGraph<N,V>
    • equals

      public final boolean equals(@CheckForNull Object obj)
      Description copied from interface: ValueGraph
      Returns true iff object is a ValueGraph that 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:

      Graph properties besides directedness do 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:
      equals in interface ValueGraph<N,V>
      Overrides:
      equals in class Object
    • hashCode

      public final int hashCode()
      Description copied from interface: ValueGraph
      Returns the hash code for this graph. The hash code of a graph is defined as the hash code of a map from each of its edges to the associated edge value.

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

      Specified by:
      hashCode in interface ValueGraph<N,V>
      Overrides:
      hashCode in class Object
    • toString

      public String toString()
      Returns a string representation of this graph.
      Overrides:
      toString in class Object
    • edgeValueMap

      private static <N, V> Map<EndpointPair<N>,V> edgeValueMap(ValueGraph<N,V> graph)