Package io.openml.gearbox.interval
Class Interval<E extends Comparable<E>>
java.lang.Object
io.openml.gearbox.interval.Interval<E>
- Type Parameters:
E
- The class of the object as the endpoint of the interval. The class must implement a meaningfulequals(Object)
method
A representation of interval bounded by comparable class.
An interval has a left bound (inclusive) and right bound (exclusive)
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionboolean
Returns whether twoInterval
s abut.boolean
Returns whether this interval contains the specified interval.boolean
getEnd()
Returns the right bound of thisInterval
.getStart()
Returns the left bound of thisInterval
.int
hashCode()
boolean
Returns whether this interval is completely before (exclusive on end) another specified interval.static <E extends Comparable<E>>
List<Interval<E>>merge
(Collection<Interval<E>> intervals) Takes one or more lists of intervals, and combines them into a single, sorted list with the minimum number of intervals needed to capture exactly the same instants as the original intervals.boolean
Returns twoInterval
s overlap.toString()
static <E extends Comparable<E>>
List<Interval<E>>union
(Collection<Interval<E>> intervals) Returns the union of a collection of intervals.
-
Constructor Details
-
Interval
Constructs a newInterval
with the specified bounds.- Parameters:
start
- The left bound of thisInterval
, inclusiveend
- The right bound of thisInterval
, inclusive- Throws:
NullPointerException
- if eitherstart
orend
isnull
-
-
Method Details
-
merge
Takes one or more lists of intervals, and combines them into a single, sorted list with the minimum number of intervals needed to capture exactly the same instants as the original intervals.If any sub-intervals of the input collection abut or overlap they will be replaced with a single, combined interval.
Taking year range as examples:
- ['2014/2017', '2015/2020'] will combine into ['2014/2020']
- ['2015/2016', '2016/2017'] will combine into ['2015/2017]
- ['2015/2016', '2013/2014'] will sort into ['2013/2014', '2015/2016']
- ['2015/2015', '2015/2016', '2012/2013'] will sort and combine to ['2012/2013', '2015/2016']
- Type Parameters:
E
- The class of the object as the endpoint of the interval. The class must implement a meaningfulequals(Object)
method- Parameters:
intervals
- The collection of intervals being collated- Returns:
- a single list of sorted intervals simplified to the smallest number of intervals able to describe the duration
- Throws:
NullPointerException
- ifintervals
isnull
-
union
Returns the union of a collection of intervals.This method is logically the same with
merge(Collection)
- Type Parameters:
E
- The class of the object as the endpoint of the interval. The class must implement a meaningfulequals(Object)
method- Parameters:
intervals
- The collection of intervals being collated- Returns:
- a single list of sorted intervals simplified to the smallest number of intervals able to describe the duration
- Throws:
NullPointerException
- ifintervals
isnull
-
getStart
Returns the left bound of thisInterval
.- Returns:
- the interval's starting instant
-
getEnd
Returns the right bound of thisInterval
.- Returns:
- the interval's ending instant
-
isBefore
Returns whether this interval is completely before (exclusive on end) another specified interval."2011/2016" is before "2017/2018" and "2016/2018" but not before "2014/2016" or "2014/2018"
- Parameters:
that
- The provided interval- Returns:
true
if this interval is completely beforeinterval
orfalse
otherwise- Throws:
NullPointerException
- ifinterval
isnull
-
contains
Returns whether this interval contains the specified interval.- Parameters:
that
- The interval to compare to- Returns:
true
if this interval containsthat
interval
-
overlaps
Returns twoInterval
s overlap.Intervals are both inclusive of the start and end instants. An interval overlaps another if it shares some common part of the datetime continuum.
-
abuts
Returns whether twoInterval
s abut.Intervals are both inclusive of the start and end instants. An interval abuts if it starts immediately after, or ends immediately before another interval without overlap.
-
equals
-
hashCode
public int hashCode() -
toString
-