Class ImmutablePair<L,R> 
- Type Parameters:
- L- the left element type
- R- 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 SummaryFieldsModifier and TypeFieldDescriptionstatic final ImmutablePair<?,?>[] An empty array.final LLeft objectfinal RRight object
- 
Constructor SummaryConstructors
- 
Method SummaryModifier 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_ARRAYAn empty array.Consider using emptyArray()to avoid generics warnings.- Since:
- 3.10.
 
- 
leftLeft object
- 
rightRight object
 
- 
- 
Constructor Details- 
ImmutablePairCreate a new pair instance.- Parameters:
- left- the left value, may be null
- right- the right value, may be null
 
 
- 
- 
Method Details- 
emptyArrayReturns 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.
 
- 
leftCreates 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 type
- R- 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
 
- 
nullPairReturns 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
 
- 
ofCreates 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 type
- R- the right element type
- Parameters:
- left- the left element, may be null
- right- the right element, may be null
- Returns:
- a pair formed from the two parameters, not null
 
- 
ofCreates 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 type
- R- the right element type
- Parameters:
- pair- the existing map entry.
- Returns:
- a pair formed from the map entry
- Since:
- 3.10
 
- 
ofNonNullCreates 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 type
- R- the right element type
- Parameters:
- left- the left element, may not be null
- right- 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
 
- 
rightCreates 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 type
- R- 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
 
- 
getLeftGets the left element from this pair.When treated as a key-value pair, this is the key. 
- 
getRightGets the right element from this pair.When treated as a key-value pair, this is the value. 
- 
setValueThrowsUnsupportedOperationException.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
 
 
-