Class ImmutablePair<L,​R>

  • Type Parameters:
    L - the type of the left element
    R - the type of the right element
    All Implemented Interfaces:
    Serializable, Comparable<ImmutablePair<L,​R>>, Map.Entry<L,​R>

    public class ImmutablePair<L,​R>
    extends Object
    implements Map.Entry<L,​R>, Serializable, Comparable<ImmutablePair<L,​R>>
    Immutable representation of a 2-tuple of elements. Although the implementation is immutable, there is no restriction on the objects that may be stored. If mutable objects are stored in the pair, then the pair itself effectively becomes mutable. ThreadSafe if both paired objects are thread-safe
    See Also:
    Serialized Form
    • Field Detail

      • left

        protected L left
      • right

        protected R right
    • Constructor Detail

      • ImmutablePair

        public ImmutablePair​(L left,
                             R right)
        Create a pair of elements.
        left - the left element
        right - the right element
    • Method Detail

      • getLeft

        public L getLeft()
        the left element
      • getRight

        public R getRight()
        the right element
      • compareTo

        public int compareTo​(ImmutablePair<L,​R> o)
        Compares the pair based on the left element followed by the right element. The types must be Comparable.
        Specified by:
        compareTo in interface Comparable<L>
        other - the other pair, not null
        negative if this is less, zero if equal, positive if greater