Class MutablePair<L,R>

java.lang.Object
org.apache.commons.lang3.tuple.Pair<L,R>
org.apache.commons.lang3.tuple.MutablePair<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 class MutablePair<L,R> extends Pair<L,R>
A mutable pair consisting of two Object elements.

Not #ThreadSafe#

Since:
3.0
See Also:
  • Field Details

  • Constructor Details

    • MutablePair

      public MutablePair()
      Create a new pair instance of two nulls.
    • MutablePair

      public MutablePair(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 Details

    • emptyArray

      public static <L,R> MutablePair<L,R>[] emptyArray()
      Returns the empty array singleton that can be assigned without compiler warning.
      Type Parameters:
      L - The left element type.
      R - The right element type.
      Returns:
      The empty array singleton that can be assigned without compiler warning.
      Since:
      3.10
    • of

      public static <L,R> MutablePair<L,R> of(L left, R right)
      Creates a mutable pair of two objects inferring 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 mutable pair formed from the two parameters, not null.
    • of

      public static <L,R> MutablePair<L,R> of(Map.Entry<L,R> pair)
      Creates a mutable pair from a map entry.
      Type Parameters:
      L - The left element type.
      R - The right element type.
      Parameters:
      pair - The existing map entry.
      Returns:
      A mutable pair formed from the map entry.
    • ofNonNull

      public static <L,R> MutablePair<L,R> ofNonNull(L left, R right)
      Creates a mutable pair of two non-null objects inferring the generic types.
      Type Parameters:
      L - The left element type.
      R - The right element type.
      Parameters:
      left - The left element, may not be null.
      right - The right element, may not be null.
      Returns:
      A mutable pair formed from the two parameters, not null.
      Throws:
      NullPointerException - Thrown if any input is null.
      Since:
      3.13.0
    • ofNonNull

      public static <L,R> MutablePair<L,R> ofNonNull(Map.Entry<L,R> pair)
      Creates a mutable pair from a map entry.
      Type Parameters:
      L - The left element type
      R - The right element type
      Parameters:
      pair - The existing map entry.
      Returns:
      A mutable pair formed from the map entry
      Throws:
      NullPointerException - Thrown if the pair is null.
      Since:
      3.20
    • 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.
    • setLeft

      public void setLeft(L left)
      Sets the left element of the pair.
      Parameters:
      left - The new value of the left element, may be null.
    • setRight

      public void setRight(R right)
      Sets the right element of the pair.
      Parameters:
      right - The new value of the right element, may be null.
    • setValue

      public R setValue(R value)
      Sets the Map.Entry value. This sets the right element of the pair.
      Parameters:
      value - The right value to set, not null.
      Returns:
      The old value for the right element.