@Test public void testGetInstanceSequence() throws Exception { Date instance = getDate("2012-05-22 13:40 UTC"); Date start = getDate("2012-05-14 07:40 UTC"); Frequency frequency = new Frequency("hours(1)"); Assert.assertEquals(199, EntityUtil.getInstanceSequence(start, frequency, tz, instance)); }
public static int getInstanceSequence(Date startTime, Frequency frequency, TimeZone tz, Date instanceTime) { if (startTime.after(instanceTime)) return -1; Calendar startCal = Calendar.getInstance(tz); startCal.setTime(startTime); int count = 0; switch (frequency.getTimeUnit()) { case months: count = (int) ((instanceTime.getTime() - startTime.getTime()) / MONTH_IN_MS); break; case days: count = (int) ((instanceTime.getTime() - startTime.getTime()) / DAY_IN_MS); break; case hours: count = (int) ((instanceTime.getTime() - startTime.getTime()) / HOUR_IN_MS); break; case minutes: count = (int) ((instanceTime.getTime() - startTime.getTime()) / MINUTE_IN_MS); break; default: } if (count > 2) { startCal.add(frequency.getTimeUnit().getCalendarUnit(), (count / frequency.getFrequency()) * frequency.getFrequency()); count = (count / frequency.getFrequency()); } else { count = 0; } while (startCal.getTime().before(instanceTime)) { startCal.add(frequency.getTimeUnit().getCalendarUnit(), frequency.getFrequency()); count++; } return count + 1; }
EntityUtil { public static int getInstanceSequence(Date startTime, Frequency frequency, TimeZone tz, Date instanceTime) { if (startTime.after(instanceTime)) return -1; Calendar startCal = Calendar.getInstance(tz); startCal.setTime(startTime); int count = 0; switch (frequency.getTimeUnit()) { case months: count = (int) ((instanceTime.getTime() - startTime.getTime()) / MONTH_IN_MS); break; case days: count = (int) ((instanceTime.getTime() - startTime.getTime()) / DAY_IN_MS); break; case hours: count = (int) ((instanceTime.getTime() - startTime.getTime()) / HOUR_IN_MS); break; case minutes: count = (int) ((instanceTime.getTime() - startTime.getTime()) / MINUTE_IN_MS); break; default: } if (count > 2) { startCal.add(frequency.getTimeUnit().getCalendarUnit(), (count / frequency.getFrequency()) * frequency.getFrequency()); count = (count / frequency.getFrequency()); } else { count = 0; } while (startCal.getTime().before(instanceTime)) { startCal.add(frequency.getTimeUnit().getCalendarUnit(), frequency.getFrequency()); count++; } return count + 1; } }
EntityUtil { public static int getInstanceSequence(Date startTime, Frequency frequency, TimeZone tz, Date instanceTime) { if (startTime.after(instanceTime)) return -1; Calendar startCal = Calendar.getInstance(tz); startCal.setTime(startTime); int count = 0; switch (frequency.getTimeUnit()) { case months: count = (int) ((instanceTime.getTime() - startTime.getTime()) / MONTH_IN_MS); break; case days: count = (int) ((instanceTime.getTime() - startTime.getTime()) / DAY_IN_MS); break; case hours: count = (int) ((instanceTime.getTime() - startTime.getTime()) / HOUR_IN_MS); break; case minutes: count = (int) ((instanceTime.getTime() - startTime.getTime()) / MINUTE_IN_MS); break; default: } if (count > 2) { startCal.add(frequency.getTimeUnit().getCalendarUnit(), (count / frequency.getFrequency()) * frequency.getFrequency()); count = (count / frequency.getFrequency()); } else { count = 0; } while (startCal.getTime().before(instanceTime)) { startCal.add(frequency.getTimeUnit().getCalendarUnit(), frequency.getFrequency()); count++; } return count + 1; }  }
EntityUtil { public static int getInstanceSequence(Date startTime, Frequency frequency, TimeZone tz, Date instanceTime) { if (startTime.after(instanceTime)) return -1; Calendar startCal = Calendar.getInstance(tz); startCal.setTime(startTime); int count = 0; switch (frequency.getTimeUnit()) { case months: count = (int) ((instanceTime.getTime() - startTime.getTime()) / MONTH_IN_MS); break; case days: count = (int) ((instanceTime.getTime() - startTime.getTime()) / DAY_IN_MS); break; case hours: count = (int) ((instanceTime.getTime() - startTime.getTime()) / HOUR_IN_MS); break; case minutes: count = (int) ((instanceTime.getTime() - startTime.getTime()) / MINUTE_IN_MS); break; default: } if (count > 2) { startCal.add(frequency.getTimeUnit().getCalendarUnit(), (count / frequency.getFrequency()) * frequency.getFrequency()); count = (count / frequency.getFrequency()); } else { count = 0; } while (startCal.getTime().before(instanceTime)) { startCal.add(frequency.getTimeUnit().getCalendarUnit(), frequency.getFrequency()); count++; } return count + 1; }  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); }
EntityUtil { public static int getInstanceSequence(Date startTime, Frequency frequency, TimeZone tz, Date instanceTime) { if (startTime.after(instanceTime)) return -1; Calendar startCal = Calendar.getInstance(tz); startCal.setTime(startTime); int count = 0; switch (frequency.getTimeUnit()) { case months: count = (int) ((instanceTime.getTime() - startTime.getTime()) / MONTH_IN_MS); break; case days: count = (int) ((instanceTime.getTime() - startTime.getTime()) / DAY_IN_MS); break; case hours: count = (int) ((instanceTime.getTime() - startTime.getTime()) / HOUR_IN_MS); break; case minutes: count = (int) ((instanceTime.getTime() - startTime.getTime()) / MINUTE_IN_MS); break; default: } if (count > 2) { startCal.add(frequency.getTimeUnit().getCalendarUnit(), (count / frequency.getFrequency()) * frequency.getFrequency()); count = (count / frequency.getFrequency()); } else { count = 0; } while (startCal.getTime().before(instanceTime)) { startCal.add(frequency.getTimeUnit().getCalendarUnit(), frequency.getFrequency()); count++; } return count + 1; }  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);  }