|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Object | +--net.agmodel.physical.Period
Represents a subset of time with an optional beginning and an optional end.
See Interval for a more useful way of representing Periods which have
both beginning and ending times.
For convenience, Periods implement the beginning and end of time
as an early Date (0 AD), and the latest Date supported by Java respectively.
These have the advantage of comparing sensibly with other dates.
Calls to getBeginning() and getEnd() will return these dates, but applications can avoid using them
with the hasBeginning and hasEnd() functions.
Periods are immutable.
| Constructor Summary | |
Period()
Constructs a Period with no beginning and no end. |
|
Period(Date aDate,
boolean endless)
Constructs a Period from a date and an indicator as whether endless. |
|
Period(Date aStart,
Date anEnd)
Constructs a Period from a starting and an ending Date (both non-null with ending date after starting date) After some experimentation I've let startdate==enddate - it is more useful. |
|
Period(Date aStart,
Duration duration)
Constructs a Period from an starting Date and a duration |
|
Period(Duration duration,
Date anEnd)
Constructs a Period from a duration and an ending Date |
|
| Method Summary | |
Object |
clone()
|
boolean |
coincidesWith(Date input)
Indicates whether the input date falls within the partially closed interval (start,end] This method is consistent with coincides(Period); See coincidesWith(Date boolean, boolean) for a more flexible version |
boolean |
coincidesWith(Date input,
boolean includeStart,
boolean includeEnd)
Indicates whether the input date falls within the interval See coincidesWith(Date) for a simpler version |
boolean |
coincidesWith(Period another)
Indicates whether this period overlaps in time with another. |
int |
compareTo(Object a)
Compares two periods based on start time, and then end time if the start times are equal |
boolean |
encompasses(Period another)
Determines whether another Period lies within this one. |
static Date |
getBeginningOfTime()
A Date which will suffice in most situations as the beginning of time This implementation may change to an earlier date at a later date. |
static Date |
getEarlierOf(Date a,
Date b)
Selects the earlier of two Dates Both Dates must be non-null. |
Date |
getEnd()
|
static Date |
getEndOfTime()
A Date corresponding to the end of time |
static Date |
getLaterOf(Date a,
Date b)
Selects the later of two Dates Both Dates must be non-null. |
Date |
getStart()
|
boolean |
hasBeginning()
Indicates whether the Period begins |
boolean |
hasEnd()
Indicates whether the Period ends |
protected void |
set(Date aStart,
Date anEnd)
Sets the start and end date, ensuring that start is before end Calls setStart(Date) and setEnd(Date) which clone the parameters passed.
|
protected void |
set(Date aStart,
Duration duration)
Sets Period using an end date and duration Note that this method is protected rather than private to allow MutableInterval to set the start and end fields. |
protected void |
set(Duration duration,
Date anEnd)
Sets Period using an end date and duration Note that this method is protected rather than private to allow MutableInterval to set the start and end fields. |
protected void |
setEnd(Date anEnd)
Changes the Period end date. |
protected void |
setStart(Date aStart)
Changes the Period start date. |
String |
toString()
|
Period |
unionWith(Period another)
Creates a new Period which minimally encompasses both this Period and the other The new period starts from the earlier of this period.getStart() and another.getStart() and ends at the later of thisPeriod.getEnd() and another.getEnd(); |
| Methods inherited from class java.lang.Object |
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Constructor Detail |
public Period(Date aStart,
Date anEnd)
IllegalArgumentException - if aStart is after aEnd
public Period(Duration duration,
Date anEnd)
duration - the duration of the periodanEnd - the ending date of the period
public Period(Date aStart,
Duration duration)
aStart - the starting date of the periodduration - the duration of the period
public Period(Date aDate,
boolean endless)
aDate - the starting or ending date of a one-ended intervalendless - how to interpret aDatepublic Period()
| Method Detail |
protected void setStart(Date aStart)
aStart - the new start date for the Period (cloned), which must be before the current ending date.set(Date,Date)protected void setEnd(Date anEnd)
anEnd - the new end date for the Period (cloned), which must be after the current starting date,set(Date,Date)
protected void set(Date aStart,
Date anEnd)
setStart(Date) and setEnd(Date) which clone the parameters passed.
Note that this method is called by the Period constructors. It is made
protected rather than private to allow MutableInterval to set the start and end fields.
protected void set(Duration duration,
Date anEnd)
protected void set(Date aStart,
Duration duration)
public boolean coincidesWith(Period another)
|-----|overlaps in time with another
|=======|passed as the parameter.
|---| |======|or
|----| |=====|both return true.
|-----|
|======|
returns false, and
|-----|
|======|
returns false.
another - period to compare with this one
public boolean coincidesWith(Date input)
coincidesWith(Date boolean, boolean) for a more flexible version
input - the Date in question
public boolean coincidesWith(Date input,
boolean includeStart,
boolean includeEnd)
coincidesWith(Date) for a simpler version
input - the Date in questionincludeStart - if input=Interval.start then also return trueincludeEnd - if input=Interval.end then also return true
public boolean hasBeginning()
public boolean hasEnd()
public Date getStart()
hasBeginning for a nice way to handle periods with no end.public Date getEnd()
hasEnd for a nice way to handle periods with no end.public String toString()
toString in class Objectpublic int compareTo(Object a)
compareTo in interface Comparablea - Object to compare - assumed to be a Period
public Object clone()
clone in class Objectpublic static Date getBeginningOfTime()
public static Date getEndOfTime()
public static Date getEarlierOf(Date a,
Date b)
a - one dateb - another date
public static Date getLaterOf(Date a,
Date b)
a - one dateb - another date
public Period unionWith(Period another)
another - the period to combine with this one
public boolean encompasses(Period another)
another - the period to test against this one
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||