/** * Returns a set of market data built from the data in this builder. * * @return a set of market data built from the data in this builder */ public ImmutableMarketData build() { return new ImmutableMarketData(valuationDate, values, timeSeries); }
@Override public ImmutableMarketData build() { return new ImmutableMarketData( valuationDate, values, timeSeries); }
/** * Combines this set of market data with another. * <p> * The result combines both sets of market data. * Values are taken from this set of market data if available, otherwise they are taken * from the other set. * <p> * The valuation dates of the sets of market data must be the same. * * @param other the other market data * @return the combined market data */ public ImmutableMarketData combinedWith(ImmutableMarketData other) { Map<MarketDataId<?>, Object> combinedValues = new HashMap<>(other.values); combinedValues.putAll(values); HashMap<ObservableId, LocalDateDoubleTimeSeries> combinedTimeSeries = new HashMap<>(other.timeSeries); combinedTimeSeries.putAll(timeSeries); if (!valuationDate.equals(other.valuationDate)) { throw new IllegalArgumentException("Unable to combine market data instances with different valuation dates"); } return new ImmutableMarketData(valuationDate, combinedValues, combinedTimeSeries); }
/** * 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()); }