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 behaviour.
#ThreadSafe# if both paired objects are thread-safe
Modifier and Type | Field and Description |
---|---|
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 |
---|---|
L |
getLeft()
Gets the left element from this pair.
|
R |
getRight()
Gets the right element from this pair.
|
static <L,R> ImmutablePair<L,R> |
nullPair()
Returns an immutable pair of nulls.
|
static <L,R> ImmutablePair<L,R> |
of(L left,
R right)
Obtains 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 ImmutablePair(L left, R right)
left
- the left value, may be nullright
- the right value, 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)
Obtains 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 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–2018 The Apache Software Foundation. All rights reserved.