/** * Access all currently available {@link MonetaryAmount} implementation classes that are * accessible from this {@link MonetaryAmount} singleton. * * @return all currently available {@link MonetaryAmount} implementation classes that have * corresponding {@link MonetaryAmountFactory} instances provided, never {@code null} */ public static Collection<Class<? extends MonetaryAmount>> getAmountTypes() { return Optional.ofNullable(monetaryAmountsSingletonSpi()) .orElseThrow(() -> new MonetaryException("No MonetaryAmountsSingletonSpi loaded.")).getAmountTypes(); }
/** * Access the default {@link MonetaryAmount} implementation class that is * accessible from this {@link MonetaryAmount} singleton. * * @return all current default {@link MonetaryAmount} implementation class, never {@code null} */ public static Class<? extends MonetaryAmount> getDefaultAmountType() { return Optional.ofNullable(monetaryAmountsSingletonSpi()) .orElseThrow(() -> new MonetaryException("No MonetaryAmountsSingletonSpi loaded.")) .getDefaultAmountType(); }
/** * Access all currently available {@link MonetaryAmount} implementation classes that are * accessible from this {@link MonetaryAmount} singleton. * * @return all currently available {@link MonetaryAmount} implementation classes that have * corresponding {@link MonetaryAmountFactory} instances provided, never {@code null} */ public static Collection<MonetaryAmountFactory<?>> getAmountFactories() { return Optional.ofNullable(monetaryAmountsSingletonSpi()) .orElseThrow(() -> new MonetaryException("No MonetaryAmountsSingletonSpi loaded.")) .getAmountFactories(); }
/** * Access the default {@link MonetaryAmountFactory} as defined by * {@link javax.money.spi.MonetaryAmountsSingletonSpi#getDefaultAmountFactory()}. * * @return the {@link MonetaryAmountFactory} corresponding to default amount type, * never {@code null}. * @throws MonetaryException if no {@link MonetaryAmountFactory} targeting the default amount type * implementation class is registered. */ public static MonetaryAmountFactory<?> getDefaultAmountFactory() { return Optional.ofNullable(monetaryAmountsSingletonSpi()) .orElseThrow(() -> new MonetaryException("No MonetaryAmountsSingletonSpi loaded.")) .getDefaultAmountFactory(); }
/** * Access an {@link MonetaryAmountFactory} for the given {@link MonetaryAmount} implementation * type. * * @param amountType {@link MonetaryAmount} implementation type, nor {@code null}. * @return the corresponding {@link MonetaryAmountFactory}, never {@code null}. * @throws MonetaryException if no {@link MonetaryAmountFactory} targeting the given {@link MonetaryAmount} * implementation class is registered. */ public static <T extends MonetaryAmount> MonetaryAmountFactory<T> getAmountFactory(Class<T> amountType) { MonetaryAmountsSingletonSpi spi = Optional.ofNullable(monetaryAmountsSingletonSpi()) .orElseThrow(() -> new MonetaryException("No MonetaryAmountsSingletonSpi loaded.")); MonetaryAmountFactory<T> factory = spi.getAmountFactory(amountType); return Optional.ofNullable(factory).orElseThrow( () -> new MonetaryException("No AmountFactory available for type: " + amountType.getName())); }