L - type of the left element.R - type of the right element.public class ComparablePair<L,R> extends Pair<L,R> implements Comparative<ComparablePair<L,R>>
The values of the pair can be mutable but the relation, 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 class implements Comparable
so either the values are Comparable or a
suitable Comparator should be provided.
This class implements Emptily.
A pair is considered to be empty if both
of its values are null.
There are several factory methods that cover all the
most common use cases but, if you need to se up a custom
combination of comparable and non comparable
values, you can use the ComparablePair.Builder.
| Modifier and Type | Class and Description |
|---|---|
static class |
ComparablePair.Builder<L>
Implementation of the
pattern builder intended to be used
to create ComparablePairs with custom combination of
comparable and non comparable values. |
| Modifier | Constructor and Description |
|---|---|
protected |
ComparablePair(L left,
Comparator<L> leftComparator,
R right,
Comparator<R> rightComparator)
Constructor with parameters.
|
| Modifier and Type | Method and Description |
|---|---|
int |
compareTo(ComparablePair<L,R> other) |
static <L,R> ComparablePair<L,R> |
empty()
Returns the singleton instance of an empty
ComparablePair. |
Comparator<L> |
getLeftComparator()
Returns the comparator for values of type
<L>. |
Comparator<R> |
getRightComparator()
Returns the comparator for values of type
<R>. |
static <L extends Comparable<L>,R extends Comparable<R>> |
of(L left,
boolean leftNullLast,
R right,
boolean rightNullLast)
Creates a new
ComparablePair with
the given values. |
static <L,R> ComparablePair<L,R> |
of(L left,
Comparator<L> leftComparator,
R right,
Comparator<R> rightComparator)
Creates a new
ComparablePair with
the given values. |
static <L extends Comparable<L>,R extends Comparable<R>> |
of(L left,
R right)
Creates a new
ComparablePair with
the given Comparable values. |
static <L extends Comparable<L>,R extends Comparable<R>> |
of(Pair<L,R> pair)
|
static <L extends Comparable<L>,R extends Comparable<R>> |
of(Pair<L,R> pair,
boolean leftNullLast,
boolean rightNullLast)
Creates a new
ComparablePair starting
from the given Pair of Comparable
values and applies the given behavior for null
values. |
static <L,R> ComparablePair<L,R> |
of(Pair<L,R> pair,
Comparator<L> leftComparator,
Comparator<R> rightComparator)
Creates a new
ComparablePair starting
from the given Pair of Comparable
values and applies the given value comparators. |
static <L extends Comparable<L>> |
withLeft(L value)
Creates a new
ComparablePair.Builder with
the given left value. |
static <L extends Comparable<L>> |
withLeft(L value,
boolean nullLast)
Creates a new
ComparablePair.Builder with
the given left values. |
static <L> ComparablePair.Builder<L> |
withLeft(L value,
Comparator<L> comparator)
Creates a new
ComparablePair.Builder with
the given left values. |
equals, getKey, getLeft, getRight, getValue, hashCode, isEmpty, toStringprotected ComparablePair(L left, Comparator<L> leftComparator, R right, Comparator<R> rightComparator)
This constructor is intended to be used by extending classes only.
To create a new pair use the factory methods.
left - the left element of the pair.leftComparator - the Comparator for the left element.right - the right element of the pair.rightComparator - the Comparator for the right element.public static <L,R> ComparablePair<L,R> empty()
ComparablePair.L - type of the element left.R - type of the element right.ComparablePair.public static <L extends Comparable<L>,R extends Comparable<R>> ComparablePair<L,R> of(L left, R right)
ComparablePair with
the given Comparable values.
This implementation considers null to be
less than non-null. Using this method is
the same as invoking
ComparablePair.of(left,false,right,false).
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 static <L extends Comparable<L>,R extends Comparable<R>> ComparablePair<L,R> of(Pair<L,R> pair)
ComparablePair starting
from the given Pair of Comparable
values.
This implementation considers null to be
less than non-null. Using this method is
the same as invoking
ComparablePair.of(pair,false,false).
This factory method is null-safe, if the
given pair is null, then this method will
return null.
L - type of the left element.R - type of the right element.pair - the source pair to make Comparable.public static <L extends Comparable<L>,R extends Comparable<R>> ComparablePair<L,R> of(L left, boolean leftNullLast, R right, boolean rightNullLast)
ComparablePair with
the given values.L - type of the left element.R - type of the right element.left - the left element of the pair.leftNullLast - tells to consider null to be greater than non-null.right - the right element of the pair.rightNullLast - tells to consider null to be greater than non-null.public static <L extends Comparable<L>,R extends Comparable<R>> ComparablePair<L,R> of(Pair<L,R> pair, boolean leftNullLast, boolean rightNullLast)
ComparablePair starting
from the given Pair of Comparable
values and applies the given behavior for null
values.
This factory method is null-safe, if the
given pair is null, then this method will
return null.
L - type of the left element.R - type of the right element.pair - the source pair to make Comparable.leftNullLast - tells to consider null to be greater than non-null.rightNullLast - tells to consider null to be greater than non-null.public static <L,R> ComparablePair<L,R> of(L left, Comparator<L> leftComparator, R right, Comparator<R> rightComparator)
ComparablePair with
the given values.L - type of the left element.R - type of the right element.left - the left element of the pair.leftComparator - comparator for values of type <L>.right - the right element of the pair.rightComparator - comparator for values of type <R>.public static <L,R> ComparablePair<L,R> of(Pair<L,R> pair, Comparator<L> leftComparator, Comparator<R> rightComparator)
ComparablePair starting
from the given Pair of Comparable
values and applies the given value comparators.
This factory method is null-safe, if the
given pair is null, then this method will
return null.
L - type of the left element.R - type of the right element.pair - the source pair to make Comparable.leftComparator - comparator for values of type <L>.rightComparator - comparator for values of type <R>.public static <L extends Comparable<L>> ComparablePair.Builder<L> withLeft(L value)
ComparablePair.Builder with
the given left value.
This implementation considers null to be
less than non-null. Using this method is
the same as invoking
ComparablePair.left(value,false).
L - type of the left element.value - the left element of the pair.ComparablePair.Builderpublic static <L extends Comparable<L>> ComparablePair.Builder<L> withLeft(L value, boolean nullLast)
ComparablePair.Builder with
the given left values.L - type of the left element.value - the left element of the pair.nullLast - tells to consider null to be greater than non-null.ComparablePair.Builderpublic static <L> ComparablePair.Builder<L> withLeft(L value, Comparator<L> comparator)
ComparablePair.Builder with
the given left values.L - type of the left element.value - the left element of the pair.comparator - comparator for values of type <L>.ComparablePair.Builderpublic int compareTo(ComparablePair<L,R> other)
compareTo in interface Comparable<ComparablePair<L,R>>public Comparator<L> getLeftComparator()
<L>.<L>.public Comparator<R> getRightComparator()
<R>.<R>.Copyright © 2011–2020 Nerd4j. All rights reserved.