FxMatrixBuilder merge(FxMatrixBuilder other) { // Find the common currencies Optional<Currency> common = currencies.keySet() .stream() .filter(other.currencies::containsKey) .findFirst(); Currency commonCurrency = common.orElseThrow(() -> new IllegalArgumentException( "There are no currencies in common between " + currencies.keySet() + " and " + other.currencies.keySet())); // Add in all currencies that we don't already have MapStream.of(other.currencies) .filterKeys(ccy -> !ccy.equals(commonCurrency) && !currencies.containsKey(ccy)) .forEach((ccy, idx) -> addCurrencyPair(commonCurrency, ccy, other.getRate(commonCurrency, ccy))); return this; }
MapStream.empty().toArray(); MapStream.empty().toArray(i -> new Object[0]); MapStream.empty().forEach(e -> System.out.println()); MapStream.empty().forEachOrdered(e -> System.out.println()); MapStream.empty().reduce(new AbstractMap.SimpleEntry<>(null, null), (o1, o2) -> null);
/** * Maps the sensitivity metadata. * * @return this, for chaining */ CurrencyParameterSensitivityBuilder mapMetadata(UnaryOperator<ParameterMetadata> metadataFn) { ImmutableMap<ParameterMetadata, Double> base = ImmutableMap.copyOf(sensitivity); sensitivity.clear(); MapStream.of(base) .mapKeys(metadataFn) .forEach((md, v) -> add(md, v)); return this; }
/** * Obtains an instance from a valuation date and map of values. * <p> * Use the {@linkplain #builder(LocalDate) builder} for more more complex use cases, * including setting time-series. * * @param valuationDate the valuation date associated with the market data * @param values the market data values * @return a set of market data containing the values in the map * @throws ClassCastException if a value does not match the parameterized type associated with the identifier */ public static ImmutableMarketData of(LocalDate valuationDate, Map<? extends MarketDataId<?>, ?> values) { MapStream.of(values).forEach((id, value) -> checkType(id, value)); return new ImmutableMarketData(valuationDate, values, ImmutableMap.of()); }
/** * Adds multiple shifts to the builder. * * @param scenarioIndex the index of the scenario containing the shifts * @param shiftMap the shift amounts, keyed by the identifier of the node to which they should be applied * @return this builder */ public PointShiftsBuilder addShifts(int scenarioIndex, Map<?, Double> shiftMap) { ArgChecker.notNull(shiftMap, "shiftMap"); ArgChecker.notNegative(scenarioIndex, "scenarioIndex"); MapStream.of(shiftMap).forEach((id, shift) -> shifts.put(Pair.of(scenarioIndex, id), shift)); return this; }
/** * Adds a collection of new rates for currency pairs to the builder. * Pairs that are already in the builder are treated as updates to the * existing rates -> !e.getKey().equals(commonCurrency) && !currencies.containsKey(e.getKey()) * * @param rates the currency pairs and rates to be added * @return the builder updated with the new rates */ public FxMatrixBuilder addRates(Map<CurrencyPair, Double> rates) { ArgChecker.notNull(rates, "rates"); if (!rates.isEmpty()) { ensureCapacity(rates.keySet().stream() .flatMap(cp -> Stream.of(cp.getBase(), cp.getCounter()))); MapStream.of(rates).forEach((pair, rate) -> addRate(pair, rate)); } return this; }
public void forEach() { HashMap<Object, Object> mutableMap = new HashMap<>(); MapStream.of(map).forEach((k, v) -> mutableMap.put(k, v)); assertThat(mutableMap).isEqualTo(map); }
private void retryDisjoints() { ensureCapacity(disjointRates.keySet() .stream() .flatMap(cp -> Stream.of(cp.getBase(), cp.getCounter()))); while (true) { int initialSize = disjointRates.size(); ImmutableMap<CurrencyPair, Double> addable = MapStream.of(disjointRates) .filterKeys(pair -> currencies.containsKey(pair.getBase()) || currencies.containsKey(pair.getCounter())) .toMap(); MapStream.of(addable).forEach((pair, rate) -> addNewRate(pair.getBase(), pair.getCounter(), rate)); addable.keySet().stream().forEach(disjointRates::remove); if (disjointRates.size() == initialSize) { // No effect so break out break; } } }
/** * Obtains an instance from a valuation date, map of values and time-series. * <p> * The valuation date and map of values must have the same number of scenarios. * * @param scenarioCount the number of scenarios * @param valuationDate the valuation dates associated with the market data, one for each scenario * @param values the market data values, one for each scenario * @param timeSeries the time-series * @return a set of market data containing the values in the map */ public static ImmutableScenarioMarketData of( int scenarioCount, MarketDataBox<LocalDate> valuationDate, Map<? extends MarketDataId<?>, MarketDataBox<?>> values, Map<? extends ObservableId, LocalDateDoubleTimeSeries> timeSeries) { MapStream.of(values).forEach((key, value) -> checkType(key, value, scenarioCount)); return new ImmutableScenarioMarketData(scenarioCount, valuationDate, values, timeSeries); }
/** * Adds a sensitivity to the builder. * <p> * Values with the same market data name and currency will be merged. * * @param sensToAdd the sensitivity to add * @return this, for chaining */ public CurrencyParameterSensitivitiesBuilder add(CurrencyParameterSensitivity sensToAdd) { sensToAdd.sensitivities() .forEach((md, value) -> add(sensToAdd.getMarketDataName(), sensToAdd.getCurrency(), md, value)); return this; }
.mapKeys((type, sens) -> Pair.of(sens.getMarketDataName().getName(), type)) .sortedKeys() .forEach((pair, paramSens) -> write( pair.getFirst(), pair.getSecond(), curveSens, paramSens, additionalHeaders, containsDates, csv));