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

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

Issue 335150043: Refreshing Number Parsing: ICU4J Base URL: svn+icussh://source.icu-project.org/repos/icu/trunk/
Patch Set: Replying to Andy feedback round one. See commit message. Created 6 years, 2 months 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/parse/MultiplierHandler.java
===================================================================
--- icu4j/main/classes/core/src/com/ibm/icu/impl/number/parse/MultiplierHandler.java (revision 0)
+++ icu4j/main/classes/core/src/com/ibm/icu/impl/number/parse/MultiplierHandler.java (revision 40782)
@@ -0,0 +1,39 @@
+// © 2017 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html#License
+package com.ibm.icu.impl.number.parse;
+
+import java.math.BigDecimal;
+import java.math.MathContext;
+
+/**
+ * @author sffc
+ *
+ */
+public class MultiplierHandler extends ValidationMatcher {
+
+ private final BigDecimal multiplier;
+ private final MathContext mc;
+ private final boolean isNegative;
+
+ public MultiplierHandler(BigDecimal multiplier, MathContext mc) {
+ this.multiplier = BigDecimal.ONE.divide(multiplier, mc).abs();
+ this.mc = mc;
+ isNegative = multiplier.signum() < 0;
+ }
+
+ @Override
+ public void postProcess(ParsedNumber result) {
+ if (result.quantity != null) {
+ result.quantity.multiplyBy(multiplier);
+ result.quantity.roundToMagnitude(result.quantity.getMagnitude() - mc.getPrecision(), mc);
+ if (isNegative) {
+ result.flags ^= ParsedNumber.FLAG_NEGATIVE;
+ }
+ }
+ }
+
+ @Override
+ public String toString() {
+ return "<MultiplierHandler " + multiplier + ">";
+ }
+}
Property changes on: icu4j/main/classes/core/src/com/ibm/icu/impl/number/parse/MultiplierHandler.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