use of javax.money.convert.ExchangeRateProvider in project jsr354-ri by JavaMoney.
the class DefaultMonetaryConversionsSingletonSpi method getExchangeRateProvider.
@Override
public ExchangeRateProvider getExchangeRateProvider(String... providers) {
List<ExchangeRateProvider> provInstances = new ArrayList<>();
for (String provName : providers) {
ExchangeRateProvider prov = Optional.ofNullable(this.conversionProviders.get(provName)).orElseThrow(() -> new MonetaryException("Unsupported conversion/rate provider: " + provName));
provInstances.add(prov);
}
if (provInstances.size() == 1) {
return provInstances.get(0);
}
return new CompoundRateProvider(provInstances);
}
use of javax.money.convert.ExchangeRateProvider in project jsr354-ri by JavaMoney.
the class DefaultMonetaryConversionsSingletonSpi method reload.
/**
* Reloads/reinitializes the providers found.
*/
public void reload() {
Map<String, ExchangeRateProvider> newProviders = new ConcurrentHashMap<>();
for (ExchangeRateProvider prov : Bootstrap.getServices(ExchangeRateProvider.class)) {
newProviders.put(prov.getContext().getProviderName(), prov);
}
this.conversionProviders = newProviders;
}
use of javax.money.convert.ExchangeRateProvider in project jsr354-ri by JavaMoney.
the class DefaultMonetaryConversionsSingletonSpi method getExchangeRateProvider.
@Override
public ExchangeRateProvider getExchangeRateProvider(ConversionQuery conversionQuery) {
Collection<String> providers = getProvidersToUse(conversionQuery);
List<ExchangeRateProvider> provInstances = new ArrayList<>();
for (String provName : providers) {
ExchangeRateProvider prov = Optional.ofNullable(this.conversionProviders.get(provName)).orElseThrow(() -> new MonetaryException("Unsupported conversion/rate provider: " + provName));
provInstances.add(prov);
}
if (provInstances.isEmpty()) {
throw new MonetaryException("No such providers: " + conversionQuery);
}
if (provInstances.size() == 1) {
return provInstances.get(0);
}
return new CompoundRateProvider(provInstances);
}
use of javax.money.convert.ExchangeRateProvider in project jsr354-ri-bp by JavaMoney.
the class ExchangeRateTypeTest method shouldReturnsECBHistoricRateProvider.
@Test
public void shouldReturnsECBHistoricRateProvider() {
ExchangeRateProvider prov = MonetaryConversions.getExchangeRateProvider(ExchangeRateType.ECB_HIST);
assertNotNull(prov);
assertEquals(ECBHistoricRateProvider.class, prov.getClass());
}
use of javax.money.convert.ExchangeRateProvider in project jsr354-ri-bp by JavaMoney.
the class ExchangeRateTypeTest method shouldReturnsIdentityRateProvider.
@Test
public void shouldReturnsIdentityRateProvider() {
ExchangeRateProvider prov = MonetaryConversions.getExchangeRateProvider(ExchangeRateType.IDENTITY);
assertNotNull(prov);
assertEquals(IdentityRateProvider.class, prov.getClass());
}
Aggregations