NoPaddingTimeSeriesSamplingFunction implements TimeSeriesSamplingFunction { @Override public LocalDateDoubleTimeSeries getSampledTimeSeries(DateDoubleTimeSeries<?> ts, LocalDate[] schedule) { ArgumentChecker.notNull(ts, "time series"); ArgumentChecker.notNull(schedule, "schedule"); LocalDateDoubleTimeSeries localDateTS = ImmutableLocalDateDoubleTimeSeries.of(ts); Set<LocalDate> timeSeriesSet = Sets.newHashSet(localDateTS.times()); Set<LocalDate> scheduleSet = Sets.newHashSet(schedule); List<LocalDate> scheduledDates = Lists.newArrayList(Sets.intersection(scheduleSet, timeSeriesSet)); Collections.sort(scheduledDates); List<Double> scheduledData = Lists.newArrayList(); for (LocalDate localDate : scheduledDates) { scheduledData.add(localDateTS.getValue(localDate)); } return ImmutableLocalDateDoubleTimeSeries.of(scheduledDates, scheduledData); }  @Override LocalDateDoubleTimeSeries getSampledTimeSeries(DateDoubleTimeSeries<?> ts, LocalDate[] schedule);  }
@Test(expectedExceptions = IllegalArgumentException.class) public void testNullTS() { F.getSampledTimeSeries(null, DAILY_SCHEDULE); }
@Test(expectedExceptions = IllegalArgumentException.class) public void testNullSchedule() { F.getSampledTimeSeries(TS_NO_MISSING_DATA, null); }
@Test public void testNoMissingData() { final LocalDateDoubleTimeSeries result = F.getSampledTimeSeries(TS_NO_MISSING_DATA, DAILY_SCHEDULE); assertEquals(TS_NO_MISSING_DATA.size(), result.size()); int i = 0; for (final Entry<LocalDate, Double> entry : result) { assertEquals(TS_NO_MISSING_DATA.getTimeAtIndex(i), entry.getKey()); assertEquals(TS_NO_MISSING_DATA.getValueAtIndex(i++), entry.getValue(), 0); } }
@Test public void testOneDayMissingData() { final LocalDateDoubleTimeSeries result = F.getSampledTimeSeries(TS_MISSING_DATA, DAILY_SCHEDULE); assertEquals(result.size(), TS_MISSING_DATA.size()); int i = 0; for (final Entry<LocalDate, Double> entry : result) { assertEquals(TS_MISSING_DATA.getTimeAtIndex(i), entry.getKey()); if (entry.getKey().equals(MISSING_DAY_TUESDAY)) { assertEquals(TS_MISSING_DATA.getValueAtIndex(i - 1), entry.getValue(), 0); } else { assertEquals(TS_MISSING_DATA.getValueAtIndex(i), entry.getValue(), 0); } i++; } }
@Test public void testOneMonthMissingData() { final LocalDateDoubleTimeSeries result = F.getSampledTimeSeries(TS_MISSING_MONTH_DATA, DAILY_SCHEDULE); assertEquals(result.size(), TS_MISSING_MONTH_DATA.size()); int i = 0; for (final Entry<LocalDate, Double> entry : result) { assertEquals(TS_MISSING_MONTH_DATA.getTimeAtIndex(i), entry.getKey()); assertEquals(TS_MISSING_MONTH_DATA.getValueAtIndex(i), entry.getValue(), 0); i++; } }