atg.service.scheduler
Class CalendarSchedule

java.lang.Object
  extended by atg.service.scheduler.CalendarSchedule
All Implemented Interfaces:
Schedule, java.io.Serializable

public class CalendarSchedule
extends java.lang.Object
implements Schedule, java.io.Serializable

A CalendarSchedule expresses a repeating job in terms of months, days, hours, and minutes. For example, a CalendarSchedule might specify that a job take place on the 15th and 30th of every month, at 3:05am. A CalendarSchedule may also express a day in terms of day of the week, so that a job could take place every Monday in February at 2:30pm.

A CalendarSchedule is built by constructing a blank CalendarSchedule, then adding months, dates, days of the week, occurrences of days of the week in the month, hours, and minutes. Any times matching some combination of the added times will trigger the job. Specifically, the job will be triggered if:

The numerical values for the months, days, days of the week, hours, and minutes correspond to the same values used by the java.util.Calendar class fields MONTH, DATE, DAY_OF_WEEK, HOUR_OF_DAY, and MINUTE. The numerical values 1-4 for the occurrence of day of the week in the month similarly correspond to the values used by the Calendar field DAY_OF_WEEK_IN_MONTH; the special value of "last" is used to indicate the last occurrence in the month (e.g., last Monday of the month).

A CalendarSchedule may also be specified through a String, which the CalendarSchedule will parse. The String is of the form:

 "<months> <dates> <days of week> <occurrences in month> <hours of day> <minutes>"
 

Each of the above elements, such as <dates>, is specified as one of the following:

For example, the following String specifies a job that will occur at 3:05pm on the 1st and 15th of every month:

"* 1,15 . . 15 5"

The following String specifies a job that will occur at midnight every Monday in the summer and winter:

"11-2,5-7 . 2 * 0 0"

And the following String specifies a job that will occur every hour on the hour on the first and last Wednesdays of every month:

"* . 4 1,last * 0"

See java.util.Calendar for more information.

See Also:
Serialized Form

Field Summary
static java.lang.String CLASS_VERSION
          Class version string
static int LAST
          Represents the last occurrence of day of the week in the month
static java.lang.String LAST_STRING
          The string corresponding to the LAST value
 
Constructor Summary
CalendarSchedule()
          Constructs a blank new CalendarSchedue
CalendarSchedule(java.lang.String pSchedule)
          Constructs a new CalendarSchedule parsed from the given String
CalendarSchedule(java.lang.String pSchedule, java.util.Locale pLocale)
          Constructs a new CalendarSchedule parsed from the given String
 
Method Summary
 CalendarSchedule addAllDates()
          Adds all dates to the schedule, so that the job will occur in every date of the month.
 CalendarSchedule addAllDaysOfTheWeek()
          Adds all days of the week to the schedule, so that the job will occur in every day of the week.
 CalendarSchedule addAllHours()
          Adds all hours to the schedule, so that the job will occur in every hour.
 CalendarSchedule addAllMinutes()
          Adds all minutes to the schedule, so that the job will occur in every minute.
 CalendarSchedule addAllMonths()
          Adds all months to the schedule, so that the job will occur in every month.
 CalendarSchedule addAllOccurrencesInTheMonth()
          Adds all occurrences of day of the week in the month to the schedule, so that the job will occur at every occurrence of day of the week in the month.
 CalendarSchedule addDate(int pDate)
          Adds the specified day of the month to the schedule (1-31).
 CalendarSchedule addDayOfTheWeek(int pDayOfTheWeek)
          Adds the specified day of the week to the schedule (1=Sunday, 7=Saturday)
 CalendarSchedule addHour(int pHour)
          Adds the specified hour to the schedule (0-23, 0=midnight).
 CalendarSchedule addMinute(int pMinute)
          Adds the specified minute to the schedule (0-59).
 CalendarSchedule addMonth(int pMonth)
          Adds the specified month to the schedule (0=January, 11=December)
 CalendarSchedule addOccurrenceInTheMonth(int pOccurrence)
          Adds the specified occurrence of day of the week in the month to the schedule (1=first, 4=fourth, LAST=last)
 boolean equals(java.lang.Object pObject)
          Returns true if the given object is a CalendarSchedule with all the same settings as this schedule.
 java.lang.String generateStringRepresentation(boolean[] pArray, int startIndex)
          represents the array as a string object to be embeded in the scheduleString.
 boolean[] getAllDates()
          gets all dates of the month to the schedule will occur in.
 boolean[] getAllDaysOfTheWeek()
          gets all days of the the week the schedule will occur in the zero'th entry can be ignored as counting starts at 1
 boolean[] getAllHours()
          gets all hours the schedule will occur in
 boolean[] getAllMinutes()
          gets all minutes schedule will occur in
 boolean[] getAllMonths()
          gets all months to the schedule will occur in
 boolean[] getAllOccurencesInTheMonth()
          gets all occurences in the month the schedule will occur in the zero'th entry can be ignored as counting starts at 1
 long getNextJobTime(long pLastOccurrenceTime)
          Returns the next time that the job Scheduled by this will take place, or -1 if the job's next time could not be calculated.
