Package it.unimi.dsi.fastutil
Interface SortedPair<K extends Comparable<K>>
- Type Parameters:
K
- the type of the elements.
- All Superinterfaces:
Pair<K,
K>
- All Known Subinterfaces:
ByteByteSortedPair
,CharCharSortedPair
,DoubleDoubleSortedPair
,FloatFloatSortedPair
,IntIntSortedPair
,LongLongSortedPair
,ShortShortSortedPair
- All Known Implementing Classes:
ByteByteImmutableSortedPair
,CharCharImmutableSortedPair
,DoubleDoubleImmutableSortedPair
,FloatFloatImmutableSortedPair
,IntIntImmutableSortedPair
,LongLongImmutableSortedPair
,ObjectObjectImmutableSortedPair
,ShortShortImmutableSortedPair
A pair of sorted elements.
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.
-
Method Summary
Modifier and TypeMethodDescriptiondefault boolean
Returns true if one of the two elements of this sorted pair is equal to a given object.static <K extends Comparable<K>>
SortedPair<K> of
(K l, K r) Returns a new immutableSortedPair
with given left and right value.
-
Method Details
-
of
Returns a new immutableSortedPair
with given left and right value.Note that if
left
andright
are in the wrong order, they will be exchanged.- Parameters:
l
- the left value.r
- the right value.- Implementation Notes:
- This factory method delegates to
ObjectObjectImmutablePair.of(Object, Object)
.
-
contains
Returns true if one of the two elements of this sorted pair is equal to a given object.- Parameters:
o
- an object, ornull
-- Returns:
- true if one of the two elements of this sorted pair is equal to
o
.
-