/** * Creates an empty builder, used to create time-series. * <p> * The builder has methods to create and modify a time-series. * * @return the time-series builder */ public static LocalDateDoubleTimeSeriesBuilder builder() { return new LocalDateDoubleTimeSeriesBuilder(); }
@Override public LocalDateDoubleTimeSeriesBuilder toBuilder() { return new LocalDateDoubleTimeSeriesBuilder(dates, values); }
@Override public LocalDateDoubleTimeSeriesBuilder toBuilder() { return new LocalDateDoubleTimeSeriesBuilder(stream()); }
@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(); }
/** * 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(); }
/** * 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(); }