private Object convert(Currency reportingCurrency, ScenarioFxRateProvider fxRateProvider, Object base, int index) { if (base instanceof FxConvertible<?>) { FxConvertible<?> convertible = (FxConvertible<?>) base; return convertible.convertedTo(reportingCurrency, fxRateProvider.fxRateProvider(index)); } return base; }
@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; }