static java.util.ResourceBundle getResources(java.util.Locale pLocale)
           
 int hashCode()
          Returns a hash code value for this object.
 boolean isRepeating()
          Returns true if this is a repeating job, false if this is a one-shot job.
 boolean jobOccursAtTime(java.util.Date pTime)
          Returns true if the given time is one of the times that the job Scheduled by this may take place.
static void main(java.lang.String[] pArgs)
          Testing method
 boolean mustKnowFirstTime()
          If true, then the first time getNextJobTime is called it will be called with -1.
 void parse(java.lang.String pSchedule)
          Parses a CalendarSchedule from the specified String, adding all the elements specified by that String.
 void parse(java.lang.String pSchedule, java.util.Locale pLocale)
          Parses a CalendarSchedule from the specified String, adding all the elements specified by that String.
 java.lang.String scheduleString()
          Returns a Parseable representation of this Schedule.
 java.lang.String scheduleString(java.util.Locale pLocale)
          Returns a Parseable representation of this Schedule.
 void setMonthNames()
           
 void setWeekdayNames()
           
 java.lang.String toString()
           
 java.lang.String toString(java.util.Locale pLocale)
          Returns a String representation of this
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

CLASS_VERSION

public static java.lang.String CLASS_VERSION
Class version string


LAST

public static final int LAST
Represents the last occurrence of day of the week in the month

See Also:
Constant Field Values

LAST_STRING

public static final java.lang.String LAST_STRING
The string corresponding to the LAST value

See Also:
Constant Field Values
Constructor Detail

CalendarSchedule

public CalendarSchedule()
Constructs a blank new CalendarSchedue


CalendarSchedule

public CalendarSchedule(java.lang.String pSchedule)
Constructs a new CalendarSchedule parsed from the given String

Throws:
java.lang.IllegalArgumentException - if the string can not be parsed as a CalendarSchedule

CalendarSchedule

public CalendarSchedule(java.lang.String pSchedule,
                        java.util.Locale pLocale)
Constructs a new CalendarSchedule parsed from the given String

Throws:
java.lang.IllegalArgumentException - if the string can not be parsed as a CalendarSchedule
Method Detail

getResources

public static java.util.ResourceBundle getResources(java.util.Locale pLocale)

setMonthNames

public void setMonthNames()

setWeekdayNames

public void setWeekdayNames()

addMonth

public CalendarSchedule addMonth(int pMonth)
Adds the specified month to the schedule (0=January, 11=December)

Returns:
this CalendarSchedule

addAllMonths

public CalendarSchedule addAllMonths()
Adds all months to the schedule, so that the job will occur in every month.

Returns:
this CalendarSchedule

getAllMonths

public boolean[] getAllMonths()
gets all months to the schedule will occur in

Returns:
all months as an array of booleans

addDate

public CalendarSchedule addDate(int pDate)
Adds the specified day of the month to the schedule (1-31).

Returns:
this CalendarSchedule

addAllDates

public CalendarSchedule addAllDates()
Adds all dates to the schedule, so that the job will occur in every date of the month.

Returns:
this CalendarSchedule

getAllDates

public boolean[] getAllDates()
gets all dates of the month to the schedule will occur in. the zero'th entry can be ignored as counting starts at 1

Returns:
all dates of the month as an array of booleans

addDayOfTheWeek

public CalendarSchedule addDayOfTheWeek(int pDayOfTheWeek)
Adds the specified day of the week to the schedule (1=Sunday, 7=Saturday)

Returns:
this CalendarSchedule

addAllDaysOfTheWeek

public CalendarSchedule addAllDaysOfTheWeek()
Adds all days of the week to the schedule, so that the job will occur in every day of the week.

