use of javax.money.convert.ExchangeRateProvider in project jsr354-ri-bp by JavaMoney.
the class ExchangeRateTypeTest method shouldReturnsIMFRateProvider.
@Test
public void shouldReturnsIMFRateProvider() {
ExchangeRateProvider prov = MonetaryConversions.getExchangeRateProvider(ExchangeRateType.IMF);
assertNotNull(prov);
assertEquals(IMFRateProvider.class, prov.getClass());
}
use of javax.money.convert.ExchangeRateProvider in project jsr354-ri-bp by JavaMoney.
the class ExchangeRateTypeTest method shouldReturnsECBHistoric90RateProvider.
@Test
public void shouldReturnsECBHistoric90RateProvider() {
ExchangeRateProvider prov = MonetaryConversions.getExchangeRateProvider(ExchangeRateType.ECB_HIST90);
assertNotNull(prov);
assertEquals(ECBHistoric90RateProvider.class, prov.getClass());
}
use of javax.money.convert.ExchangeRateProvider in project jsr354-ri-bp by JavaMoney.
the class ECBEarlyAccessProviderTest method testAccess_HIST90.
@Test
public void testAccess_HIST90() throws InterruptedException {
final MonetaryAmount inEuro = Money.of(10, "EUR");
for (int i = 0; i < 100; i++) {
try {
final ExchangeRateProvider rateProvider = MonetaryConversions.getExchangeRateProvider("ECB-HIST90");
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-HIST90");
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 CompoundRateProvider method createContext.
private static ProviderContext createContext(Iterable<ExchangeRateProvider> providers) {
Set<RateType> rateTypeSet = new HashSet<>();
StringBuilder providerName = new StringBuilder("Compound: ");
List<ProviderContext> childContextList = new ArrayList<>();
for (ExchangeRateProvider exchangeRateProvider : providers) {
childContextList.add(exchangeRateProvider.getContext());
providerName.append(exchangeRateProvider.getContext().getProviderName());
providerName.append(',');
rateTypeSet.addAll(exchangeRateProvider.getContext().getRateTypes());
}
providerName.setLength(providerName.length() - 1);
ProviderContextBuilder builder = ProviderContextBuilder.of(providerName.toString(), rateTypeSet);
builder.set(CHILD_PROVIDER_CONTEXTS_KEY, childContextList);
return builder.build();
}
use of javax.money.convert.ExchangeRateProvider in project jsr354-ri-bp by JavaMoney.
the class DefaultMonetaryConversionsSingletonSpi method getExchangeRateProvider.
@Override
public ExchangeRateProvider getExchangeRateProvider(ConversionQuery query) {
Collection<String> providers = getProvidersToUse(query);
List<ExchangeRateProvider> provInstances = new ArrayList<>();
for (String provName : providers) {
ExchangeRateProvider prov = this.conversionProviders.get(provName);
if (prov == null) {
throw new MonetaryException("Unsupported conversion/rate provider: " + provName);
}
provInstances.add(prov);
}
if (provInstances.isEmpty()) {
throw new MonetaryException("No such providers: " + query);
}
if (provInstances.size() == 1) {
return provInstances.get(0);
}
return new CompoundRateProvider(provInstances);
}
Aggregations