public class TimeRange extends Object implements Comparable<TimeRange>
Reference: http://www.java2s.com/Code/Java/Collections-Data-Structure/Anumericalinterval.htm
| Constructor and Description |
|---|
TimeRange(long min,
long max)
Initialize a closed interval [min,max].
|
| Modifier and Type | Method and Description |
|---|---|
int |
compareTo(TimeRange r) |
boolean |
contains(long time) |
boolean |
contains(long min,
long max) |
boolean |
contains(TimeRange r)
Check whether this TimeRange contains r.
|
boolean |
equals(Object o) |
IExpression |
getExpression() |
boolean |
getLeftClose() |
long |
getMax()
Get the upper range boundary.
|
long |
getMin()
Get the lower range bundary.
|
List<TimeRange> |
getRemains(List<TimeRange> timeRangesPrev)
Get the remaining time ranges in the current ranges but not in timeRangesPrev.
|
boolean |
getRightClose() |
int |
hashCode() |
boolean |
intersects(TimeRange r)
Here are some examples.
|
boolean |
overlaps(TimeRange rhs)
Check if two TimeRanges overlap
|
void |
set(long min,
long max)
Set a closed interval [min,max].
|
void |
setLeftClose(boolean leftClose) |
void |
setMax(long max) |
void |
setMin(long min) |
void |
setRightClose(boolean rightClose) |
static List<TimeRange> |
sortAndMerge(List<TimeRange> unionCandidates)
Return the union of the given time ranges.
|
String |
toString() |
public TimeRange(long min,
long max)
min - the left endpoint of the closed intervalmax - the right endpoint of the closed intervalpublic int compareTo(TimeRange r)
compareTo in interface Comparable<TimeRange>public void setMin(long min)
public void setMax(long max)
public boolean contains(TimeRange r)
public boolean contains(long min,
long max)
public boolean contains(long time)
public void set(long min,
long max)
min - the left endpoint of the closed intervalmax - the right endpoint of the closed intervalpublic long getMin()
public long getMax()
public boolean intersects(TimeRange r)
[1,3] does not intersect with (4,5].
[1,3) does not intersect with (3,5].
[1,3] does not intersect with [5,6].
[1,3] intersects with [2,5].
[1,3] intersects with (3,5].
[1,3) intersects with (2,5].
Note: this method treats [1,3] and [4,5] as two "intersected" interval even if they are not truly intersected.
r - the given time rangepublic boolean overlaps(TimeRange rhs)
rhs - the given time rangepublic void setLeftClose(boolean leftClose)
public void setRightClose(boolean rightClose)
public boolean getLeftClose()
public boolean getRightClose()
public static List<TimeRange> sortAndMerge(List<TimeRange> unionCandidates)
unionCandidates - time ranges to be mergedpublic List<TimeRange> getRemains(List<TimeRange> timeRangesPrev)
NOTE the primitive timeRange is always a closed interval [min,max] and only in this function are leftClose and rightClose changed.
timeRangesPrev - time ranges union in ascending order of the start timepublic IExpression getExpression()
Copyright © 2022 The Apache Software Foundation. All rights reserved.