edu.stanford.nlp.util
Class Comparators
java.lang.Object
edu.stanford.nlp.util.Comparators
public class Comparators
- extends Object
Method Summary |
static
|
chain(Comparator<T>... c)
|
static
|
chain(Comparator<T> c1,
Comparator<T> c2)
Returns a new Comparator which is the result of chaining the
given Comparator s. |
static
|
chain(List<Comparator<T>> c)
Returns a new Comparator which is the result of chaining the
given Comparator s. |
static
|
nullSafeComparator(T one,
T two)
Returns a consistent ordering over two elements even if one of them is null
(as long as compareTo() is stable, of course). |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Comparators
public Comparators()
chain
public static <T> Comparator<T> chain(Comparator<T> c1,
Comparator<T> c2)
- Returns a new
Comparator
which is the result of chaining the
given Comparator
s. If the first Comparator
considers two objects unequal, its result is returned; otherwise, the
result of the second Comparator
is returned. Facilitates
sorting on primary and secondary keys.
chain
public static <T> Comparator<T> chain(List<Comparator<T>> c)
- Returns a new
Comparator
which is the result of chaining the
given Comparator
s. Facilitates sorting on multiple keys.
chain
public static <T> Comparator<T> chain(Comparator<T>... c)
nullSafeComparator
public static <T extends Comparable<? super T>> int nullSafeComparator(T one,
T two)
- Returns a consistent ordering over two elements even if one of them is null
(as long as compareTo() is stable, of course).
Adapted from http://stackoverflow.com/a/481836
Stanford NLP Group