Package dev.nm.interval
Class Intervals<T extends Comparable<? super T>>
- java.lang.Object
-
- dev.nm.interval.Intervals<T>
-
- Type Parameters:
T
- a class that implementsComparable
- 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 Summary
Constructors Constructor Description Intervals()
Construct an empty set of intervals.Intervals(Interval<T> interval)
Construct a set that contains only one interval.Intervals(Interval<T>... intervals)
Construct a set of intervals.Intervals(Intervals<T> that)
Copy constructor.Intervals(T begin, T end)
Construct a set that contains only one interval [begin, end].
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
add(Interval<T> interval)
Add an interval to the set.void
add(Interval<T>... intervals)
Add intervals to the set.boolean
equals(Object obj)
Interval<T>
get(int i)
Get the i-th interval.int
hashCode()
int
size()
Get the number of disjoint intervals.String
toString()
-
-
-
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 intervalend
- the end of an interval
-
Intervals
public Intervals(Interval<T>... intervals)
Construct a set of intervals.- Parameters:
intervals
- 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
-
-