Search in sources :

Example 1 with CompoundRateProvider

use of org.javamoney.moneta.spi.CompoundRateProvider 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);
}
Also used : ExchangeRateProvider(javax.money.convert.ExchangeRateProvider) ArrayList(java.util.ArrayList) CompoundRateProvider(org.javamoney.moneta.spi.CompoundRateProvider) MonetaryException(javax.money.MonetaryException)

Example 2 with CompoundRateProvider

use of org.javamoney.moneta.spi.CompoundRateProvider in project jsr354-ri-bp by JavaMoney.

the class DefaultMonetaryConversionsSingletonSpi method getExchangeRateProvider.

@Override
public ExchangeRateProvider getExchangeRateProvider(String... providers) {
    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.size() == 1) {
        return provInstances.get(0);
    }
    return new CompoundRateProvider(provInstances);
}
Also used : ExchangeRateProvider(javax.money.convert.ExchangeRateProvider) ArrayList(java.util.ArrayList) CompoundRateProvider(org.javamoney.moneta.spi.CompoundRateProvider) MonetaryException(javax.money.MonetaryException)

Example 3 with CompoundRateProvider

use of org.javamoney.moneta.spi.CompoundRateProvider 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);
}
Also used : ExchangeRateProvider(javax.money.convert.ExchangeRateProvider) ArrayList(java.util.ArrayList) CompoundRateProvider(org.javamoney.moneta.spi.CompoundRateProvider) MonetaryException(javax.money.MonetaryException)

Example 4 with CompoundRateProvider

use of org.javamoney.moneta.spi.CompoundRateProvider 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);
}
Also used : ExchangeRateProvider(javax.money.convert.ExchangeRateProvider) ArrayList(java.util.ArrayList) CompoundRateProvider(org.javamoney.moneta.spi.CompoundRateProvider) MonetaryException(javax.money.MonetaryException)

Aggregations

ArrayList (java.util.ArrayList)4 MonetaryException (javax.money.MonetaryException)4 ExchangeRateProvider (javax.money.convert.ExchangeRateProvider)4 CompoundRateProvider (org.javamoney.moneta.spi.CompoundRateProvider)4