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>
A mutable pair consisting of two
Object elements.
Not #ThreadSafe#
- Since:
- 3.0
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final MutablePair<?,?>[] An empty array.Left object.Right object. -
Constructor Summary
ConstructorsConstructorDescriptionCreate a new pair instance of two nulls.MutablePair(L left, R right) Create a new pair instance. -
Method Summary
Modifier and TypeMethodDescriptionstatic <L,R> MutablePair<L, R>[] 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.static <L,R> MutablePair <L, R> Creates a mutable pair from a map entry.static <L,R> MutablePair <L, R> of(L left, R right) Creates a mutable pair of two objects inferring the generic types.static <L,R> MutablePair <L, R> Creates a mutable pair from a map entry.static <L,R> MutablePair <L, R> ofNonNull(L left, R right) Creates a mutable pair of two non-null objects inferring the generic types.voidSets the left element of the pair.voidSets the right element of the pair.Sets theMap.Entryvalue.Methods inherited from class Pair
accept, apply, compareTo, equals, getKey, getValue, hashCode, toString, toStringModifier and TypeMethodDescription<E extends Throwable>
voidaccept(FailableBiConsumer<L, R, E> consumer) Accepts this key and value as arguments to the given consumer.<V, E extends Throwable>
Vapply(FailableBiFunction<L, R, V, E> function) Applies this key and value as arguments to the given function.intCompares the pair based on the left element followed by the right element.booleanCompares this pair to another based on the two elements.final LgetKey()Gets the key from this pair.getValue()Gets the value from this pair.inthashCode()Returns a suitable hash code.toString()Returns a String representation of this pair using the format(left,right).Formats the receiver using the given format.
-
Field Details
-
EMPTY_ARRAY
An empty array.Consider using
emptyArray()to avoid generics warnings.- Since:
- 3.10
-
left
-
right
-
-
Constructor Details
-
MutablePair
public MutablePair()Create a new pair instance of two nulls. -
MutablePair
Create a new pair instance.- Parameters:
left- The left value, may be null.right- The right value, may be null.
-
-
Method Details
-
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
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
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
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
Creates a mutable pair from a map entry.- Type Parameters:
L- The left element typeR- 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
-
getRight
-
setLeft
-
setRight
-
setValue
-