/** * Creates a new {@link javax.money.format.AmountFormatQuery} instance. * * @return a new {@link javax.money.format.AmountFormatQuery} instance, never null. */ public AmountFormatQuery build() { return new AmountFormatQuery(this); }
/** * Gets a Locale to be applied. * * @return the style's locale, or null. */ public Locale getLocale() { return get(Locale.class); }
/** * Gets a style's id. * * @return the styleId, or null. */ public String getFormatName() { return getText(KEY_QUERY_FORMAT_NAME); }
@Override public Collection<MonetaryAmountFormat> getAmountFormats(AmountFormatQuery amountFormatQuery) { Objects.requireNonNull(amountFormatQuery, "AmountFormatContext required"); if (!amountFormatQuery.getProviderNames().isEmpty() && !amountFormatQuery.getProviderNames().contains(getProviderName())) { return Collections.emptySet(); } if (!(amountFormatQuery.getFormatName() == null || DEFAULT_STYLE.equals(amountFormatQuery.getFormatName()))) { return Collections.emptySet(); } AmountFormatContextBuilder builder = AmountFormatContextBuilder.of(DEFAULT_STYLE); if (amountFormatQuery.getLocale() != null) { builder.setLocale(amountFormatQuery.getLocale()); } builder.importContext(amountFormatQuery, false); builder.setMonetaryAmountFactory(amountFormatQuery.getMonetaryAmountFactory()); return Arrays.asList(new MonetaryAmountFormat[]{new DefaultMonetaryAmountFormat(builder.build())}); }
/** * Checks if a {@link javax.money.format.MonetaryAmountFormat} is available given a {@link javax.money.format * .AmountFormatQuery}. * * @param locale the target {@link Locale}, not {@code null}. * @param providers The (optional) providers to be used, ordered correspondingly. * @return true, if a t least one {@link javax.money.format.MonetaryAmountFormat} is matching the query. */ default boolean isAvailable(Locale locale, String... providers) { return isAvailable(AmountFormatQuery.of(locale, providers)); }
/** * Test MonetaryFormats.getAvailableLocales, all locales available also from java.text.DecimalFormat must be * supported (using AmountFormatContext.of(Locale)), more locales are possible. */ @Test(description = "4.4.3 Ensures for each locale defined by DecimalFormat.getAvailableLocales() a " + "MonetaryFormats.getAmountFormat(AmountFormatQuery) returns a formatter.") @SpecAssertion(section = "4.4.3", id = "443-A3") public void testAmountStyleOf() { for (Locale locale : DecimalFormat.getAvailableLocales()) { AssertJUnit.assertNotNull(MonetaryFormats.getAmountFormat(AmountFormatQuery.of(locale))); } } }
/** * AccessingMonetaryAmountFormat using * MonetaryFormats.getAmountFormat(AmountFormatContext style), all locales * available also from java.text.DecimalFormat must be supported * (using AmountFormatContext.of(Locale)). */ @Test(description = "4.4.3 Ensures for each locale defined by DecimalFormat.getAvailableLocales() a " + "MonetaryAmountFormat instance is provided.") @SpecAssertion(section = "4.4.3", id = "443-A2") public void testGetAmountFormat() { for (Locale locale : DecimalFormat.getAvailableLocales()) { AssertJUnit.assertNotNull(MonetaryFormats.getAmountFormat(AmountFormatQuery.of(locale))); } }
/** * Gets the {@link javax.money.MonetaryAmountFactoryQuery} to be used for accessing {@link javax.money * .MonetaryAmountFactory}, when amount's are parsed. * * @return the monetary context, or {@code null}. */ @SuppressWarnings("rawtypes") public MonetaryAmountFactory getMonetaryAmountFactory() { MonetaryAmountFactory factory = get(MonetaryAmountFactory.class); if (factory == null) { return Monetary.getDefaultAmountFactory(); } return factory; }