Search in sources :

Example 1 with ProviderContextBuilder

use of javax.money.convert.ProviderContextBuilder 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();
}
Also used : ExchangeRateProvider(javax.money.convert.ExchangeRateProvider) ProviderContext(javax.money.convert.ProviderContext) RateType(javax.money.convert.RateType) ProviderContextBuilder(javax.money.convert.ProviderContextBuilder)

Example 2 with ProviderContextBuilder

use of javax.money.convert.ProviderContextBuilder in project jsr354-ri 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();
}
Also used : ExchangeRateProvider(javax.money.convert.ExchangeRateProvider) ProviderContext(javax.money.convert.ProviderContext) ArrayList(java.util.ArrayList) RateType(javax.money.convert.RateType) ProviderContextBuilder(javax.money.convert.ProviderContextBuilder) HashSet(java.util.HashSet)

Aggregations

ExchangeRateProvider (javax.money.convert.ExchangeRateProvider)2 ProviderContext (javax.money.convert.ProviderContext)2 ProviderContextBuilder (javax.money.convert.ProviderContextBuilder)2 RateType (javax.money.convert.RateType)2 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1