Top Description Fields Constructors Methods
org.apache.commons.lang3.tuple

public Class ImmutablePair<L, R>

extends Pair<L, R>
Class Inheritance
Known Direct Subclasses
org.apache.commons.lang3.time.StopWatch.Split
Type Parameters
<L>
the left element type
<R>
the right element type
Imports
java.util.Map, .Objects

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.

#ThreadSafe# if both paired objects are thread-safe

Since
3.0

Field Summary

Modifier and TypeField and Description
public static final ImmutablePair<?, ?>[]
public final L
left

Left object

private static final ImmutablePair<L, R>
NULL

An immutable pair of nulls.

public final R
right

Right object

private static final long

Constructor Summary

AccessConstructor and Description
public
ImmutablePair(final L
the left value, may be null
left
,
final R
the right value, may be null
right
)

Create a new pair instance.

Method Summary

Modifier and TypeMethod and Description
public static <
the left element type
L
,
the right element type
R
>
ImmutablePair<L, R>[]

Returns:

the empty array singleton that can be assigned without compiler warning.
emptyArray
()

Hides org.apache.commons.lang3.tuple.Pair.emptyArray.

Returns the empty array singleton that can be assigned without compiler warning.

public L
getLeft()

Implements abstract org.apache.commons.lang3.tuple.Pair.getLeft.

Gets the left element from this pair.

public R
getRight()

Implements abstract org.apache.commons.lang3.tuple.Pair.getRight.

Gets the right element from this pair.

public static <
the left element type.
L
,
the right element type.
R
>
Pair<L, R>

Returns:

an immutable formed from the two parameters, not null.
left
(final L
the left element, may be null.
left
)

Creates an immutable pair of two objects inferring the generic types.

public static <
the left element of this pair. Value is null.
L
,
the right element of this pair. Value is null.
R
>
ImmutablePair<L, R>

Returns:

an immutable pair of nulls.
nullPair
()

Returns an immutable pair of nulls.

public static <
the left element type.
L
,
the right element type.
R
>
ImmutablePair<L, R>

Returns:

an immutable formed from the two parameters, not null.
of
(final L
the left element, may be null.
left
,
final R
the right element, may be null.
right
)

Hides org.apache.commons.lang3.tuple.Pair.of.

Creates an immutable pair of two objects inferring the generic types.

public static <
the left element type.
L
,
the right element type.
R
>
ImmutablePair<L, R>

Returns:

an immutable formed from the map entry.
of
(final Map.Entry<L, R>
the existing map entry.
pair
)

Hides org.apache.commons.lang3.tuple.Pair.of.

Creates an immutable pair from a map entry.

public static <
the left element type.
L
,
the right element type.
R
>
ImmutablePair<L, R>

Returns:

an immutable formed from the two parameters, not null.
ofNonNull
(final L
the left element, may not be null.
left
,
final R
the right element, may not be null.
right
)

Hides org.apache.commons.lang3.tuple.Pair.ofNonNull.

Creates an immutable pair of two non-null objects inferring the generic types.

public static <
the left element type.
L
,
the right element type.
R
>
Pair<L, R>

Returns:

an immutable formed from the two parameters, not null.
right
(final R
the right element, may be null.
right
)

Creates an immutable pair of two objects inferring the generic types.

public R

Returns:

never
setValue
(final R
the value to set
value
)

Implements java.util.Map.Entry.setValue.

Throws UnsupportedOperationException.

Inherited from org.apache.commons.lang3.tuple.Pair:
acceptapplycompareToequalsgetKeygetValuehashCodetoStringtoString

Field Detail

EMPTY_ARRAYback to summary
public static final ImmutablePair<?, ?>[] EMPTY_ARRAY

Hides org.apache.commons.lang3.tuple.Pair.EMPTY_ARRAY.

An empty array.

Consider using emptyArray() to avoid generics warnings.

Since
3.10
leftback to summary
public final L left

Left object

NULLback to summary
private static final ImmutablePair<L, R> NULL

An immutable pair of nulls.

Annotations
@SuppressWarnings:rawtypes
serialVersionUIDback to summary
private static final long serialVersionUID

