edu.sdsc.inca.util
Class CronSchedule

java.lang.Object
  extended by edu.sdsc.inca.util.CronSchedule

public class CronSchedule
extends java.lang.Object

A class that represents a cron schedule: an event schedule that allows for execution based on some combination of minute, hour, day of month, month, and day of week. See crontab(5).


Constructor Summary
CronSchedule()
           
CronSchedule(java.lang.String min, java.lang.String hour, java.lang.String mday, java.lang.String month, java.lang.String wday)
           
 
Method Summary
 java.lang.String getHour()
          Returns the hour field of the schedule.
 java.lang.String getMday()
          Returns the day of month field of the schedule.
 int getMinimum(int target, java.lang.String spec, int lowest, int highest)
          Given a cron field spec, a target integer, and a range, returns the lowest integer w/in the range, equal or greater to the target, that is included in the list of values specified by the field spec.
 java.lang.String getMinute()
          Returns the minute field of the schedule.
 java.lang.String getMonth()
          Returns the month field of the schedule.
 java.lang.String getWday()
          Returns the day of week field of the schedule.
 java.util.Date nextEvent()
          Returns the next date/time that this schedule will cause an event.
 java.util.Date nextEvent(java.util.Date d)
          Returns the next date/time after a specified date/time that this schedule will cause an event.
static CronSchedule parse(java.lang.String spec)
          A factory method that returns the CronSchedule corresponding to a cron spec.
static CronSchedule parseWHM(java.lang.String whm)
          A factory method that returns the CronSchedule corresponding to a cron spec w/an alternate format.
 void setHour(java.lang.String hour)
          Sets the hour field of the schedule.
 void setMday(java.lang.String mday)
          Sets the day of month field of the schedule.
 void setMinute(java.lang.String minute)
          Sets the minute field of the schedule.
 void setMonth(java.lang.String month)
          Sets the month field of the schedule.
 void setWday(java.lang.String wday)
          Sets the day of week field of the schedule.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CronSchedule

public CronSchedule()

CronSchedule

public CronSchedule(java.lang.String min,
                    java.lang.String hour,
                    java.lang.String mday,
                    java.lang.String month,
                    java.lang.String wday)
Method Detail

getHour

public java.lang.String getHour()
Returns the hour field of the schedule.

Returns:
the hour field of the schedule

getMday

public java.lang.String getMday()
Returns the day of month field of the schedule.

Returns:
the day of month field of the schedule

getMinute

public java.lang.String getMinute()
Returns the minute field of the schedule.

Returns:
the minute field of the schedule

getMonth

public java.lang.String getMonth()
Returns the month field of the schedule.

Returns:
the month field of the schedule

getWday

public java.lang.String getWday()
Returns the day of week field of the schedule.

Returns:
the day of week field of the schedule

setHour

public void setHour(java.lang.String hour)
Sets the hour field of the schedule.

Parameters:
hour - the hour field of the schedule

setMday

public void setMday(java.lang.String mday)
Sets the day of month field of the schedule.

Parameters:
mday - the day of month field of the schedule

setMinute

public void setMinute(java.lang.String minute)
Sets the minute field of the schedule.

Parameters:
minute - the minute field of the schedule

setMonth

public void setMonth(java.lang.String month)
Sets the month field of the schedule.

Parameters:
month - the month field of the schedule

setWday

public void setWday(java.lang.String wday)
Sets the day of week field of the schedule.

Parameters:
wday - the day of week field of the schedule

nextEvent

public java.util.Date nextEvent()
Returns the next date/time that this schedule will cause an event. Returns null if no later event will ever occur.

Returns:
the next date/time an event will occur

nextEvent

public java.util.Date nextEvent(java.util.Date d)
Returns the next date/time after a specified date/time that this schedule will cause an event. Returns null if no later event will ever occur.

Parameters:
d - a date/time preceding the returned value
Returns:
the next date/time an event will occur

getMinimum

public int getMinimum(int target,
                      java.lang.String spec,
                      int lowest,
                      int highest)
Given a cron field spec, a target integer, and a range, returns the lowest integer w/in the range, equal or greater to the target, that is included in the list of values specified by the field spec. Returns -1 if no such value exists.

Parameters:
target - the target integer
spec - cron field spec, format [0-9]+(-[0-9]+)?(,...)*(/[0-9]+)? (one or more values/ranges with an optional step)
lowest - the range low bound, inclusive
highest - the range high bound, inclusive
Returns:
the lowest integer w/in the range equal or greater than the target; -1 if none

parse

public static CronSchedule parse(java.lang.String spec)
                          throws java.text.ParseException
A factory method that returns the CronSchedule corresponding to a cron spec.

Parameters:
spec - the cron spec: min hour mday month wday
Returns:
the corresponding cron spec
Throws:
ParseError - on a bad spec
java.text.ParseException

parseWHM

public static CronSchedule parseWHM(java.lang.String whm)
                             throws java.text.ParseException
A factory method that returns the CronSchedule corresponding to a cron spec w/an alternate format.

Parameters:
spec - the cron spec: [[wday:]hour:]minute unspecified fields are equivalent to "*"
Returns:
the corresponding cron spec
Throws:
ParseError - on a bad spec
java.text.ParseException