ImmutablePair
- public class org.apache.commons.lang3.tuple.ImmutablePair<L, R> extends Pair<L, R>[source]
An immutable pair consisting of two
Objectelements.Although the implementation is immutable, there is no restriction on the objects that may be stored. If mutable objects are stored in the pair, then the pair itself effectively becomes mutable.
#ThreadSafe# if both paired objects are thread-safe
- Parameters:
<L> – The left element type
<R> – The right element type
- Since:
3.0
Constructors
Create a new pair instance. |
Fields and constants
An empty array. |
|
Left object |
|
Right object |
- public static final ImmutablePair<?, ?>[] EMPTY_ARRAY[source]
An empty array.
Consider using
#emptyArray()to avoid generics warnings.- Since:
3.10
Methods
Returns the empty array singleton that can be assigned without compiler warning. |
|
Gets the left element from this pair. |
|
Gets the right element from this pair. |
|
Creates an immutable pair of two objects inferring the generic types. |
|
Returns an immutable pair of nulls. |
|
Creates an immutable pair of two objects inferring the generic types. |
|
Creates an immutable pair from a map entry. |
|
Creates an immutable pair of two non-null objects inferring the generic types. |
|
Creates an immutable pair of two objects inferring the generic types. |
|
Sets no value and always throws |
- @SuppressWarnings({"unchecked"}) public static <L, R> ImmutablePair<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> Pair<L, R> left(L left)[source]
Creates an immutable 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.
- Returns:
An immutable formed from the two parameters, not null.
- Since:
3.11
- @SuppressWarnings({"unchecked"}) public static <L, R> ImmutablePair<L, R> nullPair()[source]
Returns an immutable pair of nulls.
- Type parameters:
<L> – The left element of this pair. Value is
null.<R> – The right element of this pair. Value is
null.
- Returns:
An immutable pair of nulls.
- Since:
3.6
- public static <L, R> ImmutablePair<L, R> of(L left, R right)[source]
Creates an immutable 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:
An immutable formed from the two parameters, not null.
- public static <L, R> ImmutablePair<L, R> of(Map.Entry<L, R> pair)[source]
Creates an immutable pair from a map entry.
- Type parameters:
<L> – The left element type.
<R> – The right element type.
- Parameters:
pair – The existing map entry.
- Returns:
An immutable formed from the map entry.
- Since:
3.10
- public static <L, R> ImmutablePair<L, R> ofNonNull(L left, R right)[source]
Creates an immutable 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:
An immutable 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> Pair<L, R> right(R right)[source]
Creates an immutable pair of two objects inferring the generic types.
- Type parameters:
<L> – The left element type.
<R> – The right element type.
- Parameters:
right – The right element, may be null.
- Returns:
An immutable formed from the two parameters, not null.
- Since:
3.11
- @Override public R setValue(R value)[source]
Sets no value and always throws
UnsupportedOperationException.This pair is immutable, so this operation is not supported.
- Parameters:
value – The value to set
- Returns:
never
- Throws:
java.lang.UnsupportedOperationException – Thrown because this operation is not supported.