L
- the left element typeR
- the right element typepublic final class ImmutablePair<L,R> extends Pair<L,R>
An immutable pair consisting of two 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. The class is also final
, so a subclass
can not add undesirable behavior.
#ThreadSafe# if both paired objects are thread-safe
Modifier and Type | Field and Description |
---|---|
static ImmutablePair<?,?>[] |
EMPTY_ARRAY
An empty array.
|
L |
left
Left object
|
R |
right
Right object
|
Constructor and Description |
---|
ImmutablePair(L left,
R right)
Create a new pair instance.
|
Modifier and Type | Method and Description |
---|---|
static <L,R> ImmutablePair<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> 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> |
of(L left,
R right)
Creates an immutable pair of two objects inferring the generic types.
|
static <L,R> ImmutablePair<L,R> |
of(Map.Entry<L,R> pair)
Creates an immutable pair from an existing pair.
|
static <L,R> Pair<L,R> |
right(R right)
Creates an immutable pair of two objects inferring the generic types.
|
R |
setValue(R value)
Throws
UnsupportedOperationException . |
compareTo, equals, getKey, getValue, hashCode, toString, toString
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
comparingByKey, comparingByKey, comparingByValue, comparingByValue
public static final ImmutablePair<?,?>[] EMPTY_ARRAY
Consider using emptyArray()
to avoid generics warnings.
public ImmutablePair(L left, R right)
left
- the left value, may be nullright
- the right value, may be nullpublic static <L,R> ImmutablePair<L,R>[] emptyArray()
L
- the left element typeR
- the right element typepublic static <L,R> Pair<L,R> left(L 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.
L
- the left element typeR
- the right element typeleft
- the left element, may be nullpublic static <L,R> ImmutablePair<L,R> nullPair()
L
- the left element of this pair. Value is null
.R
- the right element of this pair. Value is null
.public static <L,R> ImmutablePair<L,R> of(L left, R 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.
L
- the left element typeR
- the right element typeleft
- the left element, may be nullright
- the right element, may be nullpublic static <L,R> ImmutablePair<L,R> of(Map.Entry<L,R> pair)
Creates an immutable pair from an existing pair.
This factory allows the pair to be created using inference to obtain the generic types.
L
- the left element typeR
- the right element typepair
- the existing pair.public static <L,R> Pair<L,R> right(R 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.
L
- the left element typeR
- the right element typeright
- the right element, may be nullpublic L getLeft()
Gets the left element from this pair.
When treated as a key-value pair, this is the key.
public R getRight()
Gets the right element from this pair.
When treated as a key-value pair, this is the value.
public R setValue(R value)
Throws UnsupportedOperationException
.
This pair is immutable, so this operation is not supported.
value
- the value to setUnsupportedOperationException
- as this operation is not supportedCopyright © 2001–2020 The Apache Software Foundation. All rights reserved.