L - type of the left element.R - type of the right element.public class Pair<L,R> extends Object implements Serializable, Emptily
The values of the pair can be mutable but the association, created by this class, between two instances cannot change.
The values of the pair can be addressed as:
left and right orkey and value
This implementation does't make any assumption
on the nature of the values.
There is an extension of Pair that
requires the provided values to be Comparable
and therefore is able to implement the Comparable
interface for itself.
This class implements Emptily.
A pair is considered to be empty if both
of its values are null.
| Modifier and Type | Field and Description |
|---|---|
protected L |
left
The
left element of the pair. |
protected R |
right
The
right element of the pair. |
| Modifier | Constructor and Description |
|---|---|
protected |
Pair()
Default constructor.
|
protected |
Pair(L left,
R right)
Constructor with parameters.
|
| Modifier and Type | Method and Description |
|---|---|
static <L,R> Pair<L,R> |
empty()
Returns the singleton instance of an empty
Pair. |
boolean |
equals(Object other) |
L |
getKey()
Returns the
left element of the pair. |
L |
getLeft()
Returns the
left element of the pair. |
R |
getRight()
Returns the
right element of the pair. |
R |
getValue()
Returns the
right element of the pair. |
int |
hashCode() |
boolean |
isEmpty()
Returns
true if this object is empty. |
static <L,R> Pair<L,R> |
of(L left,
R right)
Creates a new
Pair with
the given values. |
String |
toString() |
protected final L left
left element of the pair.protected final R right
right element of the pair.protected Pair()
This constructor is intended to be used by reflection during de-serialization.
To create a new pair use the factory methods.
public static <L,R> Pair<L,R> empty()
Pair.L - type of the left element.R - type of the right element.Pair.public static <L,R> Pair<L,R> of(L left, R right)
Pair with
the given values.L - type of the left element.R - type of the right element.left - the left element of the pair.right - the right element of the pair.public boolean isEmpty()
true if this object is empty.public L getLeft()
left element of the pair.left element of the pair.public R getRight()
right element of the pair.right element of the pair.public L getKey()
left element of the pair.left element of the pair.public R getValue()
right element of the pair.right element of the pair.Copyright © 2011–2020 Nerd4j. All rights reserved.