public final class EventFrequency
extends java.lang.Object
Let interpret and computing a frequency.
The frequency is expressed as a string at initialization of this object. This string must respect the following syntax:
Where: hh = integer between 0 and 23, mm = integer between 0 and 59, dd (for 'W') = integer between 1 and 7 (1:sunday, 2:monday, ..., 7:saturday), dd (for 'M') = integer between 1 and 31.
Warning: The frequency type is case sensitive! Then you should particularly pay attention at the case when using the frequency types 'M' (monthly) and 'm' (every minute).
Parsing errors are not thrown but "resolved" silently. The "solution" depends of the error. 2 cases of errors are considered:
Examples:
When this class is initialized with a frequency, it is able to compute the date of the event following a given date.
The functions nextEvent()
and nextEvent(Date)
will compute this next event date
from, respectively, now (current date/time) and the given date (the date of the last event). Both are computing the date of the next
event by "adding" the frequency to the given date. And finally, the computed date is stored and returned.
Then, you have 2 possibilities to trigger the desired event:
isTimeElapsed()
, you can test whether at the current moment the date of the next event has been reached or not.
In function of the value returned by this function you will be then able to process the desired action or not.Constructor and Description |
---|
EventFrequency(java.lang.String interval)
Create a new event frequency.
|
Modifier and Type | Method and Description |
---|---|
java.lang.String |
getEventID()
Get a string which identity the period between the last event and the next one (whose the date has been computed by this object).
|
java.util.Date |
getNextEvent()
Get the date of the next event.
|
boolean |
isTimeElapsed()
Tell whether the interval between the last event and now is greater or equals to the frequency represented by this object.
|
java.util.Date |
nextEvent()
Compute the date of the event, by adding the interval represented by this object to the current date/time.
|
java.util.Date |
nextEvent(java.util.Date lastEventDate)
Compute the date of the event, by adding the interval represented by this object to the given date/time.
|
java.lang.String |
toString()
Display in a human readable way the frequency represented by this object.
|
public EventFrequency(java.lang.String interval)
Create a new event frequency.
The frequency string must respect the following syntax:
Where: hh = integer between 0 and 23, mm = integer between 0 and 59, dd (for 'W') = integer between 1 and 7 (1:sunday, 2:monday, ..., 7:saturday), dd (for 'M') = integer between 1 and 31.
Warning: The frequency type is case sensitive! Then you should particularly pay attention at the case when using the frequency types 'M' (monthly) and 'm' (every minute).
Parsing errors are not thrown but "resolved" silently. The "solution" depends of the error. 2 cases of errors are considered:
Examples:
interval
- A string defining the event frequency (see above for the string format).public boolean isTimeElapsed()
public java.util.Date getNextEvent()
public java.lang.String getEventID()
Get a string which identity the period between the last event and the next one (whose the date has been computed by this object).
This ID is built by formatting in string the given date of the last event.
public java.util.Date nextEvent()
Compute the date of the event, by adding the interval represented by this object to the current date/time.
The role of this function is to compute the next event date, not to get it. After computation, you can get this date
thanks to getNextEvent()
. Furthermore, using isTimeElapsed()
after having called this function will
let you test whether the next event should (have) occur(red).
Note:
This function computes the next event date by taking the current date as the date of the last event. However,
if the last event occurred at a different date, you should use nextEvent(Date)
.
public java.util.Date nextEvent(java.util.Date lastEventDate)
Compute the date of the event, by adding the interval represented by this object to the given date/time.
The role of this function is to compute the next event date, not to get it. After computation, you can get this date
thanks to getNextEvent()
. Furthermore, using isTimeElapsed()
after having called this function will
let you test whether the next event should (have) occur(red).
public java.lang.String toString()
toString
in class java.lang.Object