classpath-patches
[Top][All Lists]
Advanced

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

[cp-patches] java.text.DecimalFormat fixes


From: David Gilbert
Subject: [cp-patches] java.text.DecimalFormat fixes
Date: Mon, 13 Jun 2005 19:09:32 +0000
User-agent: Mozilla Thunderbird 1.0.2 (X11/20050426)

I'd like to commit the following change to CVS (using my
newly-acquired-but-not-yet-tested commit rights!!):

2005-06-13  David Gilbert  <address@hidden>

        * java/text/DecimalFormat.java
        (DecimalFormat(String, DecimalFormatSymbols)): store clone of symbols;
        (equals): add missing checks;
        (getDecimalFormatSymbols): return clone of symbols;
        (setDecimalFormatSymbols): store clone of symbols.

This fixes 10 failing tests in Mauve.  I posted it to the patch manager
a while ago:

http://savannah.gnu.org/patch/?func=detailitem&item_id=3827

OK to commit?

Regards,

Dave Gilbert


Index: java/text/DecimalFormat.java
===================================================================
RCS file: /cvsroot/classpath/classpath/java/text/DecimalFormat.java,v
retrieving revision 1.22
diff -u -r1.22 DecimalFormat.java
--- java/text/DecimalFormat.java        2 May 2005 17:21:51 -0000       1.22
+++ java/text/DecimalFormat.java        13 Jun 2005 16:32:08 -0000
@@ -437,13 +437,9 @@
    * @throws NullPointerException if any argument is null.
    * @throws IllegalArgumentException if the pattern is invalid.
    */
-  public DecimalFormat (String pattern, DecimalFormatSymbols symbols)
+  public DecimalFormat(String pattern, DecimalFormatSymbols symbols)
   {
-    if (symbols == null)
-      {
-        throw new NullPointerException("Supplied set of symbols is null.");
-      }
-    this.symbols = symbols;
+    this.symbols = (DecimalFormatSymbols) symbols.clone();
     applyPattern(pattern);
   }

@@ -454,21 +450,39 @@
     return s1.equals(s2);
   }

-  public boolean equals (Object obj)
+  /**
+   * Tests this instance for equality with an arbitrary object.  This
method
+   * returns <code>true</code> if:
+   * <ul>
+   * <li><code>obj</code> is not <code>null</code>;</li>
+   * <li><code>obj</code> is an instance of
<code>DecimalFormat</code>;</li>
+   * <li>this instance and <code>obj</code> have the same attributes;</li>
+   * </ul>
+   *
+   * @param obj  the object (<code>null</code> permitted).
+   *
+   * @return A boolean.
+   */
+  public boolean equals(Object obj)
   {
-    if (! (obj instanceof DecimalFormat))
+    if (!(obj instanceof DecimalFormat))
       return false;
     DecimalFormat dup = (DecimalFormat) obj;
     return (decimalSeparatorAlwaysShown == dup.decimalSeparatorAlwaysShown
-           && groupingSize == dup.groupingSize
-           && minExponentDigits == dup.minExponentDigits
-           && multiplier == dup.multiplier
-           && equals(negativePrefix, dup.negativePrefix)
-           && equals(negativeSuffix, dup.negativeSuffix)
-           && equals(positivePrefix, dup.positivePrefix)
-           && equals(positiveSuffix, dup.positiveSuffix)
-           && symbols.equals(dup.symbols)
-           && useExponentialNotation == dup.useExponentialNotation);
+      && groupingUsed == dup.groupingUsed
+      && groupingSize == dup.groupingSize
+      && multiplier == dup.multiplier
+      && useExponentialNotation == dup.useExponentialNotation)
+      && minExponentDigits == dup.minExponentDigits
+      && minimumIntegerDigits == dup.minimumIntegerDigits
+      && maximumIntegerDigits == dup.maximumIntegerDigits
+      && minimumFractionDigits == dup.minimumFractionDigits
+      && maximumFractionDigits == dup.maximumFractionDigits
+      && equals(negativePrefix, dup.negativePrefix)
+      && equals(negativeSuffix, dup.negativeSuffix)
+      && equals(positivePrefix, dup.positivePrefix)
+      && equals(positiveSuffix, dup.positiveSuffix)
+      && symbols.equals(dup.symbols);
   }

   private void formatInternal (double number, FormatBuffer dest,
@@ -784,9 +798,14 @@
     return symbols.getCurrency();
   }

-  public DecimalFormatSymbols getDecimalFormatSymbols ()
+  /**
+   * Returns a copy of the symbols used by this instance.
+   *
+   * @return A copy of the symbols.
+   */
+  public DecimalFormatSymbols getDecimalFormatSymbols()
   {
-    return symbols;
+    return (DecimalFormatSymbols) symbols.clone();
   }

   public int getGroupingSize ()
@@ -1133,9 +1152,15 @@
     symbols.setCurrency(currency);
   }

-  public void setDecimalFormatSymbols (DecimalFormatSymbols newSymbols)
+  /**
+   * Sets the symbols used by this instance.  This method makes a copy of
+   * the supplied symbols.
+   *
+   * @param newSymbols  the symbols (<code>null</code> not permitted).
+   */
+  public void setDecimalFormatSymbols(DecimalFormatSymbols newSymbols)
   {
-    symbols = newSymbols;
+    symbols = (DecimalFormatSymbols) newSymbols.clone();
   }

   public void setDecimalSeparatorAlwaysShown (boolean newValue)





reply via email to

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