Package org.apache.commons.lang3.tuple
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 typeR
- the right element type
- All Implemented Interfaces:
java.io.Serializable
,java.lang.Comparable<Pair<L,R>>
,java.util.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:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description static MutablePair<?,?>[]
EMPTY_ARRAY
An empty array.L
left
Left objectR
right
Right object
-
Constructor Summary
Constructors Constructor Description MutablePair()
Create a new pair instance of two nulls.MutablePair(L left, R right)
Create a new pair instance.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static <L,R>
MutablePair<L,R>[]emptyArray()
Returns the empty array singleton that can be assigned without compiler warning.L
getLeft()
Gets the left element from this pair.R
getRight()
Gets the right element from this pair.static <L,R>
MutablePair<L,R>of(java.util.Map.Entry<L,R> pair)
Creates a mutable pair from an existing pair.static <L,R>
MutablePair<L,R>of(L left, R right)
Creates a mutable pair of two objects inferring the generic types.void
setLeft(L left)
Sets the left element of the pair.void
setRight(R right)
Sets the right element of the pair.R
setValue(R value)
Sets theMap.Entry
value.
-
-
-
Field Detail
-
EMPTY_ARRAY
public static final MutablePair<?,?>[] EMPTY_ARRAY
An empty array.Consider using
emptyArray()
to avoid generics warnings.- Since:
- 3.10.
-
left
public L left
Left object
-
right
public R right
Right object
-
-
Method Detail
-
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 typeR
- 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.
This factory allows the pair to be created using inference to obtain the generic types.
- Type Parameters:
L
- the left element typeR
- the right element type- Parameters:
left
- the left element, may be nullright
- 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(java.util.Map.Entry<L,R> pair)
Creates a mutable pair from an existing pair.
This factory allows the pair to be created using inference to obtain the generic types.
- Type Parameters:
L
- the left element typeR
- the right element type- Parameters:
pair
- the existing pair.- 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.
-
getRight
public R getRight()
Gets the right element from this pair.
When treated as a key-value pair, this is the value.
-
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
-
-