5252 * DecimalFormat is that DigitList handles the radix 10 representation
5353 * issues; DecimalFormat handles the locale-specific issues such as
5454 * positive/negative, grouping, decimal point, currency, and so on.
55- *
55+ * <p>
5656 * A DigitList is really a representation of a floating point value.
5757 * It may be an integer value; we assume that a double has sufficient
5858 * precision to represent all digits of a long.
59- *
59+ * <p>
6060 * The DigitList representation consists of a string of characters,
6161 * which are the digits radix 10, from '0' to '9'. It also has a radix
6262 * 10 exponent associated with it. The value represented by a DigitList
@@ -82,22 +82,22 @@ final class DigitList implements Cloneable {
8282
8383 /**
8484 * These data members are intentionally public and can be set directly.
85- *
85+ * <p>
8686 * The value represented is given by placing the decimal point before
8787 * digits[decimalAt]. If decimalAt is < 0, then leading zeros between
8888 * the decimal point and the first nonzero digit are implied. If decimalAt
8989 * is > count, then trailing zeros between the digits[count-1] and the
9090 * decimal point are implied.
91- *
91+ * <p>
9292 * Equivalently, the represented value is given by f * 10^decimalAt. Here
9393 * f is a value 0.1 <= f < 1 arrived at by placing the digits in Digits to
9494 * the right of the decimal.
95- *
95+ * <p>
9696 * DigitList is normalized, so if it is non-zero, digits[0] is non-zero. We
9797 * don't allow denormalized numbers because our exponent is effectively of
9898 * unlimited magnitude. The count value contains the number of significant
9999 * digits present in digits[].
100- *
100+ * <p>
101101 * Zero is represented by any DigitList with count == 0 or with each digits[i]
102102 * for all i <= count == '0'.
103103 */
@@ -166,7 +166,7 @@ public void append(char digit) {
166166 * If (count == 0) this returns 0.0,
167167 * unlike Double.parseDouble("") which throws NumberFormatException.
168168 */
169- public final double getDouble () {
169+ public double getDouble () {
170170 if (count == 0 ) {
171171 return 0.0 ;
172172 }
@@ -178,7 +178,7 @@ public final double getDouble() {
178178 * If (count == 0) this returns 0,
179179 * unlike Long.parseLong("") which throws NumberFormatException.
180180 */
181- public final long getLong () {
181+ public long getLong () {
182182 // for now, simple implementation; later, do proper IEEE native stuff
183183
184184 if (count == 0 ) {
@@ -208,7 +208,7 @@ public final long getLong() {
208208 * If (count == 0) this does not throw a NumberFormatException,
209209 * unlike BigDecimal("").
210210 */
211- public final BigDecimal getBigDecimal () {
211+ public BigDecimal getBigDecimal () {
212212 if (count == 0 ) {
213213 return BigDecimal .valueOf (0 , -decimalAt );
214214 }
@@ -280,10 +280,26 @@ boolean fitsIntoLong(boolean isPositive, boolean ignoreNegativeZero) {
280280 * @param maximumFractionDigits The most fractional digits which should
281281 * be converted.
282282 */
283- final void set (boolean isNegative , double source , int maximumFractionDigits ) {
283+ void set (boolean isNegative , double source , int maximumFractionDigits ) {
284284 set (isNegative , source , maximumFractionDigits , true );
285285 }
286286
287+ /*
288+ * This compatibility option will only be available for a *very* limited
289+ * number of releases.
290+ * It restores the original behavior to help migrating to the new one,
291+ * and is used by adding
292+ * -Djdk.compat.DecimalFormat=true
293+ * to the launcher's command line.
294+ *
295+ * The new behavior differs from the old one only in very rare cases,
296+ * so migration should be painless.
297+ *
298+ * When this option is removed, the old behavior, including relevant
299+ * fields and methods, will be removed as well.
300+ */
301+ private static final boolean COMPAT = Boolean .getBoolean ("jdk.compat.DecimalFormat" );
302+
287303 /**
288304 * Set the digit list to a representation of the given double value.
289305 * This method supports both fixed-point and exponential notation.
@@ -295,9 +311,9 @@ final void set(boolean isNegative, double source, int maximumFractionDigits) {
295311 * @param fixedPoint If true, then maximumDigits is the maximum
296312 * fractional digits to be converted. If false, total digits.
297313 */
298- final void set (boolean isNegative , double source , int maximumDigits , boolean fixedPoint ) {
299-
300- FloatingDecimal . BinaryToASCIIConverter fdConverter = FloatingDecimal .getBinaryToASCIIConverter (source );
314+ void set (boolean isNegative , double source , int maximumDigits , boolean fixedPoint ) {
315+ FloatingDecimal . BinaryToASCIIConverter fdConverter =
316+ FloatingDecimal .getBinaryToASCIIConverter (source , COMPAT );
301317 boolean hasBeenRoundedUp = fdConverter .digitsRoundedUp ();
302318 boolean valueExactAsDecimal = fdConverter .decimalDigitsExact ();
303319 assert !fdConverter .isExceptional ();
@@ -415,7 +431,7 @@ private void roundInt(int maximumDigits) {
415431 *
416432 * Upon return, count will be less than or equal to maximumDigits.
417433 */
418- private final void round (int maximumDigits ,
434+ private void round (int maximumDigits ,
419435 boolean alreadyRounded ,
420436 boolean valueExactAsDecimal ) {
421437 // Eliminate digits beyond maximum digits to be displayed.
@@ -582,7 +598,7 @@ private int roundUp(int maximumDigits) {
582598 /**
583599 * Utility routine to set the value of the digit list from a long
584600 */
585- final void set (boolean isNegative , long source ) {
601+ void set (boolean isNegative , long source ) {
586602 set (isNegative , source , 0 );
587603 }
588604
@@ -595,7 +611,7 @@ final void set(boolean isNegative, long source) {
595611 * If maximumDigits is lower than the number of significant digits
596612 * in source, the representation will be rounded. Ignored if <= 0.
597613 */
598- final void set (boolean isNegative , long source , int maximumDigits ) {
614+ void set (boolean isNegative , long source , int maximumDigits ) {
599615 this .isNegative = isNegative ;
600616
601617 // This method does not expect a negative number. However,
@@ -645,7 +661,7 @@ final void set(boolean isNegative, long source, int maximumDigits) {
645661 * @param fixedPoint If true, then maximumDigits is the maximum
646662 * fractional digits to be converted. If false, total digits.
647663 */
648- final void set (boolean isNegative , BigDecimal source , int maximumDigits , boolean fixedPoint ) {
664+ void set (boolean isNegative , BigDecimal source , int maximumDigits , boolean fixedPoint ) {
649665 String s = source .toString ();
650666 extendDigits (s .length ());
651667
@@ -662,7 +678,7 @@ final void set(boolean isNegative, BigDecimal source, int maximumDigits, boolean
662678 * If maximumDigits is lower than the number of significant digits
663679 * in source, the representation will be rounded. Ignored if <= 0.
664680 */
665- final void set (boolean isNegative , BigInteger source , int maximumDigits ) {
681+ void set (boolean isNegative , BigInteger source , int maximumDigits ) {
666682 this .isNegative = isNegative ;
667683 String s = source .toString ();
668684 int len = s .length ();
@@ -772,7 +788,7 @@ private void extendDigits(int len) {
772788 }
773789 }
774790
775- private final char [] getDataChars (int length ) {
791+ private char [] getDataChars (int length ) {
776792 if (data == null || data .length < length ) {
777793 data = new char [length ];
778794 }
0 commit comments