Interface SortedPair<K extends Comparable<K>>

Type Parameters:
K - the type of the elements.
All Superinterfaces:
Pair<K,K>
All Known Subinterfaces:
ByteByteSortedPair, CharCharSortedPair, DoubleDoubleSortedPair, FloatFloatSortedPair, IntIntSortedPair, LongLongSortedPair, ShortShortSortedPair
All Known Implementing Classes:
ByteByteImmutableSortedPair, CharCharImmutableSortedPair, DoubleDoubleImmutableSortedPair, FloatFloatImmutableSortedPair, IntIntImmutableSortedPair, LongLongImmutableSortedPair, ObjectObjectImmutableSortedPair, ShortShortImmutableSortedPair

public interface SortedPair<K extends Comparable<K>> extends Pair<K,K>
A pair of sorted elements.

This interface strengthen Pair, without adding methods. It assumes that both elements of the pair are of the same type, and that they are primitive or comparable. It guarantees that the left element is smaller than or equal to the right element.

Implementations of this class can be used to represent unordered pairs by canonicalization. Note that, in particular, if you build a sorted pair using a left and right element in the wrong order they will be exchanged. To support this usage, this interface provides a contains(Object) method that can be used to check whether a given object is equal to either element of the sorted pair.

  • Method Details

    • of

      static <K extends Comparable<K>> SortedPair<K> of(K l, K r)
      Returns a new immutable SortedPair with given left and right value.

      Note that if left and right are in the wrong order, they will be exchanged.

      Parameters:
      l - the left value.
      r - the right value.
      Implementation Notes:
      This factory method delegates to ObjectObjectImmutablePair.of(Object, Object).
    • contains

      default boolean contains(Object o)
      Returns true if one of the two elements of this sorted pair is equal to a given object.
      Parameters:
      o - an object, or null-
      Returns:
      true if one of the two elements of this sorted pair is equal to o.