|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object edu.nrao.sss.measure.TimeInterval
public class TimeInterval
An interval from one point in time to another.
This interval is half-open; it includes the starting point but does not include the ending point.
Caveat
July 2006. It might be that some of the query methods that compare
one interval to another, or to a point, are not accurate for the
degenerate case where one or both intervals have zero length.
This possibility will be tested, and corrected, in the future.
--DMH
Version Info:
$Revision: 1708 $ |
$Date: 2008-11-14 10:31:42 -0700 (Fri, 14 Nov 2008) $ |
$Author: dharland $ |
Constructor Summary | |
---|---|
TimeInterval()
Creates a new large interval. |
|
TimeInterval(Date from,
Date to)
Creates a new interval using the given times. |
Method Summary | |
---|---|
TimeInterval |
clone()
Returns a time interval that is equal to this one. |
int |
compareTo(TimeInterval other)
Compares this interval to other for order. |
boolean |
contains(Date time)
Returns true if time is contained in this interval. |
boolean |
contains(TimeInterval other)
Returns true if this interval contains other . |
boolean |
equals(Object o)
Returns true if o is equal to this time interval. |
Date |
getCenterTime()
Returns the time that is midway between the endpoints of this interval. |
TimeDuration |
getDuration()
Returns the time duration represented by this interval. |
Date |
getEnd()
Returns a copy of this interval's ending time. |
Date |
getStart()
Returns a copy of this interval's starting time. |
int |
hashCode()
Returns a hash code value for this time interval. |
boolean |
isAfter(Date time)
Returns true if this interval starts after the given time. |
boolean |
isAfter(TimeInterval other)
Returns true if this interval starts after the other
one ends. |
boolean |
isBefore(Date time)
Returns true if this interval ends before the given time. |
boolean |
isBefore(TimeInterval other)
Returns true if this interval ends before the other
one starts. |
boolean |
isContainedBy(TimeInterval other)
Returns true if the other interval contains this one. |
boolean |
isContiguousWith(TimeInterval other)
Returns true if this interval and the other form a contiguous
non-overlapping time interval. |
boolean |
isInDefaultState()
Returns true if this interval is in its default state, no matter how it got there. |
TimeInterval |
makeGapFiller(TimeInterval other)
Returns a new time interval that exactly plugs the gap between this interval and the other . |
boolean |
overlaps(TimeInterval other)
Returns true if this interval overlaps the other interval. |
static TimeInterval |
parse(String iso8601Interval)
Creates a new time interval based on the parameter text. |
static TimeInterval |
parse(String interval,
String dateFormat,
String separator)
Creates a new time interval by parsing interval with the given
formatter and separator. |
void |
reset()
Resets this interval to its initial state. |
void |
set(Date from,
Date to)
Sets the starting and ending points of this interval. |
void |
set(String iso8601Interval)
|
void |
set(String intervalText,
String dateFormat,
String separator)
Sets the endpoints of this interval based on intervalText . |
TimeInterval[] |
split(Date pointOfSplit)
Returns two new intervals that were formed by splitting this one at the given point. |
String |
toString()
Creates a text representation of this time interval. |
String |
toString(String dateFormat,
String separator)
Returns a text representation of this interval based on the formatting parameters. |
Methods inherited from class java.lang.Object |
---|
finalize, getClass, notify, notifyAll, wait, wait, wait |
Constructor Detail |
---|
public TimeInterval()
public TimeInterval(Date from, Date to)
The description of the set(Date, Date)
method applies
to this constructor as well.
from
- the starting point of this interval. The starting
point is included in the interval.to
- the ending point of this interval. The ending
point is not included in the interval.Method Detail |
---|
public void reset()
A reset interval has the same state as one newly created by
the no-argument constructor
.
public void set(Date from, Date to)
By convention, the earlier date should be passed as
the from
parameter. However, this method will
correct the situation where from
is later than
to
, and
use the earlier of the two parameters as the starting
point of this interval. The later of the two
times will be used as the ending point.
Note that this range goes up to, but does not include,
the ending point. That is, this interval is half-open,
with the ending point excluded from the interval.
If either parameter is null, a
IllegalArgumentException
will be thrown.
Note that this method makes copies of the parameters; it does not maintain a reference to either parameter. This is done in order to maintain the integrity of the relationship between the starting and ending points of this interval.
from
- the starting point of this interval. The starting
point is included in the interval.to
- the ending point of this interval. The ending
point is not included in the interval.public void set(String intervalText, String dateFormat, String separator)
intervalText
.
If intervalText
is null or "" (the empty string),
the reset()
method is called. Otherwise, the parsing is
delegated to parse(String, String, String)
. See that method
for details related to parsing.
public void set(String iso8601Interval)
public Date getStart()
set(Date, Date)
public Date getEnd()
set(Date, Date)
public Date getCenterTime()
public TimeDuration getDuration()
public boolean contains(Date time)
time
is contained in this interval.
Note that this interval is half-open; it does not include its ending point.
time
- the time to be tested for containment.
time
is contained in this interval.public boolean contains(TimeInterval other)
other
.
Note that an interval that is equal to this one is not contained by this one. The best analogy is that of a rigid box with infinitely thin walls: a box that is exactly the same as another cannot fit inside it.
other
- an interval that might be contained by this one.
other
.public boolean isContainedBy(TimeInterval other)
other
interval contains this one.
See contains(TimeInterval)
for the definition of containment.
other
- a time interval that might contain this one.
other
interval contains this one.public boolean isBefore(TimeInterval other)
other
one starts.
other
- an interval that might come after this one.
other
starts.public boolean isAfter(TimeInterval other)
other
one ends.
other
- an interval that might come after this one.
other
ends.public boolean isBefore(Date time)
time
- a point in time that might come after this interval.
public boolean isAfter(Date time)
time
- a point in time that might come after this interval.
public boolean isContiguousWith(TimeInterval other)
other
form a contiguous
non-overlapping time interval. Since a time interval is half open, this
method returns true when either this interval starts at the same time
the other one ends, or ends at the same time the other starts.
other
- an interval that might be contiguous with this one.
other
form a contiguous
non-overlapping time interval.public boolean overlaps(TimeInterval other)
other
interval.
Note that equal intervals overlap, as do intervals that have a container-contained relationship.
other
- an interval that might overlap this one.
other
interval.public boolean isInDefaultState()
An interval is in its default state if both its endpoints
are the same as those of an interval newly created via
the no-argument constructor
.
An interval whose most recent update came via the
reset
method is also in its default state.
public TimeInterval[] split(Date pointOfSplit)
Scenario One. If this interval contains pointOfSplit
, then
the first interval in the array runs from this interval's starting point
to pointOfSplit
, and the second interval runs from
pointOfSplit
to this interval's ending point.
Scenario Two. If this interval does not contain
pointOfSplit
, then the first interval in the array will be equal
to this one, and the second interval will be a zero length interval whose
starting and ending endpoints are both pointOfSplit
.
pointOfSplit
- the point at which to split this interval in two.
public TimeInterval makeGapFiller(TimeInterval other)
other
.
If this interval is contiguous with, or overlaps, other
,
null is returned. Otherwise, a new interval is created
and valued such that it fills the gap between this interval and
the other. Note that the gap is filled regardless of whether
other
is before or after this interval.
other
- an interval that might not overlap, or be contiguous with,
this interval, and for which a gap-filling interval is sought.
other
, or null if there is no gap.public static TimeInterval parse(String iso8601Interval)
This is a convenience method that is equivalent to:
parse(iso8601Interval, FormatString.ISO8601_DATE_TIME_TIMEZONE, FormatString.ISO8601_TIME_INTERVAL_SEPARATOR);
iso8601Interval
- the text to be parsed and converted into a time
interval.
iso8601Interval
. If
iso8601Interval
is null or "" (the empty
string), a new time interval of length zero is returned.parse(String, String, String)
public static TimeInterval parse(String interval, String dateFormat, String separator)
interval
with the given
formatter and separator. The general form is
StartDateSeparatorEndDate, with the particulars of the date
format determined by dateFormat
.
interval
- the text to be parsed and converted into a time
interval. If this value is null or "" (the empty
string), a new time interval of length zero is returned.dateFormat
- the text that determines the format of the start and end
dates in interval
. These are the same formats
used in SimpleDateFormat
. A list of
ISO 8601 format strings may be found in
FormatString
.separator
- the text that separates the start date from the end date
in interval
.
interval
.
IllegalArgument
- if interval
cannot be parsed using
dateFormat
and separator
.public String toString()
A call to this method is equivalent to:
toString(FormatString.ISO8601_DATE_TIME_TIMEZONE, FormatString.ISO8601_TIME_INTERVAL_SEPARATOR);
toString
in class Object
public String toString(String dateFormat, String separator)
parse(String, String, String)
.
public TimeInterval clone()
If anything goes wrong during the cloning procedure,
a RuntimeException
will be thrown.
clone
in class Object
public boolean equals(Object o)
o
is equal to this time interval.
equals
in class Object
public int hashCode()
hashCode
in class Object
public int compareTo(TimeInterval other)
other
for order.
One interval is deemed to be "less than" the other if it begins before the other. In the case that two intervals start at the same time, the one that ends first is considered to be less than the other.
compareTo
in interface Comparable<TimeInterval>
other
- the time interval to which this one is compared.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |