private static MonetaryAmount[] of(final MonetaryAmount[] array) { for (int i = 0; i < array.length; i++) { array[i] = of(array[i]); } return array; }
public static MonetaryAmount of(final MonetaryAmount money, int fractionDigits) { return new HighPrecisionMoneyImpl(money,fractionDigits); }
@Override public int hashCode() { return asMoney().hashCode(); }
public static MonetaryAmount of(final BigDecimal money,String currency, final int fractionDigits ) { return of( money,createCurrencyByCode(currency),fractionDigits); }
private Money asMoney() { return Money.of(getNumber(), getCurrency()); }
private static BigDecimal amountToPreciseAmount(final HighPrecisionMoneyImpl monetaryAmount) { final MonetaryRounding ROUNDING = ROUNDING_PROVIDER.getRounding(RoundingQueryBuilder.of().setRoundingName("default").setCurrency(monetaryAmount.getCurrency()) .build()); return monetaryAmount .with(ROUNDING) .query(amount -> queryFrom(monetaryAmount, monetaryAmount.getFractionDigits())); }
/** * Creates a new Money instance. * Money can't represent cent fractions. The value will be rounded to nearest cent value using RoundingMode.HALF_EVEN. * * @param monetaryAmount the amount with currency to transform */ @JsonIgnore public HighPrecisionMoneyRepresentation(final HighPrecisionMoneyImpl monetaryAmount) { super(amountToCents(monetaryAmount), requireValidCurrencyCode(monetaryAmount.getCurrency().getCurrencyCode())); preciseAmount = amountToPreciseAmount(monetaryAmount); fractionDigits = monetaryAmount.getFractionDigits(); }
@Override public boolean equals(final Object obj) { return Optional.ofNullable(obj) .filter(other -> other != null) .filter(other -> other instanceof MonetaryAmount) .map(o -> (MonetaryAmount) o) .map(o -> o.getCurrency().equals(getCurrency()) && o.isEqualTo(money)) .orElse(false); }
@Override public MonetaryAmount multiply(Number multiplicand) { return of(money.multiply(multiplicand)); }
@Override public MonetaryAmount[] divideAndRemainder(long divisor) { return of(money.divideAndRemainder(divisor)); }
@Override public MonetaryAmount scaleByPowerOfTen(int power) { return of(money.scaleByPowerOfTen(power)); }
@Override public MonetaryAmount divide(Number divisor) { return of(money.divide(divisor)); }
@Override public MonetaryAmount remainder(long divisor) { return of(money.remainder(divisor)); }
@Override public MonetaryAmount subtract(MonetaryAmount amount) { return of(money.subtract(amount)); }
@Override public MonetaryAmount divideToIntegralValue(long divisor) { return of(money.divideToIntegralValue(divisor)); }
@Override public MonetaryAmount divideToIntegralValue(double divisor) { return of(money.divideToIntegralValue(divisor)); }
@Override public MonetaryAmount stripTrailingZeros() { return of(money.stripTrailingZeros()); }
@Override public MonetaryAmount with(MonetaryOperator operator) { return of(money.with(operator)); }
@Override public MonetaryAmount multiply(long multiplicand) { return of(money.multiply(multiplicand)); }
@Override public MonetaryAmount divide(long divisor) { return of(money.divide(divisor)); }