jaggregate
Class Comparing

java.lang.Object
  extended by jaggregate.Comparing

public class Comparing
extends Object

Utility class that offers common comparators.

Version:
$Id: Comparing.java,v 1.5 2008/10/03 19:01:23 pholser Exp $
Author:
Paul Holser

Method Summary
static
<T extends Comparable<? super T>>
Comparator<T>
byNaturalOrdering()
          Answers a comparator that compares its two Comparable arguments according to their natural ordering; that is, by how they answer compareTo.
static
<T> Comparator<T>
nullSafe(Comparator<T> comparator)
          Answers a comparator that defends against null actual arguments to its wrapped comparator's compare method.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

nullSafe

public static <T> Comparator<T> nullSafe(Comparator<T> comparator)
Answers a comparator that defends against null actual arguments to its wrapped comparator's compare method.

A null value compares "less than" a non-null value.

Type Parameters:
T - the type of elements to be compared
Parameters:
comparator - the comparator to wrap
Returns:
the wrapped comparator
Throws:
NullPointerException - if comparator is null

byNaturalOrdering

public static <T extends Comparable<? super T>> Comparator<T> byNaturalOrdering()
Answers a comparator that compares its two Comparable arguments according to their natural ordering; that is, by how they answer compareTo. The comparator is "null safe".

Type Parameters:
T - the type of elements to be compared
Returns:
a comparator of comparables that answers based on the arguments' natural ordering
See Also:
nullSafe(Comparator)


© Copyright 2004-2008 Paul R. Holser, Jr. All rights reserved. Licensed under the Academic Free License version 3.0. pholser@alumni.rice.edu