harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From hinde...@apache.org
Subject svn commit: r953307 - in /harmony/enhanced/java/branches/java6/classlib/modules/text/src: main/java/java/text/DecimalFormat.java test/java/org/apache/harmony/text/tests/java/text/DecimalFormatTest.java
Date Thu, 10 Jun 2010 12:36:07 GMT
Author: hindessm
Date: Thu Jun 10 12:36:07 2010
New Revision: 953307

URL: http://svn.apache.org/viewvc?rev=953307&view=rev
Log:
Apply java6 patch from "#HARMONY-6485] [classlib][text] DecimalFormat
applyPattern error".

Modified:
    harmony/enhanced/java/branches/java6/classlib/modules/text/src/main/java/java/text/DecimalFormat.java
    harmony/enhanced/java/branches/java6/classlib/modules/text/src/test/java/org/apache/harmony/text/tests/java/text/DecimalFormatTest.java

Modified: harmony/enhanced/java/branches/java6/classlib/modules/text/src/main/java/java/text/DecimalFormat.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/java/branches/java6/classlib/modules/text/src/main/java/java/text/DecimalFormat.java?rev=953307&r1=953306&r2=953307&view=diff
==============================================================================
--- harmony/enhanced/java/branches/java6/classlib/modules/text/src/main/java/java/text/DecimalFormat.java
(original)
+++ harmony/enhanced/java/branches/java6/classlib/modules/text/src/main/java/java/text/DecimalFormat.java
Thu Jun 10 12:36:07 2010
@@ -640,6 +640,13 @@ public class DecimalFormat extends Numbe
      */
     public void applyLocalizedPattern(String pattern) {
         dform.applyLocalizedPattern(pattern);
+        super.setMaximumFractionDigits(dform.getMaximumFractionDigits());
+        super.setMaximumIntegerDigits(dform.getMaximumIntegerDigits());
+        super.setMinimumFractionDigits(dform.getMinimumFractionDigits());
+        super.setMinimumIntegerDigits(dform.getMinimumIntegerDigits());
+        if (roundingMode != RoundingMode.HALF_EVEN) {
+            setRoundingIncrement(getMaximumFractionDigits());
+        }
     }
 
     /**
@@ -654,6 +661,13 @@ public class DecimalFormat extends Numbe
     public void applyPattern(String pattern) {
 
         dform.applyPattern(pattern);
+        super.setMaximumFractionDigits(dform.getMaximumFractionDigits());
+        super.setMaximumIntegerDigits(dform.getMaximumIntegerDigits());
+        super.setMinimumFractionDigits(dform.getMinimumFractionDigits());
+        super.setMinimumIntegerDigits(dform.getMinimumIntegerDigits());
+        if (roundingMode != RoundingMode.HALF_EVEN) {
+            setRoundingIncrement(getMaximumFractionDigits());
+        }
     }
 
     /**

Modified: harmony/enhanced/java/branches/java6/classlib/modules/text/src/test/java/org/apache/harmony/text/tests/java/text/DecimalFormatTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/java/branches/java6/classlib/modules/text/src/test/java/org/apache/harmony/text/tests/java/text/DecimalFormatTest.java?rev=953307&r1=953306&r2=953307&view=diff
==============================================================================
--- harmony/enhanced/java/branches/java6/classlib/modules/text/src/test/java/org/apache/harmony/text/tests/java/text/DecimalFormatTest.java
(original)
+++ harmony/enhanced/java/branches/java6/classlib/modules/text/src/test/java/org/apache/harmony/text/tests/java/text/DecimalFormatTest.java
Thu Jun 10 12:36:07 2010
@@ -752,6 +752,16 @@ public class DecimalFormatTest extends T
         assertEquals("Wrong pattern 3", "#", format.toPattern());
         format = new DecimalFormat(".#");
         assertEquals("Wrong pattern 4", "#.0", format.toPattern());
+        // Regression for HARMONY-6485
+        format = new DecimalFormat();
+        format.setMinimumIntegerDigits(0);
+        format.setMinimumFractionDigits(0);
+        format.setMaximumFractionDigits(0);
+        format.applyPattern("00.0#");
+        assertEquals("Minimum integer digits not set", 2, format.getMinimumIntegerDigits());
+        assertEquals("Minimum fraction digits not set", 1, format.getMinimumFractionDigits());
+        assertEquals("Maximum fraction digits not set", 2, format.getMaximumFractionDigits());
+
     }
 
     /**
@@ -2063,5 +2073,112 @@ public class DecimalFormatTest extends T
 				"Incorrect RoundingMode behavior: RoundingMode.UNNECESSARY",
 				"-1", result);
 
+		// Regression for HARMONY-6485
+		// Test with applyPattern call after setRoundingMode
+
+		// set RoundingMode.HALF_UP of this DecimalFormat and test its
+		// behavior
+		decimalFormat.setRoundingMode(RoundingMode.HALF_UP);
+		decimalFormat.applyPattern(".##");
+		result = decimalFormat.format(0.125);
+		assertEquals(
+			"Incorrect RoundingMode behavior after applyPattern",
+			".13", result);
+		result = decimalFormat.format(0.255);
+		assertEquals(
+			"Incorrect RoundingMode behavior after applyPattern",
+			".26", result);
+		result = decimalFormat.format(0.732);
+		assertEquals(
+			"Incorrect RoundingMode behavior after applyPattern",
+			".73", result);
+		result = decimalFormat.format(0.467);
+		assertEquals(
+			"Incorrect RoundingMode behavior after applyPattern",
+			".47", result);
+
+		// set RoundingMode.HALF_DOWN of this DecimalFormat and test its
+		// behavior
+		decimalFormat.setRoundingMode(RoundingMode.HALF_DOWN);
+		decimalFormat.applyPattern(".##");
+		result = decimalFormat.format(0.125);
+		assertEquals(
+			"Incorrect RoundingMode behavior after applyPattern",
+			".12", result);
+		result = decimalFormat.format(0.255);
+		assertEquals(
+			"Incorrect RoundingMode behavior after applyPattern",
+			".25", result);
+		result = decimalFormat.format(0.732);
+		assertEquals(
+			"Incorrect RoundingMode behavior after applyPattern",
+			".73", result);
+		result = decimalFormat.format(0.467);
+		assertEquals(
+			"Incorrect RoundingMode behavior after applyPattern",
+			".47", result);
+
+		// set RoundingMode.UP of this DecimalFormat and test its
+		// behavior
+		decimalFormat.setRoundingMode(RoundingMode.UP);
+		decimalFormat.applyPattern(".##");
+		result = decimalFormat.format(0.125);
+		assertEquals(
+			"Incorrect RoundingMode behavior after applyPattern",
+			".13", result);
+		result = decimalFormat.format(0.255);
+		assertEquals(
+			"Incorrect RoundingMode behavior after applyPattern",
+			".26", result);
+		result = decimalFormat.format(0.732);
+		assertEquals(
+			"Incorrect RoundingMode behavior after applyPattern",
+			".74", result);
+		result = decimalFormat.format(0.467);
+		assertEquals(
+			"Incorrect RoundingMode behavior after applyPattern",
+			".47", result);
+
+		// set RoundingMode.DOWN of this DecimalFormat and test its
+		// behavior
+		decimalFormat.setRoundingMode(RoundingMode.DOWN);
+		decimalFormat.applyPattern(".##");
+		result = decimalFormat.format(0.125);
+		assertEquals(
+			"Incorrect RoundingMode behavior after applyPattern",
+			".12", result);
+		result = decimalFormat.format(0.255);
+		assertEquals(
+			"Incorrect RoundingMode behavior after applyPattern",
+			".25", result);
+		result = decimalFormat.format(0.732);
+		assertEquals(
+			"Incorrect RoundingMode behavior after applyPattern",
+			".73", result);
+		result = decimalFormat.format(0.467);
+		assertEquals(
+			"Incorrect RoundingMode behavior after applyPattern",
+			".46", result);
+
+		// set RoundingMode.HALF_EVEN of this DecimalFormat and test its
+		// behavior
+		decimalFormat.setRoundingMode(RoundingMode.HALF_EVEN);
+		decimalFormat.applyPattern(".##");
+		result = decimalFormat.format(0.125);
+		assertEquals(
+			"Incorrect RoundingMode behavior after applyPattern",
+			".12", result);
+		result = decimalFormat.format(0.255);
+		assertEquals(
+			"Incorrect RoundingMode behavior after applyPattern",
+			".26", result);
+		result = decimalFormat.format(0.732);
+		assertEquals(
+			"Incorrect RoundingMode behavior after applyPattern",
+			".73", result);
+		result = decimalFormat.format(0.467);
+		assertEquals(
+			"Incorrect RoundingMode behavior after applyPattern",
+			".47", result);
 	}
 }



Mime
View raw message