Modifier and Type | Class and Description |
---|---|
static class |
CmpUtil.NullOrdering
Enum for controlling which rank is assigned to a
null
element when using a safe comparator
(safeComparator(Comparator, NullOrdering) ). |
Modifier and Type | Method and Description |
---|---|
static <U extends Comparable<U>,T extends Iterable<U>> |
lexComparator()
Retrieves a lexicographical comparator for the given type, which has
to be an
Iterable of Comparable types. |
static <T extends Iterable<U>,U> |
lexComparator(Comparator<U> elemComp)
Retrieves a lexicographical comparator for the given type.
|
static <U extends Comparable<? super U>> |
lexCompare(Iterable<? extends U> o1,
Iterable<? extends U> o2)
Lexicographically compares two
Iterable s, whose element types
are comparable. |
static <U> int |
lexCompare(Iterable<? extends U> o1,
Iterable<? extends U> o2,
Comparator<U> elemComparator)
Lexicographically compares two
Iterable s. |
static <T extends Comparable<T>> |
naturalOrderingComparator()
Retrieves a
Comparator that compares elements according to their
natural ordering (i.e., they have to implement the Comparable
interface. |
static <T> Comparator<T> |
safeComparator(Comparator<T> baseComp,
CmpUtil.NullOrdering nullOrd)
Retrieves a safe comparator, which can handle
null
element values. |
public static <U> int lexCompare(Iterable<? extends U> o1, Iterable<? extends U> o2, Comparator<U> elemComparator)
Iterable
s. Comparison of the
elements is done using the specified comparator.o1
- the first iterable.o2
- the second iterable.elemComparator
- the comparator.< 0
iff o1 is lexicographically smaller,
0
if o1 equals o2 and > 0
otherwise.public static <U extends Comparable<? super U>> int lexCompare(Iterable<? extends U> o1, Iterable<? extends U> o2)
Iterable
s, whose element types
are comparable.o1
- o2
- public static <T extends Iterable<U>,U> Comparator<T> lexComparator(Comparator<U> elemComp)
elemComp
- the comparator to use for comparing the elements.T
.public static <U extends Comparable<U>,T extends Iterable<U>> Comparator<T> lexComparator()
Iterable
of Comparable
types.public static <T> Comparator<T> safeComparator(Comparator<T> baseComp, CmpUtil.NullOrdering nullOrd)
null
element values.
Whether null
values are smaller or bigger than regular
values is controlled by the CmpUtil.NullOrdering
parameter.T
- original element class.baseComp
- the basic comparator.nullOrd
- the ordering policy for null
values.public static <T extends Comparable<T>> Comparator<T> naturalOrderingComparator()
Comparator
that compares elements according to their
natural ordering (i.e., they have to implement the Comparable
interface.
If this comparator is used on elements that don't implement this
interface, this may result in a ClassCastException
.T
- element class.Copyright © 2015. All Rights Reserved.