Class CmpUtil
- java.lang.Object
-
- net.automatalib.common.util.comparison.CmpUtil
-
public final class CmpUtil extends Object
Various methods for dealing with the comparison of objects.
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static <T extends List<U>,U extends Comparable<U>>
Comparator<T>canonicalComparator()
Retrieves a canonical comparator for the given type, which has to be aList
ofComparable
types.static <T extends List<? extends U>,U>
Comparator<T>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>>
intcanonicalCompare(List<? extends U> o1, List<? extends U> o2)
Compares twoList
s ofComparable
elements with respect to canonical ordering.static <U> int
canonicalCompare(List<? extends U> o1, List<? extends U> o2, Comparator<? super U> elemComparator)
Compares twoList
s with respect to canonical ordering.static <U extends Comparable<U>,T extends Iterable<U>>
Comparator<T>lexComparator()
Retrieves a lexicographical comparator for the given type, which has to be anIterable
ofComparable
types.static <T extends Iterable<U>,U>
Comparator<T>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>>
intlexCompare(Iterable<? extends U> o1, Iterable<? extends U> o2)
Lexicographically compares twoIterable
s, whose element types are comparable.static <U> int
lexCompare(Iterable<? extends U> o1, Iterable<? extends U> o2, Comparator<? super U> elemComparator)
Lexicographically compares twoIterable
s.
-
-
-
Method Detail
-
canonicalCompare
public static <U> int canonicalCompare(List<? extends U> o1, List<? extends U> o2, Comparator<? super U> elemComparator)
Compares twoList
s with respect to canonical ordering.In canonical ordering, a sequence
o1
is less than a sequenceo2
ifo1
is shorter thano2
, or if they have the same length ando1
is lexicographically smaller thano2
.- 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 twoList
s ofComparable
elements with respect to canonical ordering.In canonical ordering, a sequence
o1
is less than a sequenceo2
ifo1
is shorter thano2
, or if they have the same length ando1
is lexicographically smaller thano2
.- 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 twoIterable
s. Comparison of the elements is done using the specified comparator.- Parameters:
o1
- the first iterable.o2
- the second iterable.elemComparator
- the comparator.- Returns:
< 0
iff o1 is lexicographically smaller,0
if o1 equals o2 and> 0
otherwise.
-
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 twoIterable
s, whose element types are comparable.
-
lexComparator
public static <T extends Iterable<U>,U> Comparator<T> lexComparator(Comparator<U> elemComp)
Retrieves a lexicographical comparator for the given type.- Parameters:
elemComp
- the comparator to use for comparing the elements.- Returns:
- a comparator for comparing objects of type
T
based on lexicographical ordering.
-
lexComparator
public static <U extends Comparable<U>,T extends Iterable<U>> Comparator<T> lexComparator()
Retrieves a lexicographical comparator for the given type, which has to be anIterable
ofComparable
types.- 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.- Parameters:
elemComp
- the comparator to use for comparing the elements.- Returns:
- a comparator for comparing objects of type
T
based on canonical ordering.
-
canonicalComparator
public static <T extends List<U>,U extends Comparable<U>> Comparator<T> canonicalComparator()
Retrieves a canonical comparator for the given type, which has to be aList
ofComparable
types.- Returns:
- the canonical comparator
- See Also:
canonicalCompare(List, List)
-
-