public static List<Granularity> granularitiesFinerThan(final Granularity gran0) { final List<Granularity> retVal = new ArrayList<>(); final DateTime origin = (gran0 instanceof PeriodGranularity) ? ((PeriodGranularity) gran0).getOrigin() : null; final DateTimeZone tz = (gran0 instanceof PeriodGranularity) ? ((PeriodGranularity) gran0).getTimeZone() : null; for (GranularityType gran : GranularityType.values()) { /** * All and None are excluded b/c when asked to give all granularities finer * than "TEN_MINUTE", you want the answer to be "FIVE_MINUTE, MINUTE and SECOND" * it doesn't make sense to include ALL or None to be part of this. */ if (gran == GranularityType.ALL || gran == GranularityType.NONE) { continue; } final Granularity segmentGranularity = gran.create(origin, tz); final long segmentGranularityDurationMillis = segmentGranularity.bucket(DateTimes.EPOCH).toDurationMillis(); final long gran0DurationMillis = gran0.bucket(DateTimes.EPOCH).toDurationMillis(); if (segmentGranularityDurationMillis <= gran0DurationMillis) { retVal.add(segmentGranularity); } } retVal.sort((g1, g2) -> { long duration1 = g2.bucket(DateTimes.EPOCH).toDurationMillis(); long duration2 = g1.bucket(DateTimes.EPOCH).toDurationMillis(); return Longs.compare(duration1, duration2); }); return retVal; }
public static List<Granularity> granularitiesFinerThan(final Granularity gran0) { final List<Granularity> retVal = Lists.newArrayList(); final DateTime origin = (gran0 instanceof PeriodGranularity) ? ((PeriodGranularity) gran0).getOrigin() : null; final DateTimeZone tz = (gran0 instanceof PeriodGranularity) ? ((PeriodGranularity) gran0).getTimeZone() : null; for (GranularityType gran : GranularityType.values()) { /** * All and None are excluded b/c when asked to give all granularities finer * than "TEN_MINUTE", you want the answer to be "FIVE_MINUTE, MINUTE and SECOND" * it doesn't make sense to include ALL or None to be part of this. */ if (gran == GranularityType.ALL || gran == GranularityType.NONE) { continue; } final Granularity segmentGranularity = gran.create(origin, tz); final long segmentGranularityDurationMillis = segmentGranularity.bucket(DateTimes.EPOCH).toDurationMillis(); final long gran0DurationMillis = gran0.bucket(DateTimes.EPOCH).toDurationMillis(); if (segmentGranularityDurationMillis <= gran0DurationMillis) { retVal.add(segmentGranularity); } } retVal.sort((g1, g2) -> { long duration1 = g2.bucket(DateTimes.EPOCH).toDurationMillis(); long duration2 = g1.bucket(DateTimes.EPOCH).toDurationMillis(); return Longs.compare(duration1, duration2); }); return retVal; }