/** * Translates a {@code BigDecimal} value and a {@code CurrencyUnit} currency into a * {@code Money}. * * @param number numeric value of the {@code Money}. * @param currency currency unit of the {@code Money}. * @return a {@code Money} combining the numeric value and currency unit. */ public static RoundedMoney of(BigDecimal number, CurrencyUnit currency) { return new RoundedMoney(number, currency, Monetary.getDefaultRounding()); }
MonetaryOperator getDefaultMonetaryOperator(MonetaryOperator rounding, MonetaryContext context, MonetaryContextBuilder monetaryContextBuilder) { if (Objects.nonNull(rounding)) { return rounding; } if (Objects.nonNull(context)) { return createUsingMonetaryContext(context, monetaryContextBuilder); } else { return Monetary.getDefaultRounding(); } }
/** * Static factory method for creating a new instance of {@link RoundedMoney} . * * @param currencyCode The target currency as ISO currency code. * @param number The numeric part, not null. * @return A new instance of {@link RoundedMoney}. */ @Deprecated public static RoundedMoney of(Number number, String currencyCode) { return new RoundedMoney(number, Monetary.getCurrency(currencyCode), Monetary.getDefaultRounding()); }
private void applyJavaMoneyHack() { //fixes https://github.com/commercetools/commercetools-sunrise-java/issues/404 //exception play.api.http.HttpErrorHandlerExceptions$$anon$1: Execution exception[[CompletionException: java.lang.IllegalArgumentException: java.util.concurrent.CompletionException: io.sphere.sdk.json.JsonException: detailMessage: com.fasterxml.jackson.databind.JsonMappingException: Operator failed: javax.money.DefaultMonetaryRoundingsSingletonSpi$DefaultCurrencyRounding@1655879e (through reference chain: io.sphere.sdk.payments.PaymentDraftImpl["amountPlanned"]) Monetary.getDefaultRounding(); Monetary.getDefaultRounding().apply(MoneyImpl.ofCents(123, "EUR")); Monetary.getDefaultAmountType(); MonetaryFormats.getDefaultFormatProviderChain(); Monetary.getDefaultCurrencyProviderChain(); } }
private MoneyModule(final AmountWriter writer, final FieldNames names, final MonetaryAmountFormatFactory formatFactory, final MonetaryAmountFactory<? extends MonetaryAmount> amountFactory, final FastMoneyFactory fastMoneyFactory, final MoneyFactory moneyFactory, final RoundedMoneyFactory roundedMoneyFactory) { this.writer = writer; this.names = names; this.formatFactory = formatFactory; this.amountFactory = amountFactory; this.fastMoneyFactory = fastMoneyFactory; this.moneyFactory = moneyFactory; this.roundedMoneyFactory = roundedMoneyFactory; }
private MoneyModule(final AmountWriter writer, final FieldNames names, final MonetaryAmountFormatFactory formatFactory, final MonetaryAmountFactory<? extends MonetaryAmount> amountFactory, final FastMoneyFactory fastMoneyFactory, final MoneyFactory moneyFactory, final RoundedMoneyFactory roundedMoneyFactory) { this.writer = writer; this.names = names; this.formatFactory = formatFactory; this.amountFactory = amountFactory; this.fastMoneyFactory = fastMoneyFactory; this.moneyFactory = moneyFactory; this.roundedMoneyFactory = roundedMoneyFactory; }
MonetaryRounding r = Monetary.getDefaultRounding(); MonetaryAmount m = new TestMonetaryAmountBuilder().setNumber(new BigDecimal("12.123456789101222232323")).setCurrency(cu)
private MonetaryOperator createUsingMonetaryContext( MonetaryContext context, MonetaryContextBuilder monetaryContextBuilder) { MathContext mathContext = context.get(MathContext.class); if (Objects.isNull(mathContext)) { RoundingMode roundingMode = context.get(RoundingMode.class); if (Objects.nonNull(roundingMode)) { int scale = ofNullable(context.getInt("scale")).orElse(SCALE_DEFAULT); monetaryContextBuilder.set(roundingMode); monetaryContextBuilder.set("scale", scale); return Monetary.getRounding(RoundingQueryBuilder.of() .setScale(scale).set(roundingMode).build()); } else { return Monetary.getDefaultRounding(); } } else { monetaryContextBuilder.set(mathContext.getRoundingMode()); monetaryContextBuilder.set("scale", SCALE_DEFAULT); return Monetary.getRounding(RoundingQueryBuilder.of().set(mathContext) .setScale(SCALE_DEFAULT).build()); } } }
return new DefaultRounding(scale, roundingMode); } else if (roundingQuery.getRoundingName() != null && DEFAULT_ROUNDING_NAME.equals(roundingQuery.getRoundingName())) { return Monetary.getDefaultRounding();