Class EndpointPair<N>

  • All Implemented Interfaces:
    java.lang.Iterable<N>

    @Beta
    @Immutable(containerOf="N")
    public abstract class EndpointPair<N>
    extends java.lang.Object
    implements java.lang.Iterable<N>
    An immutable pair representing the two endpoints of an edge in a graph. The EndpointPair of a directed edge is an ordered pair of nodes (source() and target()). The EndpointPair of an undirected edge is an unordered pair of nodes (nodeU() and nodeV()).

    The edge is a self-loop if, and only if, the two endpoints are equal.

    Since:
    20.0
    Author:
    James Sexton
    • Method Detail

      • ordered

        public static <N> EndpointPair<N> ordered​(N source,
                                                  N target)
        Returns an EndpointPair representing the endpoints of a directed edge.
      • unordered

        public static <N> EndpointPair<N> unordered​(N nodeU,
                                                    N nodeV)
        Returns an EndpointPair representing the endpoints of an undirected edge.
      • source

        public abstract N source()
        If this EndpointPair isOrdered(), returns the node which is the source.
        Throws:
        java.lang.UnsupportedOperationException - if this EndpointPair is not ordered
      • target

        public abstract N target()
        If this EndpointPair isOrdered(), returns the node which is the target.
        Throws:
        java.lang.UnsupportedOperationException - if this EndpointPair is not ordered
      • nodeU

        public final N nodeU()
        If this EndpointPair isOrdered() returns the source(); otherwise, returns an arbitrary (but consistent) endpoint of the origin edge.
      • adjacentNode

        public final N adjacentNode​(java.lang.Object node)
        Returns the node that is adjacent to node along the origin edge.
        Throws:
        java.lang.IllegalArgumentException - if this EndpointPair does not contain node
      • isOrdered

        public abstract boolean isOrdered()
        Returns true if this EndpointPair is an ordered pair (i.e. represents the endpoints of a directed edge).
      • hashCode

        public abstract int hashCode()
        The hashcode of an ordered EndpointPair is equal to Objects.hashCode(source(), target()). The hashcode of an unordered EndpointPair is equal to nodeU().hashCode() + nodeV().hashCode().
        Overrides:
        hashCode in class java.lang.Object