Returns:
this CalendarSchedule

getAllDaysOfTheWeek

public boolean[] getAllDaysOfTheWeek()
gets all days of the the week the schedule will occur in the zero'th entry can be ignored as counting starts at 1


addOccurrenceInTheMonth

public CalendarSchedule addOccurrenceInTheMonth(int pOccurrence)
Adds the specified occurrence of day of the week in the month to the schedule (1=first, 4=fourth, LAST=last)

Returns:
this CalendarSchedule

addAllOccurrencesInTheMonth

public CalendarSchedule addAllOccurrencesInTheMonth()
Adds all occurrences of day of the week in the month to the schedule, so that the job will occur at every occurrence of day of the week in the month.

Returns:
this CalendarSchedule

getAllOccurencesInTheMonth

public boolean[] getAllOccurencesInTheMonth()
gets all occurences in the month the schedule will occur in the zero'th entry can be ignored as counting starts at 1


addHour

public CalendarSchedule addHour(int pHour)
Adds the specified hour to the schedule (0-23, 0=midnight).

Returns:
this CalendarSchedule

addAllHours

public CalendarSchedule addAllHours()
Adds all hours to the schedule, so that the job will occur in every hour.

Returns:
this CalendarSchedule

getAllHours

public boolean[] getAllHours()
gets all hours the schedule will occur in


addMinute

public CalendarSchedule addMinute(int pMinute)
Adds the specified minute to the schedule (0-59).

Returns:
this CalendarSchedule

addAllMinutes

public CalendarSchedule addAllMinutes()
Adds all minutes to the schedule, so that the job will occur in every minute.

Returns:
this CalendarSchedule

getAllMinutes

public boolean[] getAllMinutes()
gets all minutes schedule will occur in


jobOccursAtTime

public boolean jobOccursAtTime(java.util.Date pTime)
Returns true if the given time is one of the times that the job Scheduled by this may take place.


getNextJobTime

public long getNextJobTime(long pLastOccurrenceTime)
Returns the next time that the job Scheduled by this will take place, or -1 if the job's next time could not be calculated. The time returned will be on or after after the current time, and on or after the next minute after the specified last occurrence time. If the last occurrence time is -1, then this assumes that this is the first time the job is being scheduled today, and will pick the first time in the day that the job should occur.

Specified by:
getNextJobTime in interface Schedule
Parameters:
pLastOccurrenceTime - the last time the job occurred, or -1 if it has not yet occurred.
Returns:
the next time that the job will occur, or -1 if the job's next time could not be calculated.

mustKnowFirstTime

public boolean mustKnowFirstTime()
If true, then the first time getNextJobTime is called it will be called with -1. Otherwise, the first time getNextJobTime is called it will be called with the current time.

Specified by:
mustKnowFirstTime in interface Schedule

isRepeating

public boolean isRepeating()
Returns true if this is a repeating job, false if this is a one-shot job.

Specified by:
isRepeating in interface Schedule

parse

public void parse(java.lang.String pSchedule)
Parses a CalendarSchedule from the specified String, adding all the elements specified by that String.

Throws:
java.lang.IllegalArgumentException - if the string can not be parsed as a CalendarSchedule

parse

public void parse(java.lang.String pSchedule,
                  java.util.Locale pLocale)
Parses a CalendarSchedule from the specified String, adding all the elements specified by that String.

Throws:
java.lang.IllegalArgumentException - if the string can not be parsed as a CalendarSchedule

scheduleString

public java.lang.String scheduleString()
Description copied from interface: Schedule
Returns a Parseable representation of this Schedule.

Specified by:
scheduleString in interface Schedule

scheduleString

public java.lang.String scheduleString(java.util.Locale pLocale)
Returns a Parseable representation of this Schedule.

Specified by:
scheduleString in interface Schedule

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

generateStringRepresentation

public java.lang.String generateStringRepresentation(boolean[] pArray,
                                                     int startIndex)
represents the array as a string object to be embeded in the scheduleString.


toString

public java.lang.String toString(java.util.Locale pLocale)
Returns a String representation of this


equals

public boolean equals(java.lang.Object pObject)
Returns true if the given object is a CalendarSchedule with all the same settings as this schedule.

Overrides:
equals in class java.lang.Object

hashCode

public int hashCode()
Returns a hash code value for this object.

Overrides:
hashCode in class java.lang.Object

main

public static void main(java.lang.String[] pArgs)
Testing method