[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[cp-patches] Patch: FYI: PR 23890
From: |
Tom Tromey |
Subject: |
[cp-patches] Patch: FYI: PR 23890 |
Date: |
01 Oct 2005 13:37:06 -0600 |
User-agent: |
Gnus/5.09 (Gnus v5.9.0) Emacs/21.3.50 |
I'm checking this in.
This fixes PR 23890. Neither Calendar.equals nor
GregorianCalendar.equals were doing the correct checks (the 1.5
javadoc is more complete here...).
Tom
2005-10-01 Tom Tromey <address@hidden>
PR classpath/23890:
* java/util/Calendar.java (equals): Include other calendar
attributes.
(hashCode): Updated.
* java/util/GregorianCalendar.java (hashCode): New method.
(equals): Use super.equals().
Index: java/util/Calendar.java
===================================================================
RCS file: /cvsroot/classpath/classpath/java/util/Calendar.java,v
retrieving revision 1.46
diff -u -r1.46 Calendar.java
--- java/util/Calendar.java 5 Jul 2005 10:28:03 -0000 1.46
+++ java/util/Calendar.java 1 Oct 2005 19:37:31 -0000
@@ -914,8 +914,19 @@
*/
public boolean equals(Object o)
{
- return (o instanceof Calendar)
- && getTimeInMillis() == ((Calendar) o).getTimeInMillis();
+ if (! (o instanceof Calendar))
+ return false;
+ Calendar cal = (Calendar) o;
+ if (getTimeInMillis() == ((Calendar) o).getTimeInMillis()
+ && cal.getFirstDayOfWeek() == getFirstDayOfWeek()
+ && cal.isLenient() == isLenient()
+ && cal.getMinimalDaysInFirstWeek() == getMinimalDaysInFirstWeek())
+ {
+ TimeZone self = getTimeZone();
+ TimeZone oth = cal.getTimeZone();
+ return self == null ? oth == null : self.equals(oth);
+ }
+ return false;
}
/**
@@ -926,7 +937,13 @@
public int hashCode()
{
long time = getTimeInMillis();
- return (int) ((time & 0xffffffffL) ^ (time >> 32));
+ int val = (int) ((time & 0xffffffffL) ^ (time >> 32));
+ val += (getFirstDayOfWeek() + (isLenient() ? 1230 : 1237)
+ + getMinimalDaysInFirstWeek());
+ TimeZone self = getTimeZone();
+ if (self != null)
+ val ^= self.hashCode();
+ return val;
}
/**
Index: java/util/GregorianCalendar.java
===================================================================
RCS file: /cvsroot/classpath/classpath/java/util/GregorianCalendar.java,v
retrieving revision 1.42
diff -u -r1.42 GregorianCalendar.java
--- java/util/GregorianCalendar.java 2 Jul 2005 20:32:42 -0000 1.42
+++ java/util/GregorianCalendar.java 1 Oct 2005 19:37:31 -0000
@@ -868,6 +868,17 @@
areFieldsSet = isSet[ERA] = isSet[YEAR] = isSet[MONTH] =
isSet[WEEK_OF_YEAR] = isSet[WEEK_OF_MONTH] = isSet[DAY_OF_MONTH] =
isSet[DAY_OF_YEAR] = isSet[DAY_OF_WEEK] = isSet[DAY_OF_WEEK_IN_MONTH] =
isSet[AM_PM] = isSet[HOUR] = isSet[HOUR_OF_DAY] = isSet[MINUTE] = isSet[SECOND]
= isSet[MILLISECOND] = isSet[ZONE_OFFSET] = isSet[DST_OFFSET] = true;
}
+
+ /**
+ * Return a hash code for this object, following the general contract
+ * specified by address@hidden Object#hashCode()}.
+ * @return the hash code
+ */
+ public int hashCode()
+ {
+ int val = (int) ((gregorianCutover >>> 32) ^ (gregorianCutover &
0xffffffff));
+ return super.hashCode() ^ val;
+ }
/**
* Compares the given calendar with this. An object, o, is
@@ -890,7 +901,8 @@
return false;
GregorianCalendar cal = (GregorianCalendar) o;
- return (cal.getTimeInMillis() == getTimeInMillis());
+ return (cal.gregorianCutover == gregorianCutover
+ && super.equals(o));
}
/**
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [cp-patches] Patch: FYI: PR 23890,
Tom Tromey <=