Joda Time API

org.joda.time
Class DateTimeComparator

java.lang.Object
  |
  +--org.joda.time.DateTimeComparator
All Implemented Interfaces:
java.util.Comparator

public class DateTimeComparator
extends java.lang.Object
implements java.util.Comparator

DateTimeComparator is the standard implementation of the Comparator interface for various Joda and Java objects. The following types are supported for comparison:

Since:
1.0
Author:
Guy Allard, Stephen Colebourne, Brian S O'Neill

Method Summary
 int compare(java.lang.Object lhsObj, java.lang.Object rhsObj)
          Compare two objects against only the range of date time fields as specified in the constructor.
static DateTimeComparator getDateOnlyInstance(Chronology chrono)
          Returns a comparator that only considers date fields.
static DateTimeComparator getInstance()
          Returns a DateTimeComparator the compares the entire date time value.
static DateTimeComparator getInstance(DateTimeField lowerLimit)
          Returns a DateTimeComparator with a lower limit only.
static DateTimeComparator getInstance(DateTimeField lowerLimit, DateTimeField upperLimit)
          Returns a DateTimeComparator with a lower and upper limit.
static DateTimeComparator getTimeOnlyInstance(Chronology chrono)
          Returns a comparator that only considers time fields.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface java.util.Comparator
equals
 

Method Detail

getInstance

public static DateTimeComparator getInstance()
Returns a DateTimeComparator the compares the entire date time value.


getInstance

public static DateTimeComparator getInstance(DateTimeField lowerLimit)
Returns a DateTimeComparator with a lower limit only. Fields of a magnitude less than the lower limit are excluded from comparisons.

Parameters:
lowerLimit - inclusive lower limit for fields to be compared

getInstance

public static DateTimeComparator getInstance(DateTimeField lowerLimit,
                                             DateTimeField upperLimit)
Returns a DateTimeComparator with a lower and upper limit. Fields of a magnitude less than the lower limit are excluded from comparisons. Fields of a magnitude greater than or equal to the upper limit are also excluded from comparisons. Either limit may be specified as null, which indicates an unbounded limit.

Parameters:
lowerLimit - optional, inclusive lower limit for fields to be compared
upperLimit - optional, exclusive upper limit for fields to be compared

getDateOnlyInstance

public static DateTimeComparator getDateOnlyInstance(Chronology chrono)
Returns a comparator that only considers date fields. Time of day is ignored.


getTimeOnlyInstance

public static DateTimeComparator getTimeOnlyInstance(Chronology chrono)
Returns a comparator that only considers time fields. Date is ignored.


compare

public int compare(java.lang.Object lhsObj,
                   java.lang.Object rhsObj)
Compare two objects against only the range of date time fields as specified in the constructor.

Specified by:
compare in interface java.util.Comparator
Parameters:
lhsObj - The first object, logically on the left of a < comparison
rhsObj - The second object, logically on the right of a < comparison
Returns:
0 if order does not matter, -1 if lhsObj < rhsObj, 1 otherwise.
Throws:
java.lang.IllegalArgumentException - if either argument is null
java.lang.ClassCastException - if either argument is one of the support types

Joda Time API

Copyright © 2001-2003 Stephen Colebourne. All Rights Reserved.