classpath-patches
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[cp-patches] DataFormat.equals() reimplemented


From: Mark Wielaard
Subject: [cp-patches] DataFormat.equals() reimplemented
Date: Tue, 26 Jul 2005 15:24:07 +0200

Hi,

This is a reimplementation of DateFormat.equals() following the JCL book
description. While testing this I found that David already created Mauve
tests for this which closely follow this description already.

2005-07-26  Mark Wielaard  <address@hidden>

        * java/text/DateFormat.java (equals): Reimplement.

This makes all DateFormat tests in Mauve pass except one. The failure is
when the mauve test sets the TimeZone of the Calendar of the DateFormat
object to a different TimeZone, but with the same rules. As explained in
the new documentation I believe this test is wrong. Or at least I don't
see why it would matter or a way to test for it. But I may be wrong.

David, do you have a comment/suggestion for this patch/test?

Cheers,

Mark
Index: java/text/DateFormat.java
===================================================================
RCS file: /cvsroot/classpath/classpath/java/text/DateFormat.java,v
retrieving revision 1.21
diff -u -r1.21 DateFormat.java
--- java/text/DateFormat.java   23 Jul 2005 20:25:15 -0000      1.21
+++ java/text/DateFormat.java   26 Jul 2005 13:20:35 -0000
@@ -405,8 +405,18 @@
    * <ul>
    * <li>Is not <code>null</code>.</li>
    * <li>Is an instance of <code>DateFormat</code>.</li>
-   * <li>Has the same numberFormat field value as this object.</li>
+   * <li>Has equal numberFormat field as this object.</li>
+   * <li>Has equal (Calendar) TimeZone rules as this object.</li>
+   * <li>Has equal (Calendar) isLenient results.</li> 
+   * <li>Has equal Calendar first day of week and minimal days in week
+   * values.</li>
    * </ul>
+   * Note that not all properties of the Calendar are relevant for a
+   * DateFormat. For formatting only the fact whether or not the
+   * TimeZone has the same rules and whether the calendar is lenient
+   * and has the same week rules is compared for this implementation
+   * of equals. Other properties of the Calendar (such as the time)
+   * are not taken into account.
    *
    * @param obj The object to test for equality against.
    * 
@@ -419,8 +429,24 @@
       return false;
 
     DateFormat d = (DateFormat) obj;
+    TimeZone tz = getTimeZone();
+    TimeZone tzd = d.getTimeZone();
+    if (tz.hasSameRules(tzd))
+      if (isLenient() == d.isLenient())
+       {
+         Calendar c = getCalendar();
+         Calendar cd = d.getCalendar();
+         if ((c == null && cd == null)
+             ||
+             (c.getFirstDayOfWeek() == cd.getFirstDayOfWeek()
+              &&
+              c.getMinimalDaysInFirstWeek()
+              == cd.getMinimalDaysInFirstWeek()))
+           return ((numberFormat == null && d.numberFormat == null)
+                   || numberFormat.equals(d.numberFormat));
+       }
 
-    return numberFormat.equals(d.numberFormat);
+    return false;
   }
 
   /**

Attachment: signature.asc
Description: This is a digitally signed message part


reply via email to

[Prev in Thread] Current Thread [Next in Thread]