use of javax.money.convert.ExchangeRateProvider in project jsr354-ri-bp by JavaMoney.
the class DefaultMonetaryConversionsSingletonSpi method getProvidersToUse.
private Collection<String> getProvidersToUse(ConversionQuery query) {
List<String> providersToUse = new ArrayList<>();
List<String> providers = query.getProviderNames();
if (providers.isEmpty()) {
providers = getDefaultProviderChain();
if (providers.isEmpty()) {
throw new IllegalStateException("No default provider chain available.");
}
}
for (String provider : providers) {
ExchangeRateProvider prov = this.conversionProviders.get(provider);
if (prov == null) {
throw new MonetaryException("Invalid ExchangeRateProvider (not found): " + provider);
}
providersToUse.add(provider);
}
return providersToUse;
}
use of javax.money.convert.ExchangeRateProvider in project jsr354-ri-bp by JavaMoney.
the class BaseMonetaryConversionsSingletonSpi method getExchangeRateProviders.
/**
* Access the current registered {@link javax.money.convert.ExchangeRateProvider} instances. If no provider
* names are passed ALL current registered providers are returned in undefined order.
*
* @param providers the provider names of hte providers to be accessed
* @return the list of providers, in the same order as requested.
* @throws javax.money.MonetaryException if a provider could not be resolved.
*/
public List<ExchangeRateProvider> getExchangeRateProviders(String... providers) {
List<ExchangeRateProvider> provInstances = new ArrayList<>();
Collection<String> providerNames = Arrays.asList(providers);
if (providerNames.isEmpty()) {
providerNames = getProviderNames();
}
for (String provName : providerNames) {
ExchangeRateProvider provider = getExchangeRateProvider(provName);
if (provider == null) {
throw new MonetaryException("Unsupported conversion/rate provider: " + provName);
}
provInstances.add(provider);
}
return provInstances;
}
use of javax.money.convert.ExchangeRateProvider in project jsr354-ri-bp by JavaMoney.
the class ECBEarlyAccessProviderTest method testAccess_HIST.
@Test
public void testAccess_HIST() throws InterruptedException {
final MonetaryAmount inEuro = Money.of(10, "EUR");
for (int i = 0; i < 100; i++) {
try {
final ExchangeRateProvider rateProvider = MonetaryConversions.getExchangeRateProvider("ECB-HIST");
final CurrencyConversion dollarConversion = rateProvider.getCurrencyConversion("USD");
final MonetaryAmount inDollar = inEuro.with(dollarConversion);
System.out.println(String.format("RUN: %n - %s: %s ≙ %s", i, rateProvider, inEuro, inDollar));
} catch (Exception e) {
e.printStackTrace();
}
}
for (int i = 0; i < 100; i++) {
final ExchangeRateProvider rateProvider = MonetaryConversions.getExchangeRateProvider("ECB-HIST");
final CurrencyConversion dollarConversion = rateProvider.getCurrencyConversion("USD");
Thread.sleep(100L);
final MonetaryAmount inDollar = inEuro.with(dollarConversion);
System.out.println(String.format("RUN: %n - %s: %s ≙ %s", i, rateProvider, inEuro, inDollar));
}
}
use of javax.money.convert.ExchangeRateProvider in project jsr354-ri-bp by JavaMoney.
the class ECBEarlyAccessProviderTest method testAccess_ECB.
@Test
public void testAccess_ECB() throws InterruptedException {
final MonetaryAmount inEuro = Money.of(10, "EUR");
for (int i = 0; i < 100; i++) {
try {
final ExchangeRateProvider rateProvider = MonetaryConversions.getExchangeRateProvider("ECB");
final CurrencyConversion dollarConversion = rateProvider.getCurrencyConversion("USD");
final MonetaryAmount inDollar = inEuro.with(dollarConversion);
System.out.println(String.format("RUN: %n - %s: %s ≙ %s", i, rateProvider, inEuro, inDollar));
} catch (Exception e) {
e.printStackTrace();
}
}
for (int i = 0; i < 100; i++) {
final ExchangeRateProvider rateProvider = MonetaryConversions.getExchangeRateProvider("ECB");
final CurrencyConversion dollarConversion = rateProvider.getCurrencyConversion("USD");
Thread.sleep(100L);
final MonetaryAmount inDollar = inEuro.with(dollarConversion);
System.out.println(String.format("RUN: %n - %s: %s ≙ %s", i, rateProvider, inEuro, inDollar));
}
}
use of javax.money.convert.ExchangeRateProvider in project jsr354-ri-bp by JavaMoney.
the class IMFEarlyAccessProviderTest method testAccess_IMF.
@Test
public void testAccess_IMF() throws InterruptedException {
final MonetaryAmount inEuro = Money.of(10, "EUR");
for (int i = 0; i < 100; i++) {
try {
final ExchangeRateProvider rateProvider = MonetaryConversions.getExchangeRateProvider("IMF");
final CurrencyConversion dollarConversion = rateProvider.getCurrencyConversion("USD");
final MonetaryAmount inDollar = inEuro.with(dollarConversion);
System.out.println(String.format("RUN: %n - %s: %s ≙ %s", i, rateProvider, inEuro, inDollar));
} catch (Exception e) {
e.printStackTrace();
}
}
for (int i = 0; i < 100; i++) {
final ExchangeRateProvider rateProvider = MonetaryConversions.getExchangeRateProvider("IMF");
final CurrencyConversion dollarConversion = rateProvider.getCurrencyConversion("USD");
Thread.sleep(100L);
final MonetaryAmount inDollar = inEuro.with(dollarConversion);
System.out.println(String.format("RUN: %n - %s: %s ≙ %s", i, rateProvider, inEuro, inDollar));
}
}
Aggregations