/** * Get all available locales. This equals to {@link MonetaryAmountFormatProviderSpi#getAvailableLocales()}. * * @param providers The providers to be used, if not set the providers as defined by #getDefaultCurrencyProviderChain() are * used. * @return all available locales, never {@code null}. */ public static Set<Locale> getAvailableLocales(String... providers) { return getMonetaryFormatsSpi().getAvailableLocales(providers); }
/** * Get the names of the currently registered format providers. * * @return the provider names, never null. */ public static Collection<String> getFormatProviderNames() { Collection<String> providers = Optional.ofNullable(getMonetaryFormatsSpi()).orElseThrow( () -> new MonetaryException( "No MonetaryFormatsSingletonSpi loaded, query functionality is not available.")) .getProviderNames(); if (Objects.isNull(providers)) { Logger.getLogger(MonetaryFormats.class.getName()).warning( "No supported rate/conversion providers returned by SPI: " + getMonetaryFormatsSpi().getClass().getName()); return Collections.emptySet(); } return providers; }
/** * Get the default provider chain, identified by the unique provider names in order as evaluated and used. * * @return the default provider chain, never null. */ public static List<String> getDefaultFormatProviderChain() { return Optional.ofNullable(getMonetaryFormatsSpi()).orElseThrow(() -> new MonetaryException( "No MonetaryFormatsSingletonSpi " + "loaded, query functionality is not available.")) .getDefaultProviderChain(); }
/** * Checks if a {@link MonetaryAmountFormat} is available for the given {@link javax.money.format.AmountFormatQuery}. * * @param formatQuery the required {@link AmountFormatQuery}, not {@code null}. If the query does not define * any explicit provider chain, the providers as defined by #getDefaultCurrencyProviderChain() * are used. * @return true, if a corresponding {@link MonetaryAmountFormat} is accessible. */ public static boolean isAvailable(AmountFormatQuery formatQuery) { return Optional.ofNullable(getMonetaryFormatsSpi()).orElseThrow(() -> new MonetaryException( "No MonetaryFormatsSingletonSpi " + "loaded, query functionality is not available.")) .isAvailable(formatQuery); }
/** * Checks if a {@link MonetaryAmountFormat} is available for the given {@link Locale} and providers. * * @param locale the target {@link Locale}, not {@code null}. * @param providers The providers to be queried, if not set the providers as defined by #getDefaultCurrencyProviderChain() * are queried. * @return true, if a corresponding {@link MonetaryAmountFormat} is accessible. */ public static boolean isAvailable(Locale locale, String... providers) { return Optional.ofNullable(getMonetaryFormatsSpi()).orElseThrow(() -> new MonetaryException( "No MonetaryFormatsSingletonSpi " + "loaded, query functionality is not available.")) .isAvailable(locale, providers); }
/** * Access all {@link MonetaryAmountFormat} instances that match the given a {@link AmountFormatQuery}. * * @param formatQuery the required {@link AmountFormatQuery}, not {@code null}. If the query does not define * any explicit provider chain, the providers as defined by #getDefaultCurrencyProviderChain() * are used. * @return the matching {@link MonetaryAmountFormat} * @throws MonetaryException if no registered {@link MonetaryAmountFormatProviderSpi} can provide a * corresponding {@link MonetaryAmountFormat} instance. */ public static Collection<MonetaryAmountFormat> getAmountFormats(AmountFormatQuery formatQuery) { return Optional.ofNullable(getMonetaryFormatsSpi()).orElseThrow(() -> new MonetaryException( "No MonetaryFormatsSingletonSpi " + "loaded, query functionality is not available.")) .getAmountFormats(formatQuery); }
/** * Access the default {@link MonetaryAmountFormat} given a {@link Locale}. * * @param formatQuery the required {@link AmountFormatQuery}, not {@code null}. If the query does not define * any explicit provider chain, the providers as defined by #getDefaultCurrencyProviderChain() * are used. * @return the matching {@link MonetaryAmountFormat} * @throws MonetaryException if no registered {@link MonetaryAmountFormatProviderSpi} can provide a * corresponding {@link MonetaryAmountFormat} instance. */ public static MonetaryAmountFormat getAmountFormat(AmountFormatQuery formatQuery) { return Optional.ofNullable(getMonetaryFormatsSpi()).orElseThrow(() -> new MonetaryException( "No MonetaryFormatsSingletonSpi " + "loaded, query functionality is not available.")) .getAmountFormat(formatQuery); }