FXMatrix implements Serializable { public CurrencyAmount convert(final MultipleCurrencyAmount amount, final Currency ccy) { ArgumentChecker.notNull(amount, "amount"); double conversion = 0; final CurrencyAmount[] ca = amount.getCurrencyAmounts(); for (final CurrencyAmount element : ca) { conversion += element.getAmount() * getFxRate(element.getCurrency(), ccy); } return CurrencyAmount.of(ccy, conversion); } FXMatrix();  FXMatrix(final Currency ccy);  FXMatrix(final Currency ccy1, final Currency ccy2, final double fxRate);  FXMatrix(final Map<Currency, Integer> currencies, final double[][] fxRates);  FXMatrix(final FXMatrix fxMatrix); void addCurrency(final Currency ccyToAdd, final Currency ccyReference, final double fxRate); double getFxRate(final Currency ccy1, final Currency ccy2); boolean containsPair(final Currency ccy1, final Currency ccy2); CurrencyAmount convert(final MultipleCurrencyAmount amount, final Currency ccy); void updateRates(final Currency ccyToUpdate, final Currency ccyReference, final double fxRate); Map<Currency, Integer> getCurrencies(); double[][] getRates(); int getNumberOfCurrencies(); @Override String toString(); @Override int hashCode(); @Override boolean equals(final Object obj);  }
@Test public void convert() { final FXMatrix fxMatrix = new FXMatrix(); fxMatrix.addCurrency(EUR, USD, EUR_USD); fxMatrix.addCurrency(GBP, EUR, GBP_EUR); final double amountGBP = 1.0; final double amountEUR = 2.0; final double amountUSD = 3.0; MultipleCurrencyAmount amount = MultipleCurrencyAmount.of(GBP, amountGBP); amount = amount.plus(EUR, amountEUR); amount = amount.plus(USD, amountUSD); final CurrencyAmount totalUSDCalculated = fxMatrix.convert(amount, USD); final double totalUSDExpected = amountUSD + amountEUR * EUR_USD + amountGBP * GBP_EUR * EUR_USD; assertEquals("FXMatrix - convert", totalUSDExpected, totalUSDCalculated.getAmount(), 1.0E-10); assertEquals("FXMatrix - convert", USD, totalUSDCalculated.getCurrency()); }