edu.stanford.nlp.util
Class Comparators

java.lang.Object
  extended by edu.stanford.nlp.util.Comparators

public class Comparators
extends Object


Constructor Summary
Comparators()
           
 
Method Summary
static
<T> Comparator<T>
chain(Comparator<T>... c)
           
static
<T> Comparator<T>
chain(Comparator<T> c1, Comparator<T> c2)
          Returns a new Comparator which is the result of chaining the given Comparators.
static
<T> Comparator<T>
chain(List<Comparator<T>> c)
          Returns a new Comparator which is the result of chaining the given Comparators.
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).
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Comparators

public Comparators()
Method Detail

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 Comparators. 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 Comparators. 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