ICU-2060 add Calendar.isEquivalentTo() method

X-SVN-Rev: 9753
This commit is contained in:
Alan Liu 2002-08-21 18:39:56 +00:00
parent 9cca604533
commit 675de700da
2 changed files with 30 additions and 15 deletions

View file

@ -620,7 +620,7 @@ import java.util.ResourceBundle;
* @see GregorianCalendar
* @see TimeZone
* @see DateFormat
* @version $Revision: 1.29 $ $Date: 2002/08/08 01:45:21 $
* @version $Revision: 1.30 $ $Date: 2002/08/21 18:39:56 $
* @author Mark Davis, David Goldsmith, Chen-Lieh Huang, Alan Liu, Laura Werner
* @since JDK1.1
*/
@ -1685,12 +1685,26 @@ public abstract class Calendar implements Serializable, Cloneable {
Calendar that = (Calendar) obj;
return
getTimeInMillis() == that.getTime().getTime() &&
isLenient() == that.isLenient() &&
getFirstDayOfWeek() == that.getFirstDayOfWeek() &&
getMinimalDaysInFirstWeek() == that.getMinimalDaysInFirstWeek() &&
getTimeZone().equals(that.getTimeZone());
return isEquivalentTo(that) &&
getTimeInMillis() == that.getTime().getTime();
}
/**
* Returns true if the given Calendar object is equivalent to this
* one. An equivalent Calendar will behave exactly as this one
* does, but it may be set to a different time. By contrast, for
* the equals() method to return true, the other Calendar must
* be set to the same time.
*
* @param other the Calendar to be compared with this Calendar
* @since ICU 2.4
*/
public boolean isEquivalentTo(Calendar other) {
return this.getClass() == other.getClass() &&
isLenient() == other.isLenient() &&
getFirstDayOfWeek() == other.getFirstDayOfWeek() &&
getMinimalDaysInFirstWeek() == other.getMinimalDaysInFirstWeek() &&
getTimeZone().equals(other.getTimeZone());
}
/**

View file

@ -480,16 +480,17 @@ public class GregorianCalendar extends Calendar {
}
/**
* Compares this GregorianCalendar to an object reference.
* @param obj the object reference with which to compare
* @return true if this object is equal to <code>obj</code>; false otherwise
* Returns true if the given Calendar object is equivalent to this
* one. Calendar override.
*
* @param other the Calendar to be compared with this Calendar
* @since ICU 2.4
*/
public boolean equals(Object obj) {
return super.equals(obj) &&
// Calendar.equals() ensures obj instanceof GregorianCalendar
gregorianCutover == ((GregorianCalendar)obj).gregorianCutover;
public boolean isEquivalentTo(Calendar other) {
return super.isEquivalentTo(other) &&
gregorianCutover == ((GregorianCalendar)other).gregorianCutover;
}
/**
* Override hashCode.
* Generates the hash code for the GregorianCalendar object