src/share/classes/java/text/DecimalFormat.java

Print this page
rev 10195 : 8048267: Replace uses of 'new Long()' with appropriate alternative across core classes
Reviewed-by: chegar, psandoz
Contributed-by: otaviojava@java.net


2077                 longResult = -longResult;
2078             }
2079 
2080             // At this point, if we divided the result by the multiplier, the
2081             // result may fit into a long.  We check for this case and return
2082             // a long if possible.
2083             // We must do this AFTER applying the negative (if appropriate)
2084             // in order to handle the case of LONG_MIN; otherwise, if we do
2085             // this with a positive value -LONG_MIN, the double is > 0, but
2086             // the long is < 0. We also must retain a double in the case of
2087             // -0.0, which will compare as == to a long 0 cast to a double
2088             // (bug 4162852).
2089             if (multiplier != 1 && gotDouble) {
2090                 longResult = (long)doubleResult;
2091                 gotDouble = ((doubleResult != (double)longResult) ||
2092                             (doubleResult == 0.0 && 1/doubleResult < 0.0)) &&
2093                             !isParseIntegerOnly();
2094             }
2095 
2096             return gotDouble ?
2097                 (Number)new Double(doubleResult) : (Number)new Long(longResult);
2098         }
2099     }
2100 
2101     /**
2102      * Return a BigInteger multiplier.
2103      */
2104     private BigInteger getBigIntegerMultiplier() {
2105         if (bigIntegerMultiplier == null) {
2106             bigIntegerMultiplier = BigInteger.valueOf(multiplier);
2107         }
2108         return bigIntegerMultiplier;
2109     }
2110     private transient BigInteger bigIntegerMultiplier;
2111 
2112     /**
2113      * Return a BigDecimal multiplier.
2114      */
2115     private BigDecimal getBigDecimalMultiplier() {
2116         if (bigDecimalMultiplier == null) {
2117             bigDecimalMultiplier = new BigDecimal(multiplier);




2077                 longResult = -longResult;
2078             }
2079 
2080             // At this point, if we divided the result by the multiplier, the
2081             // result may fit into a long.  We check for this case and return
2082             // a long if possible.
2083             // We must do this AFTER applying the negative (if appropriate)
2084             // in order to handle the case of LONG_MIN; otherwise, if we do
2085             // this with a positive value -LONG_MIN, the double is > 0, but
2086             // the long is < 0. We also must retain a double in the case of
2087             // -0.0, which will compare as == to a long 0 cast to a double
2088             // (bug 4162852).
2089             if (multiplier != 1 && gotDouble) {
2090                 longResult = (long)doubleResult;
2091                 gotDouble = ((doubleResult != (double)longResult) ||
2092                             (doubleResult == 0.0 && 1/doubleResult < 0.0)) &&
2093                             !isParseIntegerOnly();
2094             }
2095 
2096             return gotDouble ?
2097                 (Number)new Double(doubleResult) : (Number)Long.valueOf(longResult);
2098         }
2099     }
2100 
2101     /**
2102      * Return a BigInteger multiplier.
2103      */
2104     private BigInteger getBigIntegerMultiplier() {
2105         if (bigIntegerMultiplier == null) {
2106             bigIntegerMultiplier = BigInteger.valueOf(multiplier);
2107         }
2108         return bigIntegerMultiplier;
2109     }
2110     private transient BigInteger bigIntegerMultiplier;
2111 
2112     /**
2113      * Return a BigDecimal multiplier.
2114      */
2115     private BigDecimal getBigDecimalMultiplier() {
2116         if (bigDecimalMultiplier == null) {
2117             bigDecimalMultiplier = new BigDecimal(multiplier);