Class ImmutablePair<L,R>
- Type Parameters:
L
- the left element typeR
- the right element type
- All Implemented Interfaces:
Serializable
,Comparable<Pair<L,
,R>> Map.Entry<L,
R>
Object
elements.
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
- Since:
- 3.0
- See Also:
-
Field Summary
Modifier and TypeFieldDescriptionstatic final ImmutablePair<?,
?>[] An empty array.final L
Left objectfinal R
Right object -
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic <L,
R> ImmutablePair<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> Pair<L, R> left
(L left) Creates an immutable pair of two objects inferring the generic types.static <L,
R> ImmutablePair<L, R> nullPair()
Returns an immutable pair of nulls.static <L,
R> ImmutablePair<L, R> Creates an immutable pair from a map entry.static <L,
R> ImmutablePair<L, R> of
(L left, R right) Creates an immutable pair of two objects inferring the generic types.static <L,
R> ImmutablePair<L, R> ofNonNull
(L left, R right) Creates an immutable pair of two non-null objects inferring the generic types.static <L,
R> Pair<L, R> right
(R right) Creates an immutable pair of two objects inferring the generic types.ThrowsUnsupportedOperationException
.
-
Field Details
-
EMPTY_ARRAY
An empty array.Consider using
emptyArray()
to avoid generics warnings.- Since:
- 3.10.
-
left
Left object -
right
Right object
-
-
Constructor Details
-
ImmutablePair
Create a new pair instance.- Parameters:
left
- the left value, may be nullright
- 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 typeR
- the right element type- Returns:
- the empty array singleton that can be assigned without compiler warning.
- Since:
- 3.10.
-
left
Creates an immutable 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 null- Returns:
- a pair formed from the two parameters, not null
- Since:
- 3.11
-
nullPair
Returns an immutable pair of nulls.- Type Parameters:
L
- the left element of this pair. Value isnull
.R
- the right element of this pair. Value isnull
.- Returns:
- an immutable pair of nulls.
- Since:
- 3.6
-
of
Creates an immutable 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
Creates an immutable 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 typeR
- the right element type- Parameters:
pair
- the existing map entry.- Returns:
- a pair formed from the map entry
- Since:
- 3.10
-
ofNonNull
Creates an immutable 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 typeR
- the right element type- Parameters:
left
- the left element, may not be nullright
- the right element, may not be null- Returns:
- a pair formed from the two parameters, not null
- Throws:
NullPointerException
- if any input is null- Since:
- 3.13.0
-
right
Creates an immutable 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:
right
- the right element, may be null- Returns:
- a pair formed from the two parameters, not null
- Since:
- 3.11
-
getLeft
Gets the left element from this pair.When treated as a key-value pair, this is the key.
-
getRight
Gets the right element from this pair.When treated as a key-value pair, this is the value.
-
setValue
ThrowsUnsupportedOperationException
.This pair is immutable, so this operation is not supported.
- Parameters:
value
- the value to set- Returns:
- never
- Throws:
UnsupportedOperationException
- as this operation is not supported
-