java.lang.Object
net.automatalib.common.util.comparison.CmpUtil
Various methods for dealing with the comparison of objects.
-
Method Summary
Modifier and TypeMethodDescriptionstatic <T extends List<U>,U extends Comparable<U>>
Comparator<T>Retrieves a canonical comparator for the given type, which has to be aListofComparabletypes.static <T extends List<? extends U>,U>
Comparator<T>canonicalComparator(Comparator<? super U> elemComp) Retrieves a canonical comparator for the given list type.static intcanonicalCompare(int[] a1, int[] a2) static <U extends Comparable<? super U>>
intcanonicalCompare(List<? extends U> o1, List<? extends U> o2) Compares twoLists ofComparableelements with respect to canonical ordering.static <U> intcanonicalCompare(List<? extends U> o1, List<? extends U> o2, Comparator<? super U> elemComparator) Compares twoLists with respect to canonical ordering.static <U extends Comparable<U>,T extends Iterable<U>>
Comparator<T>Retrieves a lexicographical comparator for the given type, which has to be anIterableofComparabletypes.static <T extends Iterable<U>,U>
Comparator<T>lexComparator(Comparator<? super U> elemComp) Retrieves a lexicographical comparator for the given type.static intlexCompare(int[] a1, int[] a2) static <U extends Comparable<? super U>>
intlexCompare(Iterable<? extends U> o1, Iterable<? extends U> o2) Lexicographically compares twoIterables using the inert comparability of their elements.static <U> intlexCompare(Iterable<? extends U> o1, Iterable<? extends U> o2, Comparator<? super U> elemComparator) Lexicographically compares twoIterables.
-
Method Details
-
canonicalCompare
public static <U> int canonicalCompare(List<? extends U> o1, List<? extends U> o2, Comparator<? super U> elemComparator) Compares twoLists with respect to canonical ordering.In canonical ordering, a sequence
o1is less than a sequenceo2ifo1is shorter thano2, or if they have the same length ando1is lexicographically smaller thano2.- Type Parameters:
U- element type- Parameters:
o1- the first listo2- the second listelemComparator- the comparator for comparing the single elements- Returns:
- the result of the comparison
-
canonicalCompare
public static int canonicalCompare(int[] a1, int[] a2) -
canonicalCompare
public static <U extends Comparable<? super U>> int canonicalCompare(List<? extends U> o1, List<? extends U> o2) Compares twoLists ofComparableelements with respect to canonical ordering.In canonical ordering, a sequence
o1is less than a sequenceo2ifo1is shorter thano2, or if they have the same length ando1is lexicographically smaller thano2.- Type Parameters:
U- element type- Parameters:
o1- the first listo2- the second list- Returns:
- the result of the comparison
-
lexCompare
public static <U> int lexCompare(Iterable<? extends U> o1, Iterable<? extends U> o2, Comparator<? super U> elemComparator) Lexicographically compares twoIterables. Comparison of the elements is done using the specified comparator.- Type Parameters:
U- element type- Parameters:
o1- the first iterable.o2- the second iterable.elemComparator- the comparator.- Returns:
< 0iff o1 is lexicographically smaller,0if o1 equals o2 and> 0otherwise.
-
lexCompare
public static int lexCompare(int[] a1, int[] a2) -
lexCompare
public static <U extends Comparable<? super U>> int lexCompare(Iterable<? extends U> o1, Iterable<? extends U> o2) Lexicographically compares twoIterables using the inert comparability of their elements.- Type Parameters:
U- element type- Parameters:
o1- the first iterable.o2- the second iterable.- Returns:
< 0iff o1 is lexicographically smaller,0if o1 equals o2 and> 0otherwise.
-
lexComparator
public static <T extends Iterable<U>,U> Comparator<T> lexComparator(Comparator<? super U> elemComp) Retrieves a lexicographical comparator for the given type.- Type Parameters:
U- element typeT- iterable type- Parameters:
elemComp- the comparator to use for comparing the elements.- Returns:
- a comparator for comparing iterables of type
Ubased on lexicographical ordering.
-
lexComparator
Retrieves a lexicographical comparator for the given type, which has to be anIterableofComparabletypes.- Type Parameters:
U- element typeT- iterable type- Returns:
- the lexicographical comparator.
-
canonicalComparator
public static <T extends List<? extends U>,U> Comparator<T> canonicalComparator(Comparator<? super U> elemComp) Retrieves a canonical comparator for the given list type.- Type Parameters:
U- element typeT- list type- Parameters:
elemComp- the comparator to use for comparing the elements.- Returns:
- a comparator for comparing iterables of type
Ubased on canonical ordering.
-
canonicalComparator
Retrieves a canonical comparator for the given type, which has to be aListofComparabletypes.- Type Parameters:
U- element typeT- list type- Returns:
- the canonical comparator
- See Also:
-