Class MutablePair<L,R>

java.lang.Object
org.daiitech.naftah.builtin.utils.tuple.Pair<L,R>
org.daiitech.naftah.builtin.utils.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>, NTuple

public final class MutablePair<L,R> extends Pair<L,R>
A mutable pair consisting of two Object elements.

Not #ThreadSafe#

Author:
Chakib Daii
See Also:
  • Field Details

    • serialVersionUID

      private static final long serialVersionUID
      See Also:
    • left

      public L left
      Left object.
  • 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

    • of

      public static <L, R> MutablePair<L,R> of(L left, R right)
      Creates a mutable pair of 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
    • of

      public static <L, R> MutablePair<L,R> of(Map.Entry<L,R> pair)
      Creates a mutable pair from a map entry.

      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:
      pair - the existing map entry.
      Returns:
      a 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.

      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 not be null
      right - the right element, may not be null
      Returns:
      a pair formed from the two parameters, not null
      Throws:
      NullPointerException - if any input is 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
    • 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