public void streamEntriesToMatrix() { // If we obtain a stream of rates we can collect to an fx matrix Map<CurrencyPair, Double> rates = ImmutableMap.<CurrencyPair, Double>builder() .put(CurrencyPair.of(GBP, USD), 1.6) .put(CurrencyPair.of(EUR, USD), 1.4) .put(CurrencyPair.of(CHF, AUD), 1.2) // Neither currency seen before .put(CurrencyPair.of(SEK, AUD), 0.1) // AUD seen before but not added yet .put(CurrencyPair.of(JPY, CAD), 0.0) // Neither currency seen before .put(CurrencyPair.of(EUR, CHF), 1.2) .put(CurrencyPair.of(JPY, USD), 0.008) .build(); FxMatrix matrix = rates.entrySet() .stream() .collect(entriesToFxMatrix()); assertThat(matrix.fxRate(GBP, USD)).isEqualTo(1.6); assertThat(matrix.fxRate(EUR, USD)).isEqualTo(1.4); }