public final class CmpUtil extends Object
| 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 <T extends List<U>,U extends Comparable<U>> |
canonicalComparator()
Retrieves a canonical comparator for the given type, which has to be a
List of Comparable types. |
static <T extends List<? extends U>,U> |
canonicalComparator(Comparator<? super U> elemComp)
Retrieves a canonical comparator for the given list type.
|
static int |
canonicalCompare(int[] a1,
int[] a2) |
static <U extends Comparable<? super U>> |
canonicalCompare(List<? extends U> o1,
List<? extends U> o2)
Compares two
Lists of Comparable elements with respect to canonical ordering. |
static <U> int |
canonicalCompare(List<? extends U> o1,
List<? extends U> o2,
Comparator<? super U> elemComparator)
Compares two
Lists with respect to canonical ordering. |
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 int |
lexCompare(int[] a1,
int[] a2) |
static <U extends Comparable<? super U>> |
lexCompare(Iterable<? extends U> o1,
Iterable<? extends U> o2)
Lexicographically compares two
Iterables, whose element types are comparable. |
static <U> int |
lexCompare(Iterable<? extends U> o1,
Iterable<? extends U> o2,
Comparator<U> elemComparator)
Lexicographically compares two
Iterables. |
static <T> Comparator<T> |
safeComparator(Comparator<? super T> baseComp,
CmpUtil.NullOrdering nullOrd)
Retrieves a safe comparator, which can handle
null element values. |
public static <U> int canonicalCompare(List<? extends U> o1, List<? extends U> o2, Comparator<? super U> elemComparator)
Lists with respect to canonical ordering.
In canonical ordering, a sequence o1 is less than a sequence o2 if o1 is shorter than
o2, or if they have the same length and o1 is lexicographically smaller than o2.
o1 - the first listo2 - the second listelemComparator - the comparator for comparing the single elementspublic static int canonicalCompare(int[] a1,
int[] a2)
public static <U extends Comparable<? super U>> int canonicalCompare(List<? extends U> o1, List<? extends U> o2)
Lists of Comparable elements with respect to canonical ordering.
In canonical ordering, a sequence o1 is less than a sequence o2 if o1 is shorter than
o2, or if they have the same length and o1 is lexicographically smaller than o2.
o1 - the first listo2 - the second listpublic static <U> int lexCompare(Iterable<? extends U> o1, Iterable<? extends U> o2, Comparator<U> elemComparator)
Iterables. 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 int lexCompare(int[] a1,
int[] a2)
public static <U extends Comparable<? super U>> int lexCompare(Iterable<? extends U> o1, Iterable<? extends U> o2)
Iterables, whose element types are comparable.public static <T extends Iterable<U>,U> Comparator<T> lexComparator(Comparator<U> elemComp)
elemComp - the comparator to use for comparing the elements.T based on lexicographical ordering.public static <U extends Comparable<U>,T extends Iterable<U>> Comparator<T> lexComparator()
Iterable of Comparable types.public static <T extends List<? extends U>,U> Comparator<T> canonicalComparator(Comparator<? super U> elemComp)
elemComp - the comparator to use for comparing the elements.T based on canonical ordering.public static <T extends List<U>,U extends Comparable<U>> Comparator<T> canonicalComparator()
List of Comparable types.canonicalCompare(List, List)public static <T> Comparator<T> safeComparator(Comparator<? super 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.Copyright © 2020. All rights reserved.