Hides org.apache.commons.lang3.tuple.Pair.serialVersionUID.

Serialization version

Constructor Detail

ImmutablePairback to summary
public ImmutablePair(final L left, final R right)

Create a new pair instance.

Parameters
left:L

the left value, may be null

right:R

the right value, may be null

Method Detail

emptyArrayback to summary
public static <L, R> ImmutablePair<L, R>[] emptyArray()

Hides org.apache.commons.lang3.tuple.Pair.emptyArray.

Returns the empty array singleton that can be assigned without compiler warning.

Parameters
<L>
the left element type
<R>
the right element type
Returns:ImmutablePair<L, R>[]

the empty array singleton that can be assigned without compiler warning.

Annotations
@SuppressWarnings:unchecked
Since
3.10
getLeftback to summary
public L getLeft()

Implements abstract org.apache.commons.lang3.tuple.Pair.getLeft.

Doc from org.apache.commons.lang3.tuple.Pair.getLeft.

Gets the left element from this pair.

When treated as a key-value pair, this is the key.

Annotations
@Override
getRightback to summary
public R getRight()

Implements abstract org.apache.commons.lang3.tuple.Pair.getRight.

Doc from org.apache.commons.lang3.tuple.Pair.getRight.

Gets the right element from this pair.

When treated as a key-value pair, this is the value.

Annotations
@Override
leftback to summary
public static <L, R> Pair<L, R> left(final L left)

Creates an immutable pair of two objects inferring the generic types.

Parameters
<L>
the left element type.
<R>
the right element type.
left:L

the left element, may be null.

Returns:Pair<L, R>

an immutable formed from the two parameters, not null.

Since
3.11
nullPairback to summary
public static <L, R> ImmutablePair<L, R> nullPair()

Returns an immutable pair of nulls.

Parameters
<L>
the left element of this pair. Value is null.
<R>
the right element of this pair. Value is null.
Returns:ImmutablePair<L, R>

an immutable pair of nulls.

Annotations
@SuppressWarnings:unchecked
Since
3.6
ofback to summary
public static <L, R> ImmutablePair<L, R> of(final L left, final R right)

Hides org.apache.commons.lang3.tuple.Pair.of.

Creates an immutable pair of two objects inferring the generic types.

Parameters
<L>
the left element type.
<R>
the right element type.
left:L

the left element, may be null.

right:R

the right element, may be null.

Returns:ImmutablePair<L, R>

an immutable formed from the two parameters, not null.

ofback to summary
public static <L, R> ImmutablePair<L, R> of(final Map.Entry<L, R> pair)

Hides org.apache.commons.lang3.tuple.Pair.of.

Creates an immutable pair from a map entry.

Parameters
<L>
the left element type.
<R>
the right element type.
pair:Map.Entry<L, R>

the existing map entry.

Returns:ImmutablePair<L, R>

an immutable formed from the map entry.

Since
3.10
ofNonNullback to summary
public static <L, R> ImmutablePair<L, R> ofNonNull(final L left, final R right)

Hides org.apache.commons.lang3.tuple.Pair.ofNonNull.

Creates an immutable pair of two non-null objects inferring the generic types.

Parameters
<L>
the left element type.
<R>
the right element type.
left:L

the left element, may not be null.

right:R

the right element, may not be null.

Returns:ImmutablePair<L, R>

an immutable formed from the two parameters, not null.

Exceptions
NullPointerException:
if any input is null.
Since
3.13.0
rightback to summary
public static <L, R> Pair<L, R> right(final R right)

Creates an immutable pair of two objects inferring the generic types.

Parameters
<L>
the left element type.
<R>
the right element type.
right:R

the right element, may be null.

Returns:Pair<L, R>

an immutable formed from the two parameters, not null.

Since
3.11
setValueback to summary
public R setValue(final R value)

Implements java.util.Map.Entry.setValue.

Throws UnsupportedOperationException.

This pair is immutable, so this operation is not supported.

Parameters
value:R

the value to set

Returns:R

never

Annotations
@Override
Exceptions
UnsupportedOperationException:
as this operation is not supported