LocalDate start, boolean includeStart, LocalDate end, boolean includeEnd, Integer maxPoints) {
HistoricalTimeSeriesKey seriesKey = new HistoricalTimeSeriesKey(resolutionKey, identifierValidityDate, identifierBundle, null, null, dataField);
SubSeriesKey subseriesKey = new SubSeriesKey(start, end, maxPoints);
ObjectsPair<HistoricalTimeSeriesKey, SubSeriesKey> key = Pair.of(seriesKey, subseriesKey);
Element element = _dataCache.get(key);
HistoricalTimeSeries hts;
if (element != null) {
hts = (HistoricalTimeSeries) element.getObjectValue();
if (MISS.equals(hts)) {
hts = null;
} else if (!subseriesKey.isMatch(start, includeStart, end, includeEnd, maxPoints)) {
// Pick out the sub-series requested
hts = getSubSeries(hts, start, includeStart, end, includeEnd, maxPoints);
}
} else {
// If we have the full series cached computing a sub-series could be faster
Element fullHtsElement = _dataCache.get(seriesKey);
if (fullHtsElement != null) {
hts = getSubSeries((HistoricalTimeSeries) fullHtsElement.getObjectValue(), start, includeStart, end, includeEnd, maxPoints);
} else {
if (maxPoints == null) {
hts = _underlying.getHistoricalTimeSeries(dataField, identifierBundle, identifierValidityDate, resolutionKey, subseriesKey.getStart(), true, subseriesKey.getEnd(),
subseriesKey.getIncludeEnd());
} else {
hts = _underlying.getHistoricalTimeSeries(dataField, identifierBundle, identifierValidityDate, resolutionKey, subseriesKey.getStart(), true, subseriesKey.getEnd(),
subseriesKey.getIncludeEnd(), subseriesKey.getMaxPoints());
}
if (hts != null) {
s_logger.debug("Caching sub time-series {}", hts);
_dataCache.put(new Element(key, hts));
_dataCache.put(new Element(new ObjectsPair<UniqueId, SubSeriesKey>(hts.getUniqueId(), subseriesKey), hts));
if (!subseriesKey.isMatch(start, includeStart, end, includeEnd, maxPoints)) {
// Pick out the sub-series requested
hts = getSubSeries(hts, start, includeStart, end, includeEnd, maxPoints);
}
} else {