K
- the type of the elements.public interface SortedPair<K extends java.lang.Comparable<K>> extends Pair<K,K>
This interface strengthen Pair
, without adding methods. It assumes that both elements of
the pair are of the same type, and that they are primitive or comparable. It guarantees that the
left element is smaller than or equal to the right
element.
Implementations of this class can be used to represent unordered pairs by
canonicalization. Note that, in particular, if you build a sorted pair using a left and right
element in the wrong order they will be exchanged. To support this usage, this interface provides
a contains(Object)
method that can be used to check whether a given object is equal to
either element of the sorted pair.
Modifier and Type | Method and Description |
---|---|
default boolean |
contains(java.lang.Object o)
Returns true if one of the two elements of this sorted pair is equal to a given object.
|
static <K extends java.lang.Comparable<K>> |
of(K l,
K r)
Returns a new immutable
SortedPair with given left
and right value. |
static <K extends java.lang.Comparable<K>> SortedPair<K> of(K l, K r)
SortedPair
with given left
and right value.
Note that if left
and right
are in the wrong order, they will be exchanged.
default boolean contains(java.lang.Object o)
o
- an object, or null
-o
.