LEFT | RIGHT |
(no file at all) | |
| 1 // © 2017 and later: Unicode, Inc. and others. |
| 2 // License & terms of use: http://www.unicode.org/copyright.html#License |
| 3 package com.ibm.icu.impl.number.parse; |
| 4 |
| 5 import java.math.BigDecimal; |
| 6 import java.math.MathContext; |
| 7 |
| 8 /** |
| 9 * @author sffc |
| 10 * |
| 11 */ |
| 12 public class MultiplierHandler extends ValidationMatcher { |
| 13 |
| 14 private final BigDecimal multiplier; |
| 15 private final MathContext mc; |
| 16 private final boolean isNegative; |
| 17 |
| 18 public MultiplierHandler(BigDecimal multiplier, MathContext mc) { |
| 19 this.multiplier = BigDecimal.ONE.divide(multiplier, mc).abs(); |
| 20 this.mc = mc; |
| 21 isNegative = multiplier.signum() < 0; |
| 22 } |
| 23 |
| 24 @Override |
| 25 public void postProcess(ParsedNumber result) { |
| 26 if (result.quantity != null) { |
| 27 result.quantity.multiplyBy(multiplier); |
| 28 result.quantity.roundToMagnitude(result.quantity.getMagnitude() - mc
.getPrecision(), mc); |
| 29 if (isNegative) { |
| 30 result.flags ^= ParsedNumber.FLAG_NEGATIVE; |
| 31 } |
| 32 } |
| 33 } |
| 34 |
| 35 @Override |
| 36 public String toString() { |
| 37 return "<MultiplierHandler " + multiplier + ">"; |
| 38 } |
| 39 } |
LEFT | RIGHT |