MutablePair

public class org.apache.commons.lang3.tuple.MutablePair<L, R> extends Pair<L, R>[source]

A mutable pair consisting of two Object elements.

Not #ThreadSafe#

Parameters:
  • <L> – The left element type.

  • <R> – The right element type.

Since:

3.0

Constructors

MutablePair()

Create a new pair instance of two nulls.

MutablePair(Object, Object)

Create a new pair instance.

public MutablePair()[source]

Create a new pair instance of two nulls.

public MutablePair(L left, R right)[source]

Create a new pair instance.

Parameters:
  • left – The left value, may be null.

  • right – The right value, may be null.

Fields and constants

EMPTY_ARRAY

An empty array.

left

Left object.

right

Right object.

public static final MutablePair<?, ?>[] EMPTY_ARRAY[source]

An empty array.

Consider using #emptyArray() to avoid generics warnings.

Since:

3.10

public L left[source]

Left object.

public R right[source]

Right object.

Methods

emptyArray()

Returns the empty array singleton that can be assigned without compiler warning.

getLeft()

Gets the left element from this pair.

getRight()

Gets the right element from this pair.

of(Object, Object)

Creates a mutable pair of two objects inferring the generic types.

of(Entry)

Creates a mutable pair from a map entry.

ofNonNull(Object, Object)

Creates a mutable pair of two non-null objects inferring the generic types.

ofNonNull(Entry)

Creates a mutable pair from a map entry.

setLeft(Object)

Sets the left element of the pair.

setRight(Object)

Sets the right element of the pair.

setValue(Object)

Sets the Map.Entry value.

@SuppressWarnings({"unchecked"}) public static <L, R> MutablePair<L, R>[] emptyArray()[source]

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

@Override public L getLeft()[source]

Gets the left element from this pair.

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

Returns:

The left element, may be null.

@Override public R getRight()[source]

Gets the right element from this pair.

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

Returns:

The right element, may be null.

public static <L, R> MutablePair<L, R> of(L left, R right)[source]

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.

public static <L, R> MutablePair<L, R> of(Map.Entry<L, R> pair)[source]

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.

public static <L, R> MutablePair<L, R> ofNonNull(L left, R right)[source]

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:

java.lang.NullPointerException – Thrown if any input is null.

Since:

3.13.0

public static <L, R> MutablePair<L, R> ofNonNull(Map.Entry<L, R> pair)[source]

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:

java.lang.NullPointerException – Thrown if the pair is null.

Since:

3.20

public void setLeft(L left)[source]

Sets the left element of the pair.

Parameters:

left – The new value of the left element, may be null.

public void setRight(R right)[source]

Sets the right element of the pair.

Parameters:

right – The new value of the right element, may be null.

@Override public R setValue(R value)[source]

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.