Class Intervals<T extends Comparable<? super T>>

  • Type Parameters:
    T - a class that implements Comparable
    Direct Known Subclasses:
    TimeIntervals

    public class Intervals<T extends Comparable<? super T>>
    extends Object
    This is a disjoint set of intervals. When adding a new interval, all overlapping intervals are merged into one interval. This implementation keeps the disjoint intervals sorted in ascending order. Suppose I_1 is indexed before I_2. The end of I_1 is strictly smaller than the begin of I_2, as defined by the partial ordering relation.
    • Constructor Detail

      • Intervals

        public Intervals()
        Construct an empty set of intervals.
      • Intervals

        public Intervals​(Interval<T> interval)
        Construct a set that contains only one interval.
        Parameters:
        interval - an interval
      • Intervals

        public Intervals​(T begin,
                         T end)
        Construct a set that contains only one interval [begin, end].
        Parameters:
        begin - the begin of an interval
        end - the end of an interval
      • Intervals

        public Intervals​(Interval<T>... intervals)
        Construct a set of intervals.
        Parameters:
        intervals - intervals
      • Intervals

        public Intervals​(Intervals<T> that)
        Copy constructor.
        Parameters:
        that - a set of intervals
    • Method Detail

      • size

        public int size()
        Get the number of disjoint intervals.
        Returns:
        the number of disjoint intervals
      • get

        public Interval<T> get​(int i)
        Get the i-th interval. The intervals are sorted such that if I_1 is indexed before I_2, then the end of I_1 is strictly smaller than the begin of I_2.
        Parameters:
        i - the index, counting from 1
        Returns:
        the i-th interval
      • add

        public void add​(Interval<T> interval)
        Add an interval to the set. The union remains disjoint and sorted.
        Parameters:
        interval - an interval
      • add

        public void add​(Interval<T>... intervals)
        Add intervals to the set. The union remains disjoint and sorted.
        Parameters:
        intervals - intervals
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class Object