private void ensureCapacity(int requiredOrder) { if (requiredOrder > rates.length) { rates = copyArray(rates, size(requiredOrder)); } }
/** * Build a new {@code FxMatrix} from the data in the builder. * * @return a new {@code FxMatrix} * @throws IllegalStateException if an attempt was made to add currencies * which have no currency in common with other rates */ public FxMatrix build() { if (!disjointRates.isEmpty()) { throw new IllegalStateException("Received rates with no currencies in common with other: " + disjointRates); } // Trim array down to the correct size - we have to copy the array // anyway to ensure immutability, so we may as well remove any // unused rows return new FxMatrix(ImmutableMap.copyOf(currencies), DoubleMatrix.ofUnsafe(copyArray(rates, currencies.size()))); }
FxMatrixBuilder(ImmutableMap<Currency, Integer> currencies, double[][] rates) { this.currencies = new LinkedHashMap<>(currencies); // Ensure there is space to add at least one new currency this.rates = copyArray(rates, size(currencies.size() + 1)); }