public class IterableComparator
extends java.lang.Object
implements java.util.Comparator<java.lang.Iterable<?>>
Tuple-compatible Comparator that will sort Iterables
in a manner that is consistent with the byte-representation of Tuples.
In particular, if one has two Tuples, tuple1 and tuple2,
it is the case that:
tuple1.compareTo(tuple2)
== new IterableComparator().compare(tuple1, tuple2)
== new IterableComparator().compare(tuple1.getItems(), tuple2.getItems()),
== ByteArrayUtil.compareUnsigned(tuple1.pack(), tuple2.pack())
The individual elements of the Iterable must be of a type that can
be serialized by a Tuple. For items of identical types, they will be
sorted in a way that is consistent with their natural ordering with a few
caveats:
UUID.compareTo()).
Tuples and Lists are sorted element-wise.| Constructor and Description |
|---|
IterableComparator()
Creates a new
IterableComparator. |
| Modifier and Type | Method and Description |
|---|---|
int |
compare(java.lang.Iterable<?> iterable1,
java.lang.Iterable<?> iterable2)
Compare two
Iterables in a way consistent with their
byte representation. |
public IterableComparator()
IterableComparator. This Comparator has
no internal state.public int compare(java.lang.Iterable<?> iterable1,
java.lang.Iterable<?> iterable2)
Iterables in a way consistent with their
byte representation. This is done element-wise and is consistent
with a number of other ways of sorting Tuples. This will
raise an IllegalArgumentException if any of the items
of either Iterable cannot be serialized by a Tuple.compare in interface java.util.Comparator<java.lang.Iterable<?>>iterable1 - the first Iterable of itemsiterable2 - the second Iterable of items