/** * Access a {@link javax.money.MonetaryRounding} using the rounding name. * * @param roundingName The rounding name, not null. * @param providers the optional provider list and ordering to be used * @return the corresponding {@link javax.money.MonetaryOperator} implementing the rounding, never * {@code null}. * @throws IllegalArgumentException if no such rounding is registered using a {@link * RoundingProviderSpi} instance. */ public MonetaryRounding getRounding(String roundingName, String... providers) { MonetaryRounding op = getRounding( RoundingQueryBuilder.of() .setProviderNames(providers) .setRoundingName(roundingName) .build()); if (op == null) { throw new MonetaryException("No rounding provided with rounding name: " + roundingName); } return op; }
/** * Access a {@link javax.money.MonetaryRounding} for rounding {@link javax.money.MonetaryAmount} * instances given a currency. * * @param currencyUnit The currency, which determines the required precision. As {@link * java.math.RoundingMode}, by default, {@link java.math.RoundingMode#HALF_UP} is sued. * @param providers the optional provider list and ordering to be used * @return a new instance {@link javax.money.MonetaryOperator} implementing the rounding, never * {@code null}. * @throws javax.money.MonetaryException if no such rounding could be provided. */ public MonetaryRounding getRounding(CurrencyUnit currencyUnit, String... providers) { MonetaryRounding op = getRounding( RoundingQueryBuilder.of() .setProviderNames(providers) .setCurrency(currencyUnit) .build()); if (op == null) { throw new MonetaryException( "No rounding provided for CurrencyUnit: " + currencyUnit.getCurrencyCode()); } return op; }
/** * Checks if a {@link javax.money.MonetaryRounding} is available given a {@link * javax.money.CurrencyUnit}. * * @param currencyUnit The currency, which determines the required precision. As {@link * java.math.RoundingMode}, by default, {@link java.math.RoundingMode#HALF_UP} is used. * @param providers the providers and ordering to be used. By default providers and ordering as * defined in #getDefaultProviders is used. * @return true, if a corresponding {@link javax.money.MonetaryRounding} is available. * @throws IllegalArgumentException if no such rounding is registered using a {@link * RoundingProviderSpi} instance. */ public boolean isRoundingAvailable(CurrencyUnit currencyUnit, String... providers) { return isRoundingAvailable( RoundingQueryBuilder.of().setProviderNames(providers).setCurrency(currencyUnit).build()); }
/** * Checks if a {@link javax.money.MonetaryRounding} is available given a roundingId. * * @param roundingId The rounding identifier. * @param providers the providers and ordering to be used. By default providers and ordering as * defined in #getDefaultProviders is used. * @return true, if a corresponding {@link javax.money.MonetaryRounding} is available. * @throws IllegalArgumentException if no such rounding is registered using a {@link * RoundingProviderSpi} instance. */ public boolean isRoundingAvailable(String roundingId, String... providers) { return isRoundingAvailable( RoundingQueryBuilder.of().setProviderNames(providers).setRoundingName(roundingId).build()); }