/** * Returns a copy of this market data with the specified value. * <p> * When the result is queried for the specified identifier, the specified value will be returned. * <p> * For example, this method could be used to replace a curve with a bumped curve. * * @param <T> the type of the market data value * @param id the identifier to find * @param value the value to associate with the identifier * @return the derived market data with the specified identifier and value */ public default <T> MarketData withValue(MarketDataId<T> id, T value) { return ExtendedMarketData.of(id, value, this); }
/** * Obtains an instance that decorates the underlying market data. * <p> * The specified identifier can be queried in the result, returning the specified value. * All other identifiers are queried in the underlying market data. * * @param id the additional market data identifier * @param value the additional market data value * @param underlying the underlying market data * @return a market data instance that decorates the original adding/overriding the specified identifier */ public static <T> ExtendedMarketData<T> of(MarketDataId<T> id, T value, MarketData underlying) { return new ExtendedMarketData<T>(id, value, underlying); }
public void of_override() { ExtendedMarketData<String> test = ExtendedMarketData.of(ID1, VAL3, BASE_DATA); assertEquals(test.getId(), ID1); assertEquals(test.getValue(), VAL3); assertEquals(test.getValuationDate(), VAL_DATE); assertEquals(test.containsValue(ID1), true); assertEquals(test.containsValue(ID2), true); assertEquals(test.containsValue(ID3), false); assertEquals(test.getValue(ID1), VAL3); assertEquals(test.getValue(ID2), VAL2); assertThrows(() -> test.getValue(ID3), MarketDataNotFoundException.class); assertEquals(test.findValue(ID1), Optional.of(VAL3)); assertEquals(test.findValue(ID2), Optional.of(VAL2)); assertEquals(test.findValue(ID3), Optional.empty()); assertEquals(test.getIds(), ImmutableSet.of(ID1, ID2)); assertEquals(test.getTimeSeries(ID4), TIME_SERIES); }
/** * Tests the combinedWith method when the MarketData instances are not both ImmutableMarketData. */ public void test_combinedWith_differentTypes() { Map<MarketDataId<?>, Object> dataMap1 = ImmutableMap.of(ID1, VAL1, ID2, VAL2); MarketData test1 = MarketData.of(VAL_DATE, dataMap1); Map<MarketDataId<?>, Object> dataMap2 = ImmutableMap.of(ID1, VAL1); MarketData test2 = MarketData.of(VAL_DATE, dataMap2); ExtendedMarketData<String> test3 = ExtendedMarketData.of(ID1, VAL3, test2); MarketData test = test3.combinedWith(test1); assertEquals(test.getValue(ID1), VAL3); assertEquals(test.getValue(ID2), VAL2); assertEquals(test.getIds(), ImmutableSet.of(ID1, ID2)); }
public void of_addition() { ExtendedMarketData<String> test = ExtendedMarketData.of(ID3, VAL3, BASE_DATA); assertEquals(test.getId(), ID3); assertEquals(test.getValue(), VAL3); assertEquals(test.getValuationDate(), VAL_DATE); assertEquals(test.containsValue(ID1), true); assertEquals(test.containsValue(ID2), true); assertEquals(test.containsValue(ID3), true); assertEquals(test.containsValue(ID4), false); assertEquals(test.getValue(ID1), VAL1); assertEquals(test.getValue(ID2), VAL2); assertEquals(test.getValue(ID3), VAL3); assertThrows(() -> test.getValue(ID4), MarketDataNotFoundException.class); assertEquals(test.findValue(ID1), Optional.of(VAL1)); assertEquals(test.findValue(ID2), Optional.of(VAL2)); assertEquals(test.findValue(ID3), Optional.of(VAL3)); assertEquals(test.findValue(ID4), Optional.empty()); assertEquals(test.getIds(), ImmutableSet.of(ID1, ID2, ID3)); assertEquals(test.findIds(ID1.getMarketDataName()), ImmutableSet.of(ID1)); assertEquals(test.findIds(ID3.getMarketDataName()), ImmutableSet.of(ID3)); assertEquals(test.getTimeSeries(ID4), TIME_SERIES); }
public void serialization() { ExtendedMarketData<String> test = ExtendedMarketData.of(ID1, VAL3, BASE_DATA); assertSerialization(test); }