org.apache.commons.lang3.tuple

## Class ImmutablePair<L,R>

- java.lang.Object
- - org.apache.commons.lang3.tuple.Pair<L,R>
  - - org.apache.commons.lang3.tuple.ImmutablePair<L,R>

- Type Parameters:
    `L` - the left element type
    `R` - the right element type
  All Implemented Interfaces:
    Serializable, Comparable<Pair<L,R>>, Map.Entry<L,R>

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

  An immutable pair consisting of two `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 `final`, so a subclass can not add undesirable behaviour.

  #ThreadSafe# if both paired objects are thread-safe

  Since:
    Lang 3.0
  Version:
    $Id: ImmutablePair.java 1592817 2014-05-06 17:57:38Z britter $
  See Also:
    Serialized Form

- - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `L` | `left` Left object
    `R` | `right` Right object

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `ImmutablePair(L left, R right)` Create a new pair instance.

  - ### Method Summary

    Methods
    Modifier and Type | Method and 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 `UnsupportedOperationException`.

    - ### Methods inherited from class org.apache.commons.lang3.tuple.Pair

      `compareTo, equals, getKey, getValue, hashCode, toString, toString`

    - ### Methods inherited from class java.lang.Object

      `clone, finalize, getClass, notify, notifyAll, wait, wait, wait`

- - ### Field Detail

    - #### left

          public final L left

      Left object

    - #### right

          public final R right

      Right object

  - ### Constructor Detail

    - #### ImmutablePair

          public 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

    - #### of

          public 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 to obtain the generic types.

      Type Parameters:
        `L` - the left element type
        `R` - the right element type
      Parameters:
        `left` - the left element, may be null
        `right` - the right element, may be null
      Returns:
        a pair formed from the two parameters, not null

    - #### getLeft

          public L getLeft()

      Gets the left element from this pair.

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

      Specified by:
        `getLeft` in class `Pair<L,R>`
      Returns:
        the left element, may be null

    - #### getRight

          public R getRight()

      Gets the right element from this pair.

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

      Specified by:
        `getRight` in class `Pair<L,R>`
      Returns:
        the right element, may be null

    - #### setValue

          public R setValue(R value)

      Throws `UnsupportedOperationException`.

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

      Parameters:
        `value` - the value to set
      Returns:
        never
      Throws:
        `UnsupportedOperationException` - as this operation is not supported

Copyright © 2001–2015 The Apache Software Foundation. All rights reserved.