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> NTuple
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
- Author:
- Chakib Daii
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionfinal LLeft object.private static final ImmutablePairAn immutable pair of nulls.final RRight object.private static final long -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptiongetLeft()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
-
serialVersionUID
private static final long serialVersionUID- See Also:
-
NULL
An immutable pair of nulls. -
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
-
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
-
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.
-
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
-
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
-
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
-
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
-