Class AbstractValueGraph<N,​V>

  • Type Parameters:
    N - Node parameter type
    V - 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 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
    Author:
    James Sexton
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      Graph<N> asGraph()
      Returns a live view of this graph as a Graph.
      int degree​(N node)  
      protected long edgeCount()
      Returns the number of edges in this graph; used to calculate the size of Graph.edges().
      java.util.Set<EndpointPair<N>> edges()
      An implementation of BaseGraph.edges() defined in terms of Graph.nodes() and SuccessorsFunction.successors(Object).
      java.util.Optional<V> edgeValue​(EndpointPair<N> endpoints)
      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().
      java.util.Optional<V> edgeValue​(N nodeU, N nodeV)
      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().
      boolean equals​(java.lang.Object obj)
      Returns true iff object is a ValueGraph that has the same elements and the same structural relationships as those in this graph.
      boolean hasEdgeConnecting​(EndpointPair<N> endpoints)  
      boolean hasEdgeConnecting​(N nodeU, N nodeV)  
      int hashCode()
      Returns the hash code for this graph.
      ElementOrder<N> incidentEdgeOrder()  
      java.util.Set<EndpointPair<N>> incidentEdges​(N node)  
      int inDegree​(N node)  
      protected boolean isOrderingCompatible​(EndpointPair<?> endpoints)
      Returns true iff endpoints' ordering is compatible with the directionality of this graph.
      protected <T> java.util.Set<T> nodeInvalidatableSet​(java.util.Set<T> set, N node)  
      protected <T> java.util.Set<T> nodePairInvalidatableSet​(java.util.Set<T> set, N nodeU, N nodeV)  
      int outDegree​(N node)  
      java.lang.String toString()
      Returns a string representation of this graph.
      protected void validateEndpoints​(EndpointPair<?> endpoints)
      Throws IllegalArgumentException if the ordering of endpoints is not compatible with the directionality of this graph.
      • Methods inherited from class java.lang.Object

        clone, finalize, getClass, notify, notifyAll, wait, wait, wait
    • Method Detail

      • edgeValue

        public java.util.Optional<VedgeValue​(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 java.util.Optional<VedgeValue​(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
                                    java.lang.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 java.lang.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 java.lang.Object
      • toString

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

        protected long edgeCount()
        Returns the number of edges in this graph; used to calculate the size of Graph.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.
      • 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)
        Throws IllegalArgumentException if the ordering of endpoints is not compatible with the directionality of this graph.
      • isOrderingCompatible

        protected final boolean isOrderingCompatible​(EndpointPair<?> endpoints)
        Returns true iff endpoints' ordering is compatible with the directionality of this graph.
      • nodeInvalidatableSet

        protected final <T> java.util.Set<T> nodeInvalidatableSet​(java.util.Set<T> set,
                                                                  N node)
      • nodePairInvalidatableSet

        protected final <T> java.util.Set<T> nodePairInvalidatableSet​(java.util.Set<T> set,
                                                                      N nodeU,
                                                                      N nodeV)