public interface LocalDateDoubleTimeSeries
double
values.
A timeseries is similar to both a SortedMap
of value keyed
by datetime and a List
of datetime to value pairs. As such,
the date/times do not have to be evenly spread over time within the series.
The distribution of the data will influence which implementation is most appropriate.
Implementations must be immutable and threadsafe beans.
Note that Double.NaN
is used internally as a sentinel
value and is therefore not allowed as a value.
Modifier and Type  Method and Description 

static LocalDateDoubleTimeSeriesBuilder 
builder()
Creates an empty builder, used to create timeseries.

static Collector<LocalDateDoublePoint,LocalDateDoubleTimeSeriesBuilder,LocalDateDoubleTimeSeries> 
collector()
Returns a collector that can be used to create a timeseries from a stream of points.

boolean 
containsDate(LocalDate date)
Checks if this timeseries contains a value for the specified date.

Stream<LocalDate> 
dates()
Returns a stream over the dates of this timeseries.

static LocalDateDoubleTimeSeries 
empty()
Returns an empty timeseries.

LocalDateDoubleTimeSeries 
filter(ObjDoublePredicate<LocalDate> predicate)
Create a new timeseries by filtering this one.

void 
forEach(ObjDoubleConsumer<LocalDate> action)
Applies an action to each pair in the time series.

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

default LocalDate 
getEarliestDate()
Get the earliest date contained in this timeseries.

default double 
getEarliestValue()
Get the value held for the earliest date contained in this timeseries.

LocalDate 
getLatestDate()
Get the latest date contained in this timeseries.

double 
getLatestValue()
Get the value held for the latest date contained in this timeseries.

LocalDateDoubleTimeSeries 
headSeries(int numPoints)
Gets part of this series as a subseries, choosing the earliest entries.

default LocalDateDoubleTimeSeries 
intersection(LocalDateDoubleTimeSeries other,
DoubleBinaryOperator mapper)
Obtains the intersection of a pair of time series.

boolean 
isEmpty()
Indicates if this timeseries is empty.

LocalDateDoubleTimeSeries 
mapDates(Function<? super LocalDate,? extends LocalDate> mapper)
Applies an operation to each date in the time series which creates a new date, returning a new time series
with the new dates and the points from this time series.

LocalDateDoubleTimeSeries 
mapValues(DoubleUnaryOperator mapper)
Applies an operation to each value in the time series.

static LocalDateDoubleTimeSeries 
of(LocalDate date,
double value)
Obtains a timeseries containing a single date and value.

default Pair<LocalDateDoubleTimeSeries,LocalDateDoubleTimeSeries> 
partition(ObjDoublePredicate<LocalDate> predicate)
Partition the timeseries into a pair of distinct series using a predicate.

default Pair<LocalDateDoubleTimeSeries,LocalDateDoubleTimeSeries> 
partitionByValue(DoublePredicate predicate)
Partition the timeseries into a pair of distinct series using a predicate.

int 
size()
Return the size of this timeseries.

Stream<LocalDateDoublePoint> 
stream()
Returns a stream over the points of this timeseries.

LocalDateDoubleTimeSeries 
subSeries(LocalDate startInclusive,
LocalDate endExclusive)
Gets part of this series as a subseries between two dates.

LocalDateDoubleTimeSeries 
tailSeries(int numPoints)
Gets part of this series as a subseries, choosing the latest entries.

LocalDateDoubleTimeSeriesBuilder 
toBuilder()
Return a builder populated with the values from this series.

default LocalDateDoubleTimeSeries 
union(LocalDateDoubleTimeSeries other,
DoubleBinaryOperator mapper)
Obtains the union of a pair of time series.

DoubleStream 
values()
Returns a stream over the values of this timeseries.

static LocalDateDoubleTimeSeries empty()
static LocalDateDoubleTimeSeries of(LocalDate date, double value)
date
 the singleton datevalue
 the singleton valuestatic LocalDateDoubleTimeSeriesBuilder builder()
