@Override public JumpToDefault convertedTo(Currency resultCurrency, FxRateProvider rateProvider) { Map<StandardId, Double> mutable = new HashMap<>(); for (Entry<StandardId, Double> entry : amounts.entrySet()) { double converted = rateProvider.convert(entry.getValue(), currency, resultCurrency); mutable.put(entry.getKey(), converted); } return JumpToDefault.of(resultCurrency, mutable); }
/** * Converts this amount to an equivalent amount in the specified currency. * <p> * The result will be expressed in terms of the given currency. * If conversion is needed, the provider will be used to supply the FX rate. * * @param resultCurrency the currency of the result * @param rateProvider the provider of FX rates * @return the converted instance, in the specified currency * @throws RuntimeException if no FX rate could be found */ @Override public Money convertedTo(Currency resultCurrency, FxRateProvider rateProvider) { if (currency.equals(resultCurrency)) { return this; } double converted = rateProvider.convert(amount.doubleValue(), currency, resultCurrency); return Money.of(resultCurrency, converted); }
/** * Converts this amount to an equivalent amount in the specified currency. * <p> * The result will be expressed in terms of the given currency. * If conversion is needed, the provider will be used to supply the FX rate. * * @param resultCurrency the currency of the result * @param rateProvider the provider of FX rates * @return the converted instance, in the specified currency * @throws RuntimeException if no FX rate could be found */ @Override public CurrencyAmount convertedTo(Currency resultCurrency, FxRateProvider rateProvider) { if (currency.equals(resultCurrency)) { return this; } double converted = rateProvider.convert(amount, currency, resultCurrency); return CurrencyAmount.of(resultCurrency, converted); }
/** * Converts this amount to an equivalent amount the specified currency. * <p> * The result will be expressed in terms of the given currency. * If conversion is needed, the provider will be used to supply the FX rate. * * @param resultCurrency the currency of the result * @param rateProvider the provider of FX rates * @return the converted instance, which should be expressed in the specified currency * @throws RuntimeException if no FX rate could be found */ @Override public CurrencyAmount convertedTo(Currency resultCurrency, FxRateProvider rateProvider) { if (amounts.size() == 1) { return amounts.first().convertedTo(resultCurrency, rateProvider); } double total = 0d; for (CurrencyAmount amount : amounts) { total += rateProvider.convert(amount.getAmount(), amount.getCurrency(), resultCurrency); } return CurrencyAmount.of(resultCurrency, total); }