@Override public ScenarioArray<?> convertedTo(Currency reportingCurrency, ScenarioFxRateProvider fxRateProvider) { if (value instanceof FxConvertible<?>) { FxConvertible<?> convertible = (FxConvertible<?>) value; if (fxRateProvider.getScenarioCount() != scenarioCount) { throw new IllegalArgumentException(Messages.format( "Expected {} FX rates but received {}", scenarioCount, fxRateProvider.getScenarioCount())); } ImmutableList<Object> converted = IntStream.range(0, scenarioCount) .mapToObj(i -> convertible.convertedTo(reportingCurrency, fxRateProvider.fxRateProvider(i))) .collect(toImmutableList()); return DefaultScenarioArray.of(converted); } return this; }
@Override public ScenarioArray<?> convertedTo(Currency resultCurrency, ScenarioFxRateProvider fxRateProvider) { int scenarioCount = getScenarioCount(); if (fxRateProvider.getScenarioCount() != scenarioCount) { throw new IllegalArgumentException(Messages.format( "Expected {} FX rates but received {}", scenarioCount, fxRateProvider.getScenarioCount())); } ImmutableList<Object> converted = zipWithIndex(values.stream()) .map(tp -> convert(resultCurrency, fxRateProvider, tp.getFirst(), tp.getSecond())) .collect(toImmutableList()); return DefaultScenarioArray.of(converted); }
@Override public CurrencyScenarioArray convertedTo(Currency reportingCurrency, ScenarioFxRateProvider fxRateProvider) { int size = getScenarioCount(); if (fxRateProvider.getScenarioCount() != size) { throw new IllegalArgumentException(Messages.format( "Expected {} FX rates but received {}", size, fxRateProvider.getScenarioCount())); } double[] singleCurrencyValues = new double[size]; for (Map.Entry<Currency, DoubleArray> entry : amounts.getValues().entrySet()) { Currency currency = entry.getKey(); DoubleArray currencyValues = entry.getValue(); for (int i = 0; i < size; i++) { double convertedValue = currencyValues.get(i) * fxRateProvider.fxRate(currency, reportingCurrency, i); singleCurrencyValues[i] += convertedValue; } } return CurrencyScenarioArray.of(reportingCurrency, DoubleArray.ofUnsafe(singleCurrencyValues)); }
@Override public CurrencyScenarioArray convertedTo(Currency reportingCurrency, ScenarioFxRateProvider fxRateProvider) { if (getCurrency().equals(reportingCurrency)) { return this; } if (fxRateProvider.getScenarioCount() != amounts.size()) { throw new IllegalArgumentException(Messages.format( "Expected {} FX rates but received {}", amounts.size(), fxRateProvider.getScenarioCount())); } DoubleArray convertedValues = amounts.getValues().mapWithIndex((i, v) -> v * fxRateProvider.fxRate(getCurrency(), reportingCurrency, i)); return of(reportingCurrency, convertedValues); }