Class Intervals

java.lang.Object
org.apache.druid.java.util.common.Intervals

public final class Intervals extends Object
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final org.joda.time.Interval
     
    static final com.google.common.collect.ImmutableList<org.joda.time.Interval>
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static boolean
    canCompareEndpointsAsStrings(org.joda.time.Interval interval)
    Returns true if the provided interval has endpoints that can be compared against other DateTimes using their string representations.
    static org.joda.time.Interval
    findOverlappingInterval(org.joda.time.Interval searchInterval, org.joda.time.Interval[] sortedIntervals)
    Finds an interval from the given set of sortedIntervals which overlaps with the searchInterval.
    static org.joda.time.Interval
    fromString(String serializedInterval)
    A performance-optimized method for parsing a Joda-Time Interval from a string.
    static boolean
    isEternity(org.joda.time.Interval interval)
    Returns true if the provided interval contains all time.
    static org.joda.time.Interval
    of(String interval)
     
    static org.joda.time.Interval
    of(String format, Object... formatArgs)
     
    static org.joda.time.Interval
    utc(long startInstant, long endInstant)
     

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • ETERNITY

      public static final org.joda.time.Interval ETERNITY
    • ONLY_ETERNITY

      public static final com.google.common.collect.ImmutableList<org.joda.time.Interval> ONLY_ETERNITY
  • Method Details

    • utc

      public static org.joda.time.Interval utc(long startInstant, long endInstant)
    • of

      public static org.joda.time.Interval of(String interval)
    • of

      public static org.joda.time.Interval of(String format, Object... formatArgs)
    • fromString

      public static org.joda.time.Interval fromString(String serializedInterval)
      A performance-optimized method for parsing a Joda-Time Interval from a string. This method is significantly faster than the standard of(String) for the following group of offsets:
      1. "2022-01-01T00:00:00.000Z/2022-01-02T00:00:00.000Z"
      2. "2022-01-01T00:00:00.000+05:30/2022-01-01T01:00:00.000+05:30"
      3. "2022-01-01T00:00:00.000+0530/2022-01-01T01:00:00.000+0530"

      If the input string does not match the format, it will fall back to the more flexible but slower of(String) parser. If you are dealing with any Intervals format examples below, consider using of(String) instead:

      1. "2022-01-01T00:00:00Z/2022-01-02T00:00:00Z" (without millis)
      2. "2022-01-01/2022-01-02" (Date only)
      3. "2022-01-01T12:00:00.000Z/PT6H" (Periods in start / end)
      Currently, this method is only used in SegmentId.
    • canCompareEndpointsAsStrings

      public static boolean canCompareEndpointsAsStrings(org.joda.time.Interval interval)
      Returns true if the provided interval has endpoints that can be compared against other DateTimes using their string representations. See also DateTimes.canCompareAsString(DateTime).
    • isEternity

      public static boolean isEternity(org.joda.time.Interval interval)
      Returns true if the provided interval contains all time.
    • findOverlappingInterval

      @Nullable public static org.joda.time.Interval findOverlappingInterval(org.joda.time.Interval searchInterval, org.joda.time.Interval[] sortedIntervals)
      Finds an interval from the given set of sortedIntervals which overlaps with the searchInterval. If multiple candidate intervals overlap with the searchInterval, the "smallest" interval based on the Comparators.intervalsByStartThenEnd() is returned.
      Parameters:
      searchInterval - Interval which should overlap with the result
      sortedIntervals - Candidate overlapping intervals, sorted in ascending order, using Comparators.intervalsByStartThenEnd().
      Returns:
      The first overlapping interval, if one exists, otherwise null.