/** * Returns a multi currency amount array representing the total of the input arrays. * <p> * If the input contains the same currency more than once, the amounts are added together. * * @param arrays the amount arrays * @return the total amounts */ public static MultiCurrencyAmountArray total(Iterable<CurrencyAmountArray> arrays) { return Guavate.stream(arrays).collect(toMultiCurrencyAmountArray()); }
public void collectorDifferentArrayLengths() { List<CurrencyAmountArray> arrays = ImmutableList.of( CurrencyAmountArray.of(USD, DoubleArray.of(10, 20, 30)), CurrencyAmountArray.of(GBP, DoubleArray.of(1, 2))); assertThrowsIllegalArg(() -> arrays.stream().collect(toMultiCurrencyAmountArray())); }
public void collector() { List<CurrencyAmountArray> arrays = ImmutableList.of( CurrencyAmountArray.of(USD, DoubleArray.of(10, 20, 30)), CurrencyAmountArray.of(USD, DoubleArray.of(5, 6, 7)), CurrencyAmountArray.of(EUR, DoubleArray.of(2, 4, 6)), CurrencyAmountArray.of(GBP, DoubleArray.of(11, 12, 13)), CurrencyAmountArray.of(GBP, DoubleArray.of(1, 2, 3))); Map<Currency, DoubleArray> expectedMap = ImmutableMap.of( USD, DoubleArray.of(15, 26, 37), EUR, DoubleArray.of(2, 4, 6), GBP, DoubleArray.of(12, 14, 16)); MultiCurrencyAmountArray expected = MultiCurrencyAmountArray.of(expectedMap); assertThat(arrays.stream().collect(toMultiCurrencyAmountArray())).isEqualTo(expected); }