/**
 * Copyright (C) 2015 - present by OpenGamma Inc. and the OpenGamma group of companies
 *
 * Please see distribution for license.
 */
package com.opengamma.strata.engine.marketdata;

import static com.opengamma.strata.collect.Guavate.toImmutableMap;

import java.time.LocalDate;
import java.util.Map;
import java.util.Set;

import com.opengamma.strata.basics.market.MarketDataId;
import com.opengamma.strata.basics.market.ObservableId;
import com.opengamma.strata.collect.timeseries.LocalDateDoubleTimeSeries;

/**
 * A interface for looking up items of market data by ID, used when building market data.
 */
public interface MarketDataLookup {

  /**
   * Checks if this set of data contains a value for the specified ID and it is of the expected type.
   *
   * @param id  an ID identifying an item of market data
   * @return true if this set of data contains a value for the specified ID and it is of the expected type
   */
  public abstract boolean containsValue(MarketDataId<?> id);

  /**
   * Checks if this set of data contains values for all the specified IDs with the expected types.
   *
   * @param ids  IDs of items of market data
   * @return true if this set of market data contains values for every ID and the values have the expected types
   */
  public default boolean containsValues(Set<? extends MarketDataId<?>> ids) {
    return ids.stream().allMatch(this::containsValue);
  }

  /**
   * Returns a market data value.
   * <p>
   * The date of the market data is the same as the valuation date of the calculations.
   *
   * @param <T>  type of the market data
   * @param id  ID of the market data
   * @return a market data value
   * @throws IllegalArgumentException if there is no value for the specified ID
   */
  public abstract <T> T getValue(MarketDataId<T> id);

  /**
   * Returns a map of market data values for a set of IDs.
   * <p>
   * The return value is guaranteed to contain a value for every ID. If any values are unavailable this
   * method throws {@code IllegalArgumentException}.
   *
   * @param <T>  type of the market data
   * @param <I>  type of the market data ID
   * @param ids  market data IDs
   * @return a map of market data values for the IDs
   * @throws IllegalArgumentException if there is no value for any of the IDs
   */
  public default <T, I extends MarketDataId<T>> Map<MarketDataId<?>, Object> getValues(Set<I> ids) {
    return ids.stream().collect(toImmutableMap(id -> id, this::getValue));
  }

  /**
   * Returns a map of observable market data values for a set of IDs.
   * <p>
   * The return value is guaranteed to contain a value for every ID. If any values are unavailable this
   * method throws {@code IllegalArgumentException}.
   *
   * @param ids  market data IDs
   * @return a map of market data values for the IDs
   * @throws IllegalArgumentException if there is no value for any of the IDs
   */
  public default Map<ObservableId, Double> getObservableValues(Set<? extends ObservableId> ids) {
    return ids.stream().collect(toImmutableMap(id -> id, this::getValue));
  }

  /**
   * Checks if this set of data contains a time series for the specified market data ID.
   *
   * @param id  an ID identifying an item of market data
   * @return true if this set of data contains a time series for the specified market data ID
   */
  public abstract boolean containsTimeSeries(ObservableId id);

  /**
   * Returns a time series of market data values.
   *
   * @param id  ID of the market data
   * @return a time series of market data values
   * @throws IllegalArgumentException if there is no time series for the specified ID
   */
  public abstract LocalDateDoubleTimeSeries getTimeSeries(ObservableId id);

  /**
   * Returns the valuation date of the market data.
   *
   * @return the valuation date of the market data
   */
  public LocalDate getValuationDate();
}

@@ -2035,93 +2035,8 @@
   *%0A
-   * @param %3CT%3E  type of the market data%0A   * @param %3CI%3E  type of the market data ID%0A
    *
@@ -2056,32 +2056,32 @@
 market data IDs%0A
+
    * @return a m
@@ -2221,39 +2221,8 @@
 ault
- %3CT, I extends MarketDataId%3CT%3E%3E
  Map
@@ -2265,17 +2265,88 @@
 Set%3C
-I%3E ids) %7B
+? extends MarketDataId%3C?%3E%3E ids) %7B%0A    // additional type information for Eclipse
 %0A   
@@ -2395,38 +2395,56 @@
 p(id -%3E id, 
-this::
+(MarketDataId%3C?%3E id) -%3E 
 getValue
 ));%0A  %7D%0A%0A  /
@@ -2423,32 +2423,36 @@
  id) -%3E getValue
+(id)
 ));%0A  %7D%0A%0A  /**%0A 

Enhance engine generics