Class LocalDateDoubleTimeSeriesBuilder


  • public final class LocalDateDoubleTimeSeriesBuilder
    extends Object
    Builder to create the immutable LocalDateDoubleTimeSeries.

    This builder allows a time-series to be created. Entries can be added to the builder in any order. If a date is duplicated it will overwrite an earlier entry.

    Use LocalDateDoubleTimeSeries.builder() to create an instance.

    • Method Detail

      • get

        public OptionalDouble get​(LocalDate date)
        Gets the value associated with the specified date.

        The result is an OptionalDouble which avoids the need to handle null or exceptions. Use isPresent() to check whether the value is present. Use orElse(double) to default a missing value.

        Parameters:
        date - the date to get the value for
        Returns:
        the value associated with the date, optional empty if the date is not present
      • put

        public LocalDateDoubleTimeSeriesBuilder put​(LocalDate date,
                                                    double value)
        Puts the specified date/value point into this builder.
        Parameters:
        date - the date to be added
        value - the value associated with the date
        Returns:
        this builder
      • merge

        public LocalDateDoubleTimeSeriesBuilder merge​(LocalDate date,
                                                      double value,
                                                      DoubleBinaryOperator operator)
        Merges the specified date/value point into this builder.

        The operator is invoked if the date already exists.

        Parameters:
        date - the date to be added
        value - the value associated with the date
        operator - the operator to use for merging
        Returns:
        this builder
      • putAll

        public LocalDateDoubleTimeSeriesBuilder putAll​(Collection<LocalDate> dates,
                                                       Collection<Double> values)
        Puts all the specified dates and values into this builder.

        The date and value collections must be the same size.

        The date-value pairs are added one by one. If a date is duplicated it will overwrite an earlier entry.

        Parameters:
        dates - the dates to be added
        values - the values to be added
        Returns:
        this builder
      • putAll

        public LocalDateDoubleTimeSeriesBuilder putAll​(Collection<LocalDate> dates,
                                                       double[] values)
        Puts all the specified dates and values into this builder.

        The date collection and value array must be the same size.

        The date-value pairs are added one by one. If a date is duplicated it will overwrite an earlier entry.

        Parameters:
        dates - the dates to be added
        values - the values to be added
        Returns:
        this builder
      • putAll

        public LocalDateDoubleTimeSeriesBuilder putAll​(Stream<LocalDateDoublePoint> points)
        Puts all the specified points into this builder.

        The points are added one by one. If a date is duplicated it will overwrite an earlier entry.

        Parameters:
        points - the points to be added
        Returns:
        this builder
      • putAll

        public LocalDateDoubleTimeSeriesBuilder putAll​(List<LocalDateDoublePoint> points)
        Puts all the specified points into this builder.

        The points are added one by one. If a date is duplicated it will overwrite an earlier entry.

        Parameters:
        points - the points to be added
        Returns:
        this builder
      • putAll

        public LocalDateDoubleTimeSeriesBuilder putAll​(Map<LocalDate,​Double> map)
        Puts all the entries from the supplied map into this builder.

        If a date is duplicated it will overwrite an earlier entry.

        Parameters:
        map - the map of points to be added
        Returns:
        this builder
      • build

        public LocalDateDoubleTimeSeries build()
        Build the time-series from the builder.
        Returns:
        a time-series containing the entries from the builder