commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "C. Scott Ananian" <csc...@cscott.net>
Subject Re: [collections][lang] generic min/max functions
Date Tue, 01 Jun 2004 21:16:09 GMT
On Tue, 1 Jun 2004, Emmanuel Bourg wrote:

> Only if the dates are not null of course, otherwise it becomes something

How about Collections.min(Arrays.asList(new Date[] { date1, date2 })) ?

I'm not sure how Date.compareTo() reacts to null (it's not specified in
the javadoc), but if it reacts poorly, all you need is a
  public class NullNaturalComparator implements Comparator {
     public int compare(Object o1, Object o2) {
        if (o1==null) return (o2==null) ? 0 : -1;
        if (o2==null) return +1;
	return ((Comparable)o1).compareTo(o2);
     }
  }

 --scott

Marxist Shoal Bay Rijndael Pakistan NSA anthrax ammunition Sugar Grove
RUCKUS Hawk Suharto shortwave SSBN 743 Nader assassination politics
                         ( http://cscott.net/ )

---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


Mime
View raw message