/** Choose which datapoint to use. */ public enum TimeScale { SEC10(TimeUnit2.SECONDS.toMillis(10)), MIN(TimeUnit2.MINUTES.toMillis(1)), HOUR(TimeUnit2.HOURS.toMillis(1)); /** Number of milliseconds (10 secs, 1 min, and 1 hour) that this constant represents. */ public final long tick; TimeScale(long tick) { this.tick = tick; } /** Creates a new {@link DateFormat} suitable for processing this {@link TimeScale}. */ public DateFormat createDateFormat() { switch (this) { case HOUR: return new SimpleDateFormat("MMM/dd HH"); case MIN: return new SimpleDateFormat("HH:mm"); case SEC10: return new SimpleDateFormat("HH:mm:ss"); default: throw new AssertionError(); } } /** Parses the {@link TimeScale} from the query parameter. */ public static TimeScale parse(String type) { if (type == null) return TimeScale.MIN; return Enum.valueOf(TimeScale.class, type.toUpperCase(Locale.ENGLISH)); } }
/** * Returns the interval between indexing. * * @return the interval between indexing. */ @SuppressWarnings("unused") // used by Jelly EL public String getInterval() { if (interval < TimeUnit2.SECONDS.toMillis(1)) { return Long.toString(interval) + "ms"; } if (interval < TimeUnit2.MINUTES.toMillis(1)) { return Long.toString(TimeUnit2.MILLISECONDS.toSeconds(interval)) + "s"; } if (interval < TimeUnit2.HOURS.toMillis(1)) { return Long.toString(TimeUnit2.MILLISECONDS.toMinutes(interval)) + "m"; } if (interval < TimeUnit2.DAYS.toMillis(1)) { return Long.toString(TimeUnit2.MILLISECONDS.toHours(interval)) + "h"; } return Long.toString(TimeUnit2.MILLISECONDS.toDays(interval)) + "d"; }