Class LocalDateDoubleTimeSeriesBuilder


  • public final class LocalDateDoubleTimeSeriesBuilder
    extends java.lang.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 java.util.OptionalDouble get​(java.time.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​(java.time.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​(java.time.LocalDate date,
                                                      double value,
                                                      java.util.function.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
      • merge

        public LocalDateDoubleTimeSeriesBuilder merge​(LocalDateDoublePoint point,
                                                      java.util.function.DoubleBinaryOperator operator)
        Merges the specified date/value point into this builder.

        The operator is invoked if the date already exists.

        Parameters:
        point - the point to be added
        operator - the operator to use for merging
        Returns:
        this builder
      • putAll

        public LocalDateDoubleTimeSeriesBuilder putAll​(java.util.Collection<java.time.LocalDate> dates,
                                                       java.util.Collection<java.lang.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​(java.util.Collection<java.time.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​(java.util.stream.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​(java.util.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​(java.util.Map<java.time.LocalDate,​java.lang.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