Copyright © 2011 Citra Technologies. All Rights Reserved.

com.citra.comparators
Class DateComparator

java.lang.Object
  extended by com.citra.comparators.DateComparator
All Implemented Interfaces:
Serializable, Comparator

public class DateComparator
extends Object
implements Comparator, Serializable

This class is used to compare two Date objects.

DateComparator makes use of two calendar objects for the comparisons, each initialized to the Date objects being compared.

See Also:
Serialized Form

Field Summary
protected  Calendar calendar1
          a calendar object that is used in the compare method
protected  Calendar calendar2
          a calendar object that is used in the compare method
protected  boolean ignoreTime
          flag to indicate if the date comparator will ignore time differences
 
Constructor Summary
DateComparator()
          Constructs a DateComparator object that will ignore time differences.
DateComparator(boolean ignoreTime)
          Constructs a DateComparator object that will ignore time differences if ignoreTime is true.
 
Method Summary
 int compare(Object o1, Object o2)
          Compares its two arguments for order as defined by compare of the Comparator interface.
 boolean getIgnoreTime()
          Returns a boolean which is true if the date comparator is set to ignore time differences.
 void setIgnoreTime(boolean ignoreTime)
          Set whether time differences are to be ignored or not.
 
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
 

Field Detail

ignoreTime

protected boolean ignoreTime
flag to indicate if the date comparator will ignore time differences


calendar1

protected Calendar calendar1
a calendar object that is used in the compare method


calendar2

protected Calendar calendar2
a calendar object that is used in the compare method

Constructor Detail

DateComparator

public DateComparator()
Constructs a DateComparator object that will ignore time differences.


DateComparator

public DateComparator(boolean ignoreTime)
Constructs a DateComparator object that will ignore time differences if ignoreTime is true.

Method Detail

compare

public int compare(Object o1,
                   Object o2)
Compares its two arguments for order as defined by compare of the Comparator interface. o1 and o2 must be Date objects, otherwise this method throws a ClassCastException.

If the ignoreTime flag is false, this method will compare only the year, month and date fields of the date objects supplied.

Specified by:
compare in interface Comparator
Parameters:
o1 - the first object to be compared.
o2 - the second object to be compared.
Returns:
a negative integer, zero, or a positive integer as o1 is less than, equal to, or greater than o2 accordingly.

getIgnoreTime

public boolean getIgnoreTime()
Returns a boolean which is true if the date comparator is set to ignore time differences.

Returns:
the ignore time flag

setIgnoreTime

public void setIgnoreTime(boolean ignoreTime)
Set whether time differences are to be ignored or not.

Parameters:
ignoreTime - the ignore time flag

Copyright © 2011 Citra Technologies. All Rights Reserved.