public void streamPairsToMatrix() { // If we obtain a stream of pairs with rates we can stream them // This could happen if an entry set undergoes a map operation 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() .map(e -> Pair.of(e.getKey(), e.getValue() * 1.01)) // Apply some shift .collect(pairsToFxMatrix()); assertThat(matrix.fxRate(GBP, USD)).isEqualTo(1.616); assertThat(matrix.fxRate(EUR, USD)).isEqualTo(1.414); }