@Test public void createReferencesEmpty3() { GregorianCalendar cal = new GregorianCalendar( 2014 , 10 , 22 , 11 , 30 , 0 ); cal.set( GregorianCalendar.MILLISECOND , 999 ); Instant start = cal.getTime().toInstant(); TimeInterval timeInterval = TimeInterval.between( start , start.plus( Duration.ofMillis( 3 ) ) ); List<Instant> references = TimeScales.createReferences( timeInterval , new TimePeriod( MILLISECOND , 3000 ) ); assertThat( references.size() , equalTo(0) ); }
static List<Instant> createReferences(TimeInterval timeInterval, TimePeriod period) { Date start = Date.from(timeInterval.getStart()); Date end = Date.from(timeInterval.getEnd()); GregorianCalendar endCal = new GregorianCalendar(); endCal.setTime(end); GregorianCalendar cal = new GregorianCalendar(); cal.setTime(start); round(cal, period.fieldId); cal.set(period.fieldId, (cal.get(period.fieldId) / (int) period.amount) * (int) period.amount); List<Instant> references = new ArrayList<>(); while (endCal.compareTo(cal) >= 0) { Instant newTime = cal.getTime().toInstant(); if (timeInterval.contains(newTime)) { references.add(newTime); } cal.add(period.fieldId, (int) period.amount); } return references; }
TimeScales { static List<Instant> createReferences(TimeInterval timeInterval, TimePeriod period) { Date start = Date.from(timeInterval.getStart()); Date end = Date.from(timeInterval.getEnd()); GregorianCalendar endCal = new GregorianCalendar(); endCal.setTime(end); GregorianCalendar cal = new GregorianCalendar(); cal.setTime(start); round(cal, period.fieldId); cal.set(period.fieldId, (cal.get(period.fieldId) / (int) period.amount) * (int) period.amount); List<Instant> references = new ArrayList<>(); while (endCal.compareTo(cal) >= 0) { Instant newTime = cal.getTime().toInstant(); if (timeInterval.contains(newTime)) { references.add(newTime); } cal.add(period.fieldId, (int) period.amount); } return references; } }
TimeScales { static List<Instant> createReferences(TimeInterval timeInterval, TimePeriod period) { Date start = Date.from(timeInterval.getStart()); Date end = Date.from(timeInterval.getEnd()); GregorianCalendar endCal = new GregorianCalendar(); endCal.setTime(end); GregorianCalendar cal = new GregorianCalendar(); cal.setTime(start); round(cal, period.fieldId); cal.set(period.fieldId, (cal.get(period.fieldId) / (int) period.amount) * (int) period.amount); List<Instant> references = new ArrayList<>(); while (endCal.compareTo(cal) >= 0) { Instant newTime = cal.getTime().toInstant(); if (timeInterval.contains(newTime)) { references.add(newTime); } cal.add(period.fieldId, (int) period.amount); } return references; }  }
TimeScales { static List<Instant> createReferences(TimeInterval timeInterval, TimePeriod period) { Date start = Date.from(timeInterval.getStart()); Date end = Date.from(timeInterval.getEnd()); GregorianCalendar endCal = new GregorianCalendar(); endCal.setTime(end); GregorianCalendar cal = new GregorianCalendar(); cal.setTime(start); round(cal, period.fieldId); cal.set(period.fieldId, (cal.get(period.fieldId) / (int) period.amount) * (int) period.amount); List<Instant> references = new ArrayList<>(); while (endCal.compareTo(cal) >= 0) { Instant newTime = cal.getTime().toInstant(); if (timeInterval.contains(newTime)) { references.add(newTime); } cal.add(period.fieldId, (int) period.amount); } return references; }  static TimeScale linearAbsoluteScale(); }
TimeScales { static List<Instant> createReferences(TimeInterval timeInterval, TimePeriod period) { Date start = Date.from(timeInterval.getStart()); Date end = Date.from(timeInterval.getEnd()); GregorianCalendar endCal = new GregorianCalendar(); endCal.setTime(end); GregorianCalendar cal = new GregorianCalendar(); cal.setTime(start); round(cal, period.fieldId); cal.set(period.fieldId, (cal.get(period.fieldId) / (int) period.amount) * (int) period.amount); List<Instant> references = new ArrayList<>(); while (endCal.compareTo(cal) >= 0) { Instant newTime = cal.getTime().toInstant(); if (timeInterval.contains(newTime)) { references.add(newTime); } cal.add(period.fieldId, (int) period.amount); } return references; }  static TimeScale linearAbsoluteScale(); final static int HOUR_FIELD_ID; final static int FIRST_HOUR; final static int DAY_FIELD_ID; final static int FIRST_DAY; final static int WEEK_FIELD_ID; final static int FIRST_WEEK; }