org.springframework.scheduling.support
Class CronSequenceGenerator

java.lang.Object
  extended by org.springframework.scheduling.support.CronSequenceGenerator

public class CronSequenceGenerator
extends java.lang.Object

Date sequence generator for a Crontab pattern, allowing clients to specify a pattern that the sequence matches.

The pattern is a list of six single space-separated fields: representing second, minute, hour, day, month, weekday. Month and weekday names can be given as the first three letters of the English names.

Example patterns:

Since:
3.0
Author:
Dave Syer, Juergen Hoeller
See Also:
CronTrigger

Field Summary
private  java.util.BitSet daysOfMonth
           
private  java.util.BitSet daysOfWeek
           
private  java.lang.String expression
           
private  java.util.BitSet hours
           
private  java.util.BitSet minutes
           
private  java.util.BitSet months
           
private  java.util.BitSet seconds
           
private  java.util.TimeZone timeZone
           
 
Constructor Summary
CronSequenceGenerator(java.lang.String expression, java.util.TimeZone timeZone)
          Construct a CronSequenceGenerator from the pattern provided.
 
Method Summary
private  void doNext(java.util.Calendar calendar, int dot)
           
 boolean equals(java.lang.Object obj)
           
private  int findNext(java.util.BitSet bits, int value, java.util.Calendar calendar, int field, int nextField, java.util.List<java.lang.Integer> lowerOrders)
          Search the bits provided for the next set bit after the value provided, and reset the calendar.
private  int findNextDay(java.util.Calendar calendar, java.util.BitSet daysOfMonth, int dayOfMonth, java.util.BitSet daysOfWeek, int dayOfWeek, java.util.List<java.lang.Integer> resets)
           
private  int[] getRange(java.lang.String field, int min, int max)
           
 int hashCode()
           
 java.util.Date next(java.util.Date date)
          Get the next Date in the sequence matching the Cron pattern and after the value provided.
private  void parse(java.lang.String expression)
          Parse the given pattern expression.
private  java.lang.String replaceOrdinals(java.lang.String value, java.lang.String commaSeparatedList)
          Replace the values in the commaSeparatedList (case insensitive) with their index in the list.
private  void reset(java.util.Calendar calendar, java.util.List<java.lang.Integer> fields)
          Reset the calendar setting all the fields provided to zero.
private  void setDays(java.util.BitSet bits, java.lang.String field, int max)
           
private  void setDaysOfMonth(java.util.BitSet bits, java.lang.String field)
           
private  void setMonths(java.util.BitSet bits, java.lang.String value)
           
private  void setNumberHits(java.util.BitSet bits, java.lang.String value, int min, int max)
           
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

seconds

private final java.util.BitSet seconds

minutes

private final java.util.BitSet minutes

hours

private final java.util.BitSet hours

daysOfWeek

private final java.util.BitSet daysOfWeek

daysOfMonth

private final java.util.BitSet daysOfMonth

months

private final java.util.BitSet months

expression

private final java.lang.String expression

timeZone

private final java.util.TimeZone timeZone
Constructor Detail

CronSequenceGenerator

public CronSequenceGenerator(java.lang.String expression,
                             java.util.TimeZone timeZone)
Construct a CronSequenceGenerator from the pattern provided.

Parameters:
expression - a space-separated list of time fields
timeZone - the TimeZone to use for generated trigger times
Throws:
java.lang.IllegalArgumentException - if the pattern cannot be parsed
Method Detail

next

public java.util.Date next(java.util.Date date)
Get the next Date in the sequence matching the Cron pattern and after the value provided. The return value will have a whole number of seconds, and will be after the input value.

Parameters:
date - a seed value
Returns:
the next value matching the pattern

doNext

private void doNext(java.util.Calendar calendar,
                    int dot)

findNextDay

private int findNextDay(java.util.Calendar calendar,
                        java.util.BitSet daysOfMonth,
                        int dayOfMonth,
                        java.util.BitSet daysOfWeek,
                        int dayOfWeek,
                        java.util.List<java.lang.Integer> resets)

findNext

private int findNext(java.util.BitSet bits,
                     int value,
                     java.util.Calendar calendar,
                     int field,
                     int nextField,
                     java.util.List<java.lang.Integer> lowerOrders)
Search the bits provided for the next set bit after the value provided, and reset the calendar.

Parameters:
bits - a BitSet representing the allowed values of the field
value - the current value of the field
calendar - the calendar to increment as we move through the bits
field - the field to increment in the calendar (@see Calendar for the static constants defining valid fields)
lowerOrders - the Calendar field ids that should be reset (i.e. the ones of lower significance than the field of interest)
Returns:
the value of the calendar field that is next in the sequence

reset

private void reset(java.util.Calendar calendar,
                   java.util.List<java.lang.Integer> fields)
Reset the calendar setting all the fields provided to zero.


parse

private void parse(java.lang.String expression)
            throws java.lang.IllegalArgumentException
Parse the given pattern expression.

Throws:
java.lang.IllegalArgumentException

replaceOrdinals

private java.lang.String replaceOrdinals(java.lang.String value,
                                         java.lang.String commaSeparatedList)
Replace the values in the commaSeparatedList (case insensitive) with their index in the list.

Returns:
a new string with the values from the list replaced

setDaysOfMonth

private void setDaysOfMonth(java.util.BitSet bits,
                            java.lang.String field)

setDays

private void setDays(java.util.BitSet bits,
                     java.lang.String field,
                     int max)

setMonths

private void setMonths(java.util.BitSet bits,
                       java.lang.String value)

setNumberHits

private void setNumberHits(java.util.BitSet bits,
                           java.lang.String value,
                           int min,
                           int max)

getRange

private int[] getRange(java.lang.String field,
                       int min,
                       int max)

equals

public boolean equals(java.lang.Object obj)
Overrides:
equals in class java.lang.Object

hashCode

public int hashCode()
Overrides:
hashCode in class java.lang.Object

toString

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