|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.emarsys.ecommon.time.TimeInterval
public class TimeInterval
Represents a time slot specified by two Calendar
objects.
The start date must always be less or equal to the end date
according to Calendar.compareTo(Calendar)
.
Note that a TimeInterval
instances are immutable.
Every operation that alters a TimeInterval
will
actually return new instance.
Dates
,
Field Summary | |
---|---|
protected java.util.Calendar |
end
|
protected java.text.DateFormat |
format
|
protected java.util.Calendar |
mean
|
protected java.util.Calendar |
start
|
Constructor Summary | |
---|---|
TimeInterval(java.util.Calendar start,
java.util.Calendar end)
|
Method Summary | |
---|---|
boolean |
equals(java.lang.Object that)
|
static java.util.Calendar |
getDateIfWithinInterval(java.util.Calendar date,
TimeInterval interval)
Returns the passed Calendar object if the date
is within the passed interval, otherwise null . |
long |
getDuration()
|
java.util.Calendar |
getEnd()
|
static java.util.Calendar |
getFirstDateWithinInterval(java.util.List<java.util.Calendar> dates,
TimeInterval interval)
Returns the first of the passed dates that is within the passed interval. |
java.util.Calendar |
getMean()
|
java.util.Calendar |
getStart()
|
int |
hashCode()
|
TimeInterval |
intersect(TimeInterval that)
|
boolean |
isOverlapping(TimeInterval that)
|
boolean |
isWithinInterval(java.util.Calendar date)
|
java.lang.String |
toString()
|
Methods inherited from class java.lang.Object |
---|
clone, finalize, getClass, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
protected java.util.Calendar start
protected java.util.Calendar end
protected java.util.Calendar mean
protected java.text.DateFormat format
Constructor Detail |
---|
public TimeInterval(java.util.Calendar start, java.util.Calendar end)
start
- end
- Method Detail |
---|
public static java.util.Calendar getDateIfWithinInterval(java.util.Calendar date, TimeInterval interval)
Returns the passed Calendar
object if the date
is within the passed interval, otherwise null
.
This method can be used to check if a date is inside of a
confidence interval which is specified by the passed
TimeInterval
.
If the passed date is within the passed, non-null
TimeInterval
then it will be returned, otherwise if
the interval is null
or the date is not within it
null
will be returned.
If the passed date is not set then null
will be
returned, too.
date
- - the date to be returned if its within the intervalinterval
- - the interval to be
Calendar
representing a date within
the specified interval or null
.public static java.util.Calendar getFirstDateWithinInterval(java.util.List<java.util.Calendar> dates, TimeInterval interval)
Returns the first of the passed dates that is within the passed interval.
This method can be used to select a date out of a
List
of dates (which should be sorted by priority)
that fits into a specified confidence TimeInterval
.
If the passed List
of Calendar
s is null
or emtpy then in any case null
will be returned.
If the passed TimeInterval
is null
then the first non-null
date from the passed
ones will be returned.
It might be a good practive to append a Calendar
representing the current time and/or
getMean()
at the end of the passed
List
in order to get fallback values.
dates
- - the dates to select the first one within the
confidence interval frominterval
- - the confidence interval for to select the
passed dates from
Calendar
instance or null
.getDateIfWithinInterval(Calendar, TimeInterval)
public java.util.Calendar getEnd()
TimeInterval
public java.util.Calendar getStart()
TimeInterval
public java.util.Calendar getMean()
public long getDuration()
TimeInterval
public boolean isWithinInterval(java.util.Calendar date)
date
-
true
iff date >= getStart()
&&
date <= getEnd()
according to
Calendar.compareTo(Calendar)
,
false
otherwise.Calendar.compareTo(Calendar)
public boolean isOverlapping(TimeInterval that)
that
-
public TimeInterval intersect(TimeInterval that)
that
-
null
if the passed TimeInterval
is null
or if its not overlapping with this one,
otherwise a new TimeInterval
instance beginning with
the latest beginning and the earliest end of this and the
passed interval.public boolean equals(java.lang.Object that)
equals
in class java.lang.Object
Object.equals(java.lang.Object)
public int hashCode()
hashCode
in class java.lang.Object
Object.hashCode()
public java.lang.String toString()
toString
in class java.lang.Object
Object.toString()
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |