Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(2161)

Unified Diff: icu4j/main/classes/core/src/com/ibm/icu/impl/number/rounders/IncrementRounder.java

Issue 315420043: DecimalFormat rewrite, Java Base URL: svn+icussh://source.icu-project.org/repos/icu/branches/shane/numberformat/
Patch Set: r39857: Last commit before merge to trunk. Created 7 years ago
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: icu4j/main/classes/core/src/com/ibm/icu/impl/number/rounders/IncrementRounder.java
===================================================================
--- icu4j/main/classes/core/src/com/ibm/icu/impl/number/rounders/IncrementRounder.java (revision 0)
+++ icu4j/main/classes/core/src/com/ibm/icu/impl/number/rounders/IncrementRounder.java (revision 39857)
@@ -0,0 +1,67 @@
+// © 2017 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html#License
+package com.ibm.icu.impl.number.rounders;
+
+import java.math.BigDecimal;
+
+import com.ibm.icu.impl.number.FormatQuantity;
+import com.ibm.icu.impl.number.Properties;
+import com.ibm.icu.impl.number.Rounder;
+
+public class IncrementRounder extends Rounder {
+
+ public static interface IProperties extends IBasicRoundingProperties {
+
+ static BigDecimal DEFAULT_ROUNDING_INCREMENT = null;
+
+ /** @see #setRoundingIncrement */
+ public BigDecimal getRoundingIncrement();
+
+ /**
+ * Sets the increment to which to round numbers. For example, with a rounding interval of 0.05,
+ * the number 11.17 would be formatted as "11.15" in locale <em>en-US</em> with the default
+ * rounding mode.
+ *
+ * <p>You can use either a rounding increment or significant digits, but not both at the same
+ * time.
+ *
+ * <p>The rounding increment can be specified in a pattern string. For example, the pattern
+ * "#,##0.05" corresponds to a rounding interval of 0.05 with 1 minimum integer digit and a
+ * grouping size of 3.
+ *
+ * @param roundingIncrement The interval to which to round.
+ * @return The property bag, for chaining.
+ */
+ public IProperties setRoundingIncrement(BigDecimal roundingIncrement);
+ }
+
+ public static boolean useRoundingIncrement(IProperties properties) {
+ return properties.getRoundingIncrement() != IProperties.DEFAULT_ROUNDING_INCREMENT;
+ }
+
+ private final BigDecimal roundingIncrement;
+
+ public static IncrementRounder getInstance(IProperties properties) {
+ return new IncrementRounder(properties);
+ }
+
+ private IncrementRounder(IProperties properties) {
+ super(properties);
+ if (properties.getRoundingIncrement().compareTo(BigDecimal.ZERO) <= 0) {
+ throw new IllegalArgumentException("Rounding interval must be greater than zero");
+ }
+ roundingIncrement = properties.getRoundingIncrement();
+ }
+
+ @Override
+ public void apply(FormatQuantity input) {
+ input.roundToIncrement(roundingIncrement, mathContext);
+ applyDefaults(input);
+ }
+
+ @Override
+ public void export(Properties properties) {
+ super.export(properties);
+ properties.setRoundingIncrement(roundingIncrement);
+ }
+}
Property changes on: icu4j/main/classes/core/src/com/ibm/icu/impl/number/rounders/IncrementRounder.java
___________________________________________________________________
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:mime-type
## -0,0 +1 ##
+text/plain;charset=utf-8
\ No newline at end of property

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b