Class Interval


  • public final class Interval
    extends Object
    Immutable time interval which supports included and excluded bounds.
    • Field Detail

      • INFINITY_INTERVAL

        public static final Interval INFINITY_INTERVAL
        Infinity interval on both bounds.
    • Constructor Detail

      • Interval

        public Interval​(Interval interval)
        Copy constructor.
        Parameters:
        interval - interval to copy
      • Interval

        public Interval​(double low,
                        double high)
        Constructor with bounds and whether they are included or excluded.
        Parameters:
        low - interval's low bound
        high - interval's high bound
    • Method Detail

      • compareTo

        public int compareTo​(Interval interval)
        Compares this interval with the specified interval for order.

        Any two intervals i and i' satisfy the interval trichotomy; that is, exactly one of the following three properties holds:

        1. i and i' overlap
        2. i is to the left of i'
        3. i is to the right of i'

        Note that if two intervals are equal (i.low = i'.low and i.high = i'.high), they overlap as well. But if they simply overlap (for instance i.low < i'.low and i.high > i'.high) they aren't equal.

        Parameters:
        interval - the interval to be compared
        Returns:
        a negative integer, zero, or a positive integer as this interval is to the left of, overlaps with, or is to the right of the specified interval.
        Throws:
        NullPointerException - if interval is null.
      • compareTo

        public int compareTo​(Double timestamp)
        Compares this interval to the given timetamp.
        Parameters:
        timestamp - timestamp
        Returns:
        a negative integer, zero or a positive integer if this interval is to the left of, overlaps with, or is to the right with the specified timestamp.
        Throws:
        NullPointerException - if timestamp is null.
      • getLow

        public double getLow()
        Returns the left endpoint.
        Returns:
        the left endpoint.
      • getHigh

        public double getHigh()
        Returns the right endpoint.
        Returns:
        the right endpoint.
      • equals

        public boolean equals​(Object obj)
        Compares this interval with the specified object for equality.

        Note that two intervals are equal if i.low = i'.low and i.high = i'.high.

        Overrides:
        equals in class Object
        Parameters:
        obj - object to which this interval is to be compared
        Returns:
        true if and only if the specified Object is a Interval whose low and high are equal to this Interval's.
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class Object