/** * Merges the entries from the other matrix into this one. * <p> * The other matrix should have at least one currency in common with this one. * The additional currencies from the other matrix are added one by one and * the exchange rate data created is coherent with some data in this matrix. * <p> * Note that if the other matrix has more than one currency in common with * this one, and the rates for pairs of those currencies are different to * the equivalents in this matrix, then the rates between the additional * currencies is this matrix will differ from those in the original. * * @param other the matrix to be merged into this one * @return a new matrix containing the rates from this matrix * plus any rates for additional currencies from the other matrix */ public FxMatrix merge(FxMatrix other) { return toBuilder().merge(other.toBuilder()).build(); }
public void rateCanBeUpdatedWithDirectionSwitched() { FxMatrix matrix1 = FxMatrix.builder() .addRate(GBP, USD, 1.6) .build(); assertThat(matrix1.getCurrencies()).hasSize(2); assertThat(matrix1.fxRate(GBP, USD)).isEqualTo(1.6); FxMatrix matrix2 = matrix1.toBuilder() .addRate(USD, GBP, 0.625) .build(); assertThat(matrix2.getCurrencies()).hasSize(2); assertThat(matrix2.fxRate(GBP, USD)).isEqualTo(1.6); }
public void ratedCanBeUpdatedAndAddedViaBuilder() { FxMatrix matrix1 = FxMatrix.builder() .addRate(GBP, USD, 1.5) .build(); assertThat(matrix1.getCurrencies()).containsOnly(GBP, USD); assertThat(matrix1.fxRate(GBP, USD)).isEqualTo(1.5); FxMatrix matrix2 = matrix1.toBuilder() .addRate(GBP, USD, 1.6) .addRate(EUR, USD, 1.4) .build(); assertThat(matrix2.getCurrencies()).containsOnly(GBP, USD, EUR); assertThat(matrix2.fxRate(GBP, USD)).isEqualTo(1.6); assertThat(matrix2.fxRate(EUR, USD)).isEqualTo(1.4); }