@Test public void testTimeIntervals() { List<String> startList = new ArrayList<>(); List<String> endList = new ArrayList<>(); List<Interval> intervalList = new ArrayList<>(); List<List<String>> expectedResultList = new ArrayList<>(); startList.add("2008-01-31T12:34:56"); endList.add("2010-01-31T12:34:56"); intervalList.add(Interval.YEARLY); expectedResultList.add(Arrays.asList("2008-01-31T12:34:56", "2009-01-31T12:34:56", "2010-01-31T12:34:56")); startList.add("2008-01-31T12:34:56"); endList.add("2008-07-31T12:34:56"); intervalList.add(Interval.QUARTERLY); expectedResultList.add(Arrays.asList("2008-01-31T12:34:56", "2008-04-30T12:34:56", "2008-07-31T12:34:56")); startList.add("2008-01-31T12:34:56"); endList.add("2008-03-31T12:34:56"); intervalList.add(Interval.MONTHLY); expectedResultList.add(Arrays.asList("2008-01-31T12:34:56", "2008-02-29T12:34:56", "2008-03-31T12:34:56")); startList.add("2008-01-31T12:34:56"); endList.add("2008-02-14T12:34:56"); intervalList.add(Interval.WEEKLY); expectedResultList.add(Arrays.asList("2008-01-31T12:34:56", "2008-02-07T12:34:56", "2008-02-14T12:34:56")); startList.add("2008-01-31T12:34:56"); endList.add("2008-02-02T12:34:56"); intervalList.add(Interval.DAILY); expectedResultList.add(Arrays.asList("2008-01-31T12:34:56", "2008-02-01T12:34:56", "2008-02-02T12:34:56")); startList.add("2008-01-31T12:34:56"); endList.add("2008-01-31T15:00:00"); intervalList.add(Interval.HOURLY); expectedResultList.add(Arrays.asList("2008-01-31T12:34:56", "2008-01-31T13:34:56", "2008-01-31T14:34:56")); assertEquals(startList.size(), endList.size()); assertEquals(startList.size(), intervalList.size()); assertEquals(startList.size(), expectedResultList.size()); Set<Interval> testedIntervals = EnumSet.noneOf(Interval.class); for (int i = 0; i < startList.size(); i++) { OSHDBTimestamps timestamps = new OSHDBTimestamps(startList.get(i), endList.get(i), intervalList.get(i)); Iterator resultIt = timestamps.get().iterator(); Iterator expResultIt = expectedResultList.get(i).iterator(); while (resultIt.hasNext()) { assertEquals(expResultIt.next().toString(), resultIt.next().toString()); } assertFalse(expResultIt.hasNext()); testedIntervals.add(intervalList.get(i)); } assertTrue(testedIntervals.containsAll(EnumSet.allOf(Interval.class))); }
public SortedSet<OSHDBTimestamp> get() { if (period != null) { return new TreeSet<>( _getTimestampsAsEpochSeconds(start, end, period, fromEnd).stream().map(OSHDBTimestamp::new).collect(Collectors.toList()) ); } else { SortedSet<OSHDBTimestamp> timestamps = new TreeSet<>(); try { timestamps.add(new OSHDBTimestamp(ISODateTimeParser.parseISODateTime(start).toEpochSecond())); if (start.equals(end)) return timestamps; timestamps.add(new OSHDBTimestamp(ISODateTimeParser.parseISODateTime(end).toEpochSecond())); } catch (Exception e) { LOG.error("Unable to parse timestamp string, skipping: " + e.getMessage()); } return timestamps; } }
OSHDBTimestamps implements OSHDBTimestampList { public SortedSet<OSHDBTimestamp> get() { if (period != null) { return new TreeSet<>( _getTimestampsAsEpochSeconds(start, end, period, fromEnd).stream().map(OSHDBTimestamp::new).collect(Collectors.toList()) ); } else { SortedSet<OSHDBTimestamp> timestamps = new TreeSet<>(); try { timestamps.add(new OSHDBTimestamp(ISODateTimeParser.parseISODateTime(start).toEpochSecond())); if (start.equals(end)) return timestamps; timestamps.add(new OSHDBTimestamp(ISODateTimeParser.parseISODateTime(end).toEpochSecond())); } catch (Exception e) { LOG.error("Unable to parse timestamp string, skipping: " + e.getMessage()); } return timestamps; } } }
OSHDBTimestamps implements OSHDBTimestampList { public SortedSet<OSHDBTimestamp> get() { if (period != null) { return new TreeSet<>( _getTimestampsAsEpochSeconds(start, end, period, fromEnd).stream().map(OSHDBTimestamp::new).collect(Collectors.toList()) ); } else { SortedSet<OSHDBTimestamp> timestamps = new TreeSet<>(); try { timestamps.add(new OSHDBTimestamp(ISODateTimeParser.parseISODateTime(start).toEpochSecond())); if (start.equals(end)) return timestamps; timestamps.add(new OSHDBTimestamp(ISODateTimeParser.parseISODateTime(end).toEpochSecond())); } catch (Exception e) { LOG.error("Unable to parse timestamp string, skipping: " + e.getMessage()); } return timestamps; } } OSHDBTimestamps(String isoDateStart, String isoDateEnd, String isoPeriod);  OSHDBTimestamps(String isoDateStart, String isoDateEnd, String isoPeriod, Boolean fromEnd);  OSHDBTimestamps(String isoDateStart, String isoDateEnd, Interval interval);  OSHDBTimestamps(String isoDateStart, String isoDateEnd, Interval interval, Boolean fromEnd);  OSHDBTimestamps(String isoDateStart, String isoDateEnd);  OSHDBTimestamps(String isoDate); }
OSHDBTimestamps implements OSHDBTimestampList { public SortedSet<OSHDBTimestamp> get() { if (period != null) { return new TreeSet<>( _getTimestampsAsEpochSeconds(start, end, period, fromEnd).stream().map(OSHDBTimestamp::new).collect(Collectors.toList()) ); } else { SortedSet<OSHDBTimestamp> timestamps = new TreeSet<>(); try { timestamps.add(new OSHDBTimestamp(ISODateTimeParser.parseISODateTime(start).toEpochSecond())); if (start.equals(end)) return timestamps; timestamps.add(new OSHDBTimestamp(ISODateTimeParser.parseISODateTime(end).toEpochSecond())); } catch (Exception e) { LOG.error("Unable to parse timestamp string, skipping: " + e.getMessage()); } return timestamps; } } OSHDBTimestamps(String isoDateStart, String isoDateEnd, String isoPeriod);  OSHDBTimestamps(String isoDateStart, String isoDateEnd, String isoPeriod, Boolean fromEnd);  OSHDBTimestamps(String isoDateStart, String isoDateEnd, Interval interval);  OSHDBTimestamps(String isoDateStart, String isoDateEnd, Interval interval, Boolean fromEnd);  OSHDBTimestamps(String isoDateStart, String isoDateEnd);  OSHDBTimestamps(String isoDate); SortedSet<OSHDBTimestamp> get(); }
OSHDBTimestamps implements OSHDBTimestampList { public SortedSet<OSHDBTimestamp> get() { if (period != null) { return new TreeSet<>( _getTimestampsAsEpochSeconds(start, end, period, fromEnd).stream().map(OSHDBTimestamp::new).collect(Collectors.toList()) ); } else { SortedSet<OSHDBTimestamp> timestamps = new TreeSet<>(); try { timestamps.add(new OSHDBTimestamp(ISODateTimeParser.parseISODateTime(start).toEpochSecond())); if (start.equals(end)) return timestamps; timestamps.add(new OSHDBTimestamp(ISODateTimeParser.parseISODateTime(end).toEpochSecond())); } catch (Exception e) { LOG.error("Unable to parse timestamp string, skipping: " + e.getMessage()); } return timestamps; } } OSHDBTimestamps(String isoDateStart, String isoDateEnd, String isoPeriod);  OSHDBTimestamps(String isoDateStart, String isoDateEnd, String isoPeriod, Boolean fromEnd);  OSHDBTimestamps(String isoDateStart, String isoDateEnd, Interval interval);  OSHDBTimestamps(String isoDateStart, String isoDateEnd, Interval interval, Boolean fromEnd);  OSHDBTimestamps(String isoDateStart, String isoDateEnd);  OSHDBTimestamps(String isoDate); SortedSet<OSHDBTimestamp> get();  }