javax.money.CurrencyQuery Java Examples
The following examples show how to use
javax.money.CurrencyQuery.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ConfigurableCurrencyUnitProviderTest.java From jsr354-ri with Apache License 2.0 | 6 votes |
/** * Tests that searching by numeric code is supported by {@link ConfigurableCurrencyUnitProvider}. */ @Test public void testSearchByNumericCurrencyCode() { CurrencyUnit usd = CurrencyUnitBuilder.of("USD", "search-test") .setNumericCode(840) .setDefaultFractionDigits(2) .build(false); CurrencyUnit eur = CurrencyUnitBuilder.of("EUR", "search-test") .setNumericCode(978) .setDefaultFractionDigits(2) .build(false); ConfigurableCurrencyUnitProvider.registerCurrencyUnit(usd); ConfigurableCurrencyUnitProvider.registerCurrencyUnit(eur); try { CurrencyQuery query = CurrencyQueryBuilder.of() .setProviderName(ConfigurableCurrencyUnitProvider.class.getSimpleName()) .setNumericCodes(840) .build(); CurrencyUnit currency = Monetary.getCurrency(query); assertEquals(usd, currency); } finally { ConfigurableCurrencyUnitProvider.removeCurrencyUnit(usd.getCurrencyCode()); ConfigurableCurrencyUnitProvider.removeCurrencyUnit(eur.getCurrencyCode()); } }
Example #2
Source File: CurrencyQueryTest.java From jsr354-ri with Apache License 2.0 | 6 votes |
/** * Tests that searching currencies by regex is supported. */ @Test public void testSeachByRegex() { String dollarRegex = "\\p{Upper}{2}D"; Pattern dollarPattern = Pattern.compile(dollarRegex); Collection<CurrencyUnit> allCurrencies = Monetary.getCurrencies(CurrencyQueryBuilder.of().build()); Set<String> availableDollarCodes = allCurrencies.stream() .map(CurrencyUnit::getCurrencyCode) .filter(currencyCode -> dollarPattern.matcher(currencyCode).matches()) .collect(toSet()); assertFalse(availableDollarCodes.isEmpty()); CurrencyQuery dollarQuery = CurrencyQueryBuilder.of().setCurrencyCodes(dollarRegex).build(); Collection<CurrencyUnit> dollarCurrencies = Monetary.getCurrencies(dollarQuery); for (CurrencyUnit dollarCurrency : dollarCurrencies) { availableDollarCodes.remove(dollarCurrency.getCurrencyCode()); } assertTrue(availableDollarCodes.isEmpty()); }
Example #3
Source File: CDITestCurrencyProvider.java From javamoney-lib with Apache License 2.0 | 5 votes |
@Override public Set<CurrencyUnit> getCurrencies(CurrencyQuery query) { if (query.getCurrencyCodes().contains("CDITest")) { return currencies; } return Collections.emptySet(); }
Example #4
Source File: DefaultMonetaryCurrenciesSingletonSpi.java From jsr354-ri with Apache License 2.0 | 5 votes |
@Override public Set<CurrencyUnit> getCurrencies(CurrencyQuery query) { Set<CurrencyUnit> result = new HashSet<>(); List<CurrencyProviderSpi> providers = collectProviders(query); for (CurrencyProviderSpi spi : providers) { try { result.addAll(spi.getCurrencies(query)); } catch (Exception e) { Logger.getLogger(DefaultMonetaryCurrenciesSingletonSpi.class.getName()) .log(Level.SEVERE, "Error loading currency provider names for " + spi.getClass().getName(), e); } } return result; }
Example #5
Source File: DefaultMonetaryCurrenciesSingletonSpi.java From jsr354-ri with Apache License 2.0 | 5 votes |
private boolean isCurrencyAvailable(CurrencyQuery query) { for (CurrencyProviderSpi provider : collectProviders(query)) { if (provider.isCurrencyAvailable(query)) { return true; } } return false; }
Example #6
Source File: GeeConCurrencyProvider.java From javamoney-examples with Apache License 2.0 | 5 votes |
@Override public Set<CurrencyUnit> getCurrencies(CurrencyQuery query) { if(Boolean.TRUE.equals(query.getBoolean("GeeCon"))) { return currencies; } return Collections.emptySet(); }
Example #7
Source File: GeeConCurrencyProvider.java From javamoney-examples with Apache License 2.0 | 5 votes |
@Override public Set<CurrencyUnit> getCurrencies(CurrencyQuery query) { if(Boolean.TRUE.equals(query.getBoolean("GeeCon"))) { return currencies; } return Collections.emptySet(); }
Example #8
Source File: GeeConCurrencyProvider.java From javamoney-examples with Apache License 2.0 | 4 votes |
@Override public boolean isCurrencyAvailable(CurrencyQuery query) { // TODO Auto-generated method stub return false; }
Example #9
Source File: GeeConCurrencyProvider.java From javamoney-examples with Apache License 2.0 | 4 votes |
@Override public boolean isCurrencyAvailable(CurrencyQuery query) { // TODO Auto-generated method stub return false; }
Example #10
Source File: BitcoinCurrencyProvider.java From consensusj with Apache License 2.0 | 3 votes |
/** * Return a {@link CurrencyUnit} instances matching the given * {@link javax.money.CurrencyQuery}. * * @param query the {@link javax.money.CurrencyQuery} containing the parameters determining the query. not null. * @return the corresponding {@link CurrencyUnit}s matching, never null. */ @Override public Set<CurrencyUnit> getCurrencies(CurrencyQuery query){ // Query for currencyCode BTC or default query returns bitcoinSet else emptySet. return (query.getCurrencyCodes().contains("BTC") || query.getCurrencyCodes().isEmpty()) ? bitcoinSet : Collections.emptySet(); }