public class IterableComparator
extends java.lang.Object
implements java.util.Comparator<java.lang.Iterable<?>>
Tuple
-compatible Comparator
that will sort Iterable
s
in a manner that is consistent with the byte-representation of Tuple
s.
In particular, if one has two Tuple
s, 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()
).
Tuple
s and List
s 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
Iterable s 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)
Iterable
s in a way consistent with their
byte representation. This is done element-wise and is consistent
with a number of other ways of sorting Tuple
s. 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