EntityUtil { public static Date getNextStartTime(Date startTime, Frequency frequency, TimeZone timezone, Date now) { if (startTime.after(now)) return startTime; Calendar startCal = Calendar.getInstance(timezone); startCal.setTime(startTime); int count = 0; switch (frequency.getTimeUnit()) { case months: count = (int) ((now.getTime() - startTime.getTime()) / MONTH_IN_MS); break; case days: count = (int) ((now.getTime() - startTime.getTime()) / DAY_IN_MS); break; case hours: count = (int) ((now.getTime() - startTime.getTime()) / HOUR_IN_MS); break; case minutes: count = (int) ((now.getTime() - startTime.getTime()) / MINUTE_IN_MS); break; default: } if (count > 2) { startCal.add(frequency.getTimeUnit().getCalendarUnit(), ((count - 2) / frequency.getFrequency()) * frequency.getFrequency()); } while (startCal.getTime().before(now)) { startCal.add(frequency.getTimeUnit().getCalendarUnit(), frequency.getFrequency()); } return startCal.getTime(); }  static T getEntity(EntityType type, String entityName); static T getEntity(String type, String entityName); static TimeZone getTimeZone(String tzId); static Date getEndTime(Entity entity, String cluster); static Date parseDateUTC(String dateStr); static Date getStartTime(Entity entity, String cluster); static Date getEndTime(Process process, String cluster); static Date getStartTime(Process process, String cluster); static Date getEndTime(Feed feed, String cluster); static Date getStartTime(Feed feed, String cluster); static int getParallel(Entity entity); static void setStartDate(Entity entity, String cluster, Date startDate); static void setEndTime(Entity entity, String cluster, Date endDate); static void setParallel(Entity entity, int parallel); static int getParallel(Process process); static void setStartDate(Process process, String cluster, Date startDate); static void setParallel(Process process, int parallel); static void setEndTime(Process process, String cluster, Date endDate); static int getParallel(Feed feed); static void setStartDate(Feed feed, String cluster, Date startDate); static void setEndTime(Feed feed, String cluster, Date endDate); static void setParallel(Feed feed, int parallel); static Frequency getFrequency(Entity entity); static Frequency getFrequency(Process process); static Frequency getFrequency(Feed feed); static TimeZone getTimeZone(Entity entity); static TimeZone getTimeZone(Process process); static TimeZone getTimeZone(Feed feed); static Date getNextStartTime(Date startTime, Frequency frequency, TimeZone timezone, Date now); static int getInstanceSequence(Date startTime, Frequency frequency, TimeZone tz, Date instanceTime); static String md5(Entity entity); static boolean equals(Entity lhs, Entity rhs); static boolean equals(Entity lhs, Entity rhs, String[] filterProps); static String stringOf(Entity entity); static String getStagingPath(Entity entity); static WorkflowName getWorkflowName(Tag tag, List<String> suffixes,
			Entity entity); static WorkflowName getWorkflowName(Tag tag, Entity entity); static WorkflowName getWorkflowName(Entity entity); static String getWorkflowNameSuffix(String workflowName,
			Entity entity); static Tag getWorkflowNameTag(String workflowName, Entity entity); static T getClusterView(T entity, String clusterName); static Set<String> getClustersDefined(Entity entity); static Set<String> getClustersDefinedInColos(Entity entity); static Path getStagingPath(
			org.apache.ivory.entity.v0.cluster.Cluster cluster, Entity entity); static Retry getRetry(Entity entity); static LateProcess getLateProcess(Entity entity); static Path getLogPath(
			org.apache.ivory.entity.v0.cluster.Cluster cluster, Entity entity); static String UTCtoURIDate(String utc);  }
@Test public void testgetNextStartTimeOld() throws Exception { Date now = getDate("2012-05-02 02:45 UTC"); Date start = getDate("2012-02-01 03:00 UTC"); Date newStart = getDate("2012-05-02 03:00 UTC"); Frequency frequency = new Frequency("days(7)"); Assert.assertEquals(newStart, EntityUtil.getNextStartTime(start, frequency, tz, now)); }
@Test public void testGetNextStartTime2() throws Exception { Date now = getDate("2010-05-02 04:45 UTC"); Date start = getDate("2010-02-01 03:00 UTC"); Date newStart = getDate("2010-05-03 03:00 UTC"); Frequency frequency = new Frequency("days(7)"); Assert.assertEquals(newStart, EntityUtil.getNextStartTime(start, frequency, tz, now)); }
@Test public void testGetNextStartTime3() throws Exception { Date now = getDate("2010-05-02 04:45 UTC"); Date start = getDate("1980-02-01 03:00 UTC"); Date newStart = getDate("2010-05-07 03:00 UTC"); Frequency frequency = new Frequency("days(7)"); Assert.assertEquals(newStart, EntityUtil.getNextStartTime(start, frequency, tz, now)); }
@Test public void testGetNextStartTime() throws Exception { Date now = getDate("2012-04-03 02:45 UTC"); Date start = getDate("2012-04-02 03:00 UTC"); Date newStart = getDate("2012-04-03 03:00 UTC"); Frequency frequency = new Frequency("hours(1)"); Assert.assertEquals(newStart, EntityUtil.getNextStartTime(start, frequency, tz, now)); }