/** * Obtains the union of a pair of time series. * <p> * This returns a time-series with the union of the dates of the two inputs. * When the same date occurs in both time-series, the operator is invoked to combine the values. * * @param other the time-series to combine with * @param mapper the function to be used to combine the values * @return a new time-series containing the dates in common between the * input series with their values combined together using the function */ public default LocalDateDoubleTimeSeries union(LocalDateDoubleTimeSeries other, DoubleBinaryOperator mapper) { ArgChecker.notNull(other, "other"); ArgChecker.notNull(mapper, "mapper"); LocalDateDoubleTimeSeriesBuilder builder = new LocalDateDoubleTimeSeriesBuilder(stream()); other.stream().forEach(pt -> builder.merge(pt, mapper)); return builder.build(); }
public void test_merge_dateValue() { LocalDateDoubleTimeSeriesBuilder test = LocalDateDoubleTimeSeries.builder(); test.put(date(2013, 1, 1), 2d); test.merge(date(2013, 1, 1), 3d, Double::sum); assertEquals(test.get(date(2013, 1, 1)), OptionalDouble.of(5d)); }
public void test_merge_point() { LocalDateDoubleTimeSeriesBuilder test = LocalDateDoubleTimeSeries.builder(); test.put(date(2013, 1, 1), 2d); test.merge(LocalDateDoublePoint.of(date(2013, 1, 1), 3d), Double::sum); assertEquals(test.get(date(2013, 1, 1)), OptionalDouble.of(5d)); }