/** * Returns a copy of this point with another value. * * @param value the value to change the point to * @return a point based on this point with the value changed */ public LocalDateDoublePoint withValue(double value) { return LocalDateDoublePoint.of(date, value); }
/** * Obtains a point from date and value. * * @param date the date * @param value the value * @return the point */ public static LocalDateDoublePoint of(LocalDate date, double value) { return new LocalDateDoublePoint(date, value); }
public void test_equalsHashCode_differentValues() { LocalDateDoublePoint a1 = LocalDateDoublePoint.of(DATE_2012_06_29, 1d); LocalDateDoublePoint a2 = LocalDateDoublePoint.of(DATE_2012_06_29, 1d); LocalDateDoublePoint b = LocalDateDoublePoint.of(DATE_2012_06_29, 2d); LocalDateDoublePoint c = LocalDateDoublePoint.of(DATE_2012_06_29, 3d); assertEquals(a1.equals(a1), true); assertEquals(a1.equals(a2), true); assertEquals(a1.equals(b), false); assertEquals(a1.equals(c), false); assertEquals(a1.hashCode(), a1.hashCode()); }
public void test_compareTo() { LocalDateDoublePoint a = LocalDateDoublePoint.of(DATE_2012_06_29, 1d); LocalDateDoublePoint b = LocalDateDoublePoint.of(DATE_2012_06_30, 1d); LocalDateDoublePoint c = LocalDateDoublePoint.of(DATE_2012_07_01, 1d); assertTrue(a.compareTo(a) == 0); assertTrue(a.compareTo(b) < 0); assertTrue(a.compareTo(c) < 0); assertTrue(b.compareTo(a) > 0); assertTrue(b.compareTo(b) == 0); assertTrue(b.compareTo(c) < 0); assertTrue(c.compareTo(a) > 0); assertTrue(c.compareTo(b) > 0); assertTrue(c.compareTo(c) == 0); }
public void test_stream_withCollector() { LocalDateDoubleTimeSeries base = LocalDateDoubleTimeSeries.builder().putAll(DATES_2010_12, VALUES_10_12).build(); LocalDateDoubleTimeSeries test = base.stream() .map(point -> point.withValue(1.5d)) .collect(LocalDateDoubleTimeSeries.collector()); assertEquals(test.size(), 3); assertEquals(test.get(DATE_2010_01_01), OptionalDouble.of(1.5)); assertEquals(test.get(DATE_2011_01_01), OptionalDouble.of(1.5)); assertEquals(test.get(DATE_2012_01_01), OptionalDouble.of(1.5)); }
/** * Obtains the intersection of a pair of time series. * <p> * This returns a time-series with the intersection of the dates of the two inputs. * 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 intersection(LocalDateDoubleTimeSeries other, DoubleBinaryOperator mapper) { ArgChecker.notNull(other, "other"); ArgChecker.notNull(mapper, "mapper"); return new LocalDateDoubleTimeSeriesBuilder() .putAll(stream() .filter(pt -> other.containsDate(pt.getDate())) .map(pt -> LocalDateDoublePoint.of( pt.getDate(), mapper.applyAsDouble(pt.getValue(), other.get(pt.getDate()).getAsDouble())))) .build(); }
public void test_equalsHashCode_differentDates() { LocalDateDoublePoint a1 = LocalDateDoublePoint.of(DATE_2012_06_29, 1d); LocalDateDoublePoint a2 = LocalDateDoublePoint.of(DATE_2012_06_29, 1d); LocalDateDoublePoint b = LocalDateDoublePoint.of(DATE_2012_06_30, 1d); LocalDateDoublePoint c = LocalDateDoublePoint.of(DATE_2012_07_01, 1d); assertEquals(a1.equals(a1), true); assertEquals(a1.equals(a2), true); assertEquals(a1.equals(b), false); assertEquals(a1.equals(c), false); assertEquals(a1.hashCode(), a1.hashCode()); }
public void test_stream_withCollector() { LocalDateDoubleTimeSeries base = LocalDateDoubleTimeSeries.builder().putAll(DATES_2010_12, VALUES_10_12).build(); LocalDateDoubleTimeSeries test = base.stream() .map(point -> point.withValue(1.5d)) .collect(LocalDateDoubleTimeSeries.collector()); assertEquals(test.size(), 3); assertEquals(test.get(DATE_2010_01_01), OptionalDouble.of(1.5)); assertEquals(test.get(DATE_2011_01_01), OptionalDouble.of(1.5)); assertEquals(test.get(DATE_2012_01_01), OptionalDouble.of(1.5)); }
/** * Returns a copy of this point with another date. * * @param date the date to change the point to * @return a point based on this point with the date changed */ public LocalDateDoublePoint withDate(LocalDate date) { return LocalDateDoublePoint.of(date, value); }
/** * Merges the specified date/value point into this builder. * <p> * The operator is invoked if the date already exists. * * @param point the point to be added * @param operator the operator to use for merging * @return this builder */ public LocalDateDoubleTimeSeriesBuilder merge(LocalDateDoublePoint point, DoubleBinaryOperator operator) { ArgChecker.notNull(point, "point"); entries.merge(point.getDate(), point.getValue(), (a, b) -> operator.applyAsDouble(a, b)); return this; }
private Stream<LocalDateDoublePoint> streamEntries() { return entries.entrySet() .stream() .map(e -> LocalDateDoublePoint.of(e.getKey(), e.getValue())); }
@Override public LocalDateDoubleTimeSeries filter(ObjDoublePredicate<LocalDate> predicate) { Stream<LocalDateDoublePoint> filteredPoints = stream().filter(pt -> predicate.test(pt.getDate(), pt.getValue())); // As we may have changed the density of the series by filtering // go via the builder to get the best implementation return new LocalDateDoubleTimeSeriesBuilder(filteredPoints).build(); }