The builder has methods to create and modify a timeseries.
static Collector<LocalDateDoublePoint,LocalDateDoubleTimeSeriesBuilder,LocalDateDoubleTimeSeries> collector()
int size()
boolean isEmpty()
boolean containsDate(LocalDate date)
date
 the date to check forOptionalDouble get(LocalDate 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.
date
 the date to get the value fordefault LocalDate getEarliestDate()
If the timeseries is empty then NoSuchElementException
will be thrown.
NoSuchElementException
 if the timeseries is emptydefault double getEarliestValue()
If the timeseries is empty then NoSuchElementException
will be thrown.
NoSuchElementException
 if the timeseries is emptyLocalDate getLatestDate()
If the timeseries is empty then NoSuchElementException
will be thrown.
NoSuchElementException
 if the timeseries is emptydouble getLatestValue()
If the timeseries is empty then NoSuchElementException
will be thrown.
NoSuchElementException
 if the timeseries is emptyLocalDateDoubleTimeSeries subSeries(LocalDate startInclusive, LocalDate endExclusive)
The datetimes do not have to match exactly. The subseries contains all entries between the two dates using a halfopen interval. The start date is included, the end date is excluded. The dates may be before or after the end of the timeseries.
To obtain the series before a specific date, used LocalDate.MIN
as the first argument.
To obtain the series from a specific date, used LocalDate.MAX
as the second argument.
startInclusive
 the start date, inclusiveendExclusive
 the end date, exclusiveIllegalArgumentException
 if the end is before the startLocalDateDoubleTimeSeries headSeries(int numPoints)
The subseries contains the earliest part of the series up to the specified number of points. If the series contains less points than the number requested, the whole timeseries is returned.
numPoints
 the number of items to select, zero or greaterIllegalArgumentException
 if the number of items is less than zeroLocalDateDoubleTimeSeries tailSeries(int numPoints)
The subseries contains the latest part of the series up to the specified number of points. If the series contains less points than the number requested, the whole timeseries is returned.
numPoints
 the number of items to select, zero or greaterIllegalArgumentException
 if the number of items is less than zeroStream<LocalDateDoublePoint> stream()
This provides access to the entire timeseries.
Stream<LocalDate> dates()
This is most useful to summarize the dates in the stream, such as calculating the maximum or minimum date, or searching for a specific value.
DoubleStream values()
This is most useful to summarize the values in the stream, such as calculating the maximum, minimum or average value, or searching for a specific value.
void forEach(ObjDoubleConsumer<LocalDate> action)
This is generally used to apply a mathematical operation to the values. For example, the operator could multiply each value by a constant, or take the inverse.
base.forEach((date, value) > System.out.println(date + "=" + value));
action
 the action to be applied to each pairLocalDateDoubleTimeSeries mapDates(Function<? super LocalDate,? extends LocalDate> mapper)
This operation creates a new time series with the same data but the dates moved.
The operation must not change the dates in a way that reorders them. The mapped dates must be in ascending order or an exception is thrown.
updatedSeries = timeSeries.mapDates(date > date.plusYears(1));
mapper
 the operation applied to each date in the time seriesLocalDateDoubleTimeSeries mapValues(DoubleUnaryOperator mapper)
This is generally used to apply a mathematical operation to the values. For example, the operator could multiply each value by a constant, or take the inverse.
multiplied = base.mapValues(value > value * 3);
mapper
 the operator to be applied to the valuesLocalDateDoubleTimeSeries filter(ObjDoublePredicate<LocalDate> predicate)
The timeseries can be filtered by both date and value.
Note that if filtering by date range is required, it is likely to be more efficient to
use subSeries(LocalDate, LocalDate)
as that avoids traversal of the whole series.
predicate
 the predicate to use to the filter the elements of the seriesdefault LocalDateDoubleTimeSeries intersection(LocalDateDoubleTimeSeries other, DoubleBinaryOperator mapper)
This returns a timeseries with the intersection of the dates of the two inputs. The operator is invoked to combine the values.
other
 the timeseries to combine withmapper
 the function to be used to combine the valuesdefault LocalDateDoubleTimeSeries union(LocalDateDoubleTimeSeries other, DoubleBinaryOperator mapper)
This returns a timeseries with the union of the dates of the two inputs. When the same date occurs in both timeseries, the operator is invoked to combine the values.
other
 the timeseries to combine withmapper
 the function to be used to combine the valuesdefault Pair<LocalDateDoubleTimeSeries,LocalDateDoubleTimeSeries> partition(ObjDoublePredicate<LocalDate> predicate)
Points in the timeseries which match the predicate will be put into the first series, whilst those points which do not match will be put into the second.
predicate
 predicate used to test the points in the timeseriesPair
containing two timeseries. The first is a series
made of all the points in this series which match the predicate. The
second is a series made of the points which do not match.default Pair<LocalDateDoubleTimeSeries,LocalDateDoubleTimeSeries> partitionByValue(DoublePredicate predicate)
Points in the timeseries whose values match the predicate will be put into the first series, whilst those points whose values do not match will be put into the second.
predicate
 predicate used to test the points in the timeseriesPair
containing two timeseries. The first is a series
made of all the points in this series which match the predicate. The
second is a series made of the points which do not match.LocalDateDoubleTimeSeriesBuilder toBuilder()
This can be used to mutate the timeseries.
Copyright 2009Present by OpenGamma Inc. and individual contributors
Apache v2 licensed
Additional documentation can be found at strata.opengamma.io.