Package 

Class ImmutablePair

  • All Implemented Interfaces:
    java.io.Serializable , java.lang.Comparable , java.util.Map.Entry

    
    public final class ImmutablePair<L, R>
    extends Pair<L, R>
                        

    An immutable pair consisting of two {@code Object} 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. The class is also not {@code final}, so a subclass could add undesirable behaviour.

    #ThreadSafe# if the objects are threadsafe

    • Field Summary

      Fields 
      Modifier and Type Field Description
      public final L left
      public final R right
    • Constructor Summary

      Constructors 
      Constructor Description
      ImmutablePair(L left, R right) Create a new pair instance.
    • Method Summary

      Modifier and Type Method Description
      L getLeft() Gets the left element from this pair.
      R getRight() Gets the right element from this pair.
      static <L, R> ImmutablePair<L, R> of(L left, R right) Obtains an immutable pair of from two objects inferring the generic types.
      R setValue(R value) Throws {@code UnsupportedOperationException}.
      • Methods inherited from class external.org.apache.commons.lang3.tuple.Pair

        compareTo, equals, getKey, getValue, hashCode, of, toString, toString
      • Methods inherited from class java.util.Map.Entry

        comparingByKey, comparingByValue, getKey, getValue, setValue
      • Methods inherited from class java.lang.Comparable

        compareTo
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • ImmutablePair

        ImmutablePair(L left, R right)
        Create a new pair instance.
        Parameters:
        left - the left value, may be null
        right - the right value, may be null
    • Method Detail

      • getLeft

         L getLeft()

        Gets the left element from this pair.

        When treated as a key-value pair, this is the key.

      • getRight

         R getRight()

        Gets the right element from this pair.

        When treated as a key-value pair, this is the value.

      • of

         static <L, R> ImmutablePair<L, R> of(L left, R right)

        Obtains an immutable pair of from two objects inferring the generic types.

        This factory allows the pair to be created using inference toobtain the generic types.

        Parameters:
        left - the left element, may be null
        right - the right element, may be null
      • setValue

         R setValue(R value)

        Throws {@code UnsupportedOperationException}.

        This pair is immutable, so this operation is not supported.

        Parameters:
        value - the value to set