L - the type of the left element.R - the type of the right element.public interface Pair<L,R>
This inferface gives access to a pair of elements <l, r>, where l is the left element and r is the right element. Mutability is optional.
Since pairs have many different interpretation depending on the context, this interface offers
alternative but equivalent access methods based on first/second and key/value. All
such methods have default implementations that delegates to the standard methods. Implementations
need only to provide left() and right(), and possibly left(Object) and
right(Object) for mutability.
Setters return the instance, and are thus chainable. You can write
pair.left(0).right(1)and, if necessary, pass this value to a method.
| Modifier and Type | Method and Description |
|---|---|
default L |
first()
Returns the left element of this pair.
|
default Pair<L,R> |
first(L l)
Sets the left element of this pair (optional operation).
|
default L |
key()
Returns the left element of this pair.
|
default Pair<L,R> |
key(L l)
Sets the left element of this pair (optional operation).
|
L |
left()
Returns the left element of this pair.
|
default Pair<L,R> |
left(L l)
Sets the left element of this pair (optional operation).
|
static <L,R> java.util.Comparator<Pair<L,R>> |
lexComparator()
Returns a lexicographical comparator for pairs.
|
static <L,R> Pair<L,R> |
of(L l,
R r)
Returns a new immutable
Pair with given left and right
value. |
R |
right()
Returns the right element of this pair.
|
default Pair<L,R> |
right(R r)
Sets the right element of this pair (optional operation).
|
default R |
second()
Returns the right element of this pair.
|
default Pair<L,R> |
second(R r)
Sets the right element of this pair (optional operation).
|
default R |
value()
Returns the right element of this pair.
|
default Pair<L,R> |
value(R r)
Sets the right element of this pair (optional operation).
|
L left()
R right()
default Pair<L,R> left(L l)
l - a new value for the left element.default Pair<L,R> right(R r)
r - a new value for the right element.default L first()
default R second()
default Pair<L,R> first(L l)
l - a new value for the left element.default Pair<L,R> second(R r)
r - a new value for the right element.default Pair<L,R> key(L l)
l - a new value for the left element.default Pair<L,R> value(R r)
r - a new value for the right element.default L key()
default R value()
static <L,R> Pair<L,R> of(L l, R r)
Pair with given left and right
value.l - the left value.r - the right value.static <L,R> java.util.Comparator<Pair<L,R>> lexComparator()
The comparator returned by this method implements lexicographical order. It compares first the left elements: if the result of the comparison is nonzero, it returns said result. Otherwise, this comparator returns the result of the comparison of the right elements.