edu.stanford.nlp.util
Class Comparators

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

public class Comparators
extends java.lang.Object


Constructor Summary
Comparators()
           
 
Method Summary
static
<T> java.util.Comparator<T>
chain(java.util.Comparator<T>... c)
           
static
<T> java.util.Comparator<T>
chain(java.util.Comparator<T> c1, java.util.Comparator<T> c2)
          Returns a new Comparator which is the result of chaining the given Comparators.
static
<T> java.util.Comparator<T>
chain(java.util.List<java.util.Comparator<T>> c)
          Returns a new Comparator which is the result of chaining the given Comparators.
static
<T extends java.lang.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> java.util.Comparator<T> chain(java.util.Comparator<T> c1,
                                                java.util.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> java.util.Comparator<T> chain(java.util.List<java.util.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> java.util.Comparator<T> chain(java.util.Comparator<T>... c)

nullSafeComparator

public static <T extends java.lang.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