|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.opensymphony.oscache.util.FastCronParser
public class FastCronParser
Parses cron expressions and determines at what time in the past is the most recent match for the supplied expression.
Field Summary | |
---|---|
private String |
cronExpression
Holds the raw cron expression that this parser is handling. |
private static int |
DAY_OF_MONTH
|
private static int |
DAY_OF_WEEK
|
private static int[] |
DAYS_IN_MONTH
A lookup table holding the number of days in each month (with the obvious exception that February requires special handling). |
private static int |
HOUR
|
private long[] |
lookup
This is the main lookup table that holds a parsed cron expression. |
private int[] |
lookupMax
This is based on the contents of the lookup table. |
private int[] |
lookupMin
This is based on the contents of the lookup table. |
private static int[] |
MAX_VALUE
|
private static int[] |
MIN_VALUE
|
private static int |
MINUTE
|
private static int |
MONTH
|
private static int |
NUMBER_OF_CRON_FIELDS
|
Constructor Summary | |
---|---|
FastCronParser()
Creates a FastCronParser that uses a default cron expression of "* * * * *". |
|
FastCronParser(String cronExpression)
Constructs a new FastCronParser based on the supplied expression. |
Method Summary | |
---|---|
private void |
addToLookup(int start,
int end,
int field,
int interval)
Adds a group of valid values to the lookup table for the specified field. |
private int |
dayOfWeek(int day,
int month,
int year)
Calculate the day of the week. |
String |
getCronExpression()
Retrieves the current cron expression. |
private int |
getDayOfWeekVal(char ch1,
char[] element,
int i)
Quickly retrieves the day of week value (Sun = 0, ... |
private String |
getExpressionSetSummary(int field)
Converts the internal datastructure that holds a particular cron field into a human-readable list of values of the field's contents. |
String |
getExpressionSummary()
Recreates the original human-readable cron expression based on the internal datastructure values. |
private int |
getMonthVal(char ch1,
char[] element,
int i)
Quickly retrieves the month value (Jan = 1, ..., Dec = 12) that corresponds to the month name that is specified in the character array. |
long |
getTimeBefore(long time)
Find the most recent time that matches this cron expression. |
private ValueSet |
getValue(int value,
char[] element,
int i)
Extracts a numerical value from inside a character array. |
boolean |
hasMoreRecentMatch(long time)
Determines whether this cron expression matches a date/time that is more recent than the one supplied. |
private boolean |
isLeapYear(int year)
Indicates if a year is a leap year or not. |
private ParseException |
makeParseException(String msg,
char[] data,
int offset)
Makes a ParseException . |
private int |
numberOfDaysInMonth(int month,
int year)
Retrieves the number of days in the supplied month, taking into account leap years. |
private void |
parseExpression(String expression)
Takes a cron expression as an input parameter, and extracts from it the relevant minutes/hours/days/months that the expression matches. |
void |
setCronExpression(String cronExpression)
Resets the cron expression to the value supplied. |
private void |
storeExpressionValues(char[] element,
int field)
Stores the values for the supplied cron element into the specified field. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
private static final int NUMBER_OF_CRON_FIELDS
private static final int MINUTE
private static final int HOUR
private static final int DAY_OF_MONTH
private static final int MONTH
private static final int DAY_OF_WEEK
private static final int[] MIN_VALUE
private static final int[] MAX_VALUE
private static final int[] DAYS_IN_MONTH
private String cronExpression
private long[] lookup
lookup[MINUTE]
map to minutes 0 -> 59 respectively. Bits are set if
the corresponding value is enabled. So if the minute field in the cron expression
was "0,2-8,50"
, bits 0, 2, 3, 4, 5, 6, 7, 8 and 50 will be set.
If the cron expression is "*"
, the long value is set to
Long.MAX_VALUE
.
private int[] lookupMax
lookup
table. It holds the
highest valid field value for each field type.
private int[] lookupMin
lookup
table. It holds the
lowest valid field value for each field type.
Constructor Detail |
---|
public FastCronParser()
"* * * * *".
This will match any time that is supplied.
public FastCronParser(String cronExpression) throws ParseException
ParseException
- if the supplied expression is not a valid cron expression.Method Detail |
---|
public void setCronExpression(String cronExpression) throws ParseException
cronExpression
- the new cron expression.
ParseException
- if the supplied expression is not a valid cron expression.public String getCronExpression()
public boolean hasMoreRecentMatch(long time)
time
- The time to compare the cron expression against.
true
if the cron expression matches a time that is closer
to the current time than the supplied time is, false
otherwise.public long getTimeBefore(long time)
time
- The time (in milliseconds) that we're using as our upper bound.
private void parseExpression(String expression) throws ParseException
expression
- A valid cron expression.
ParseException
- If the supplied expression could not be parsed.private void storeExpressionValues(char[] element, int field) throws ParseException
element
- The cron element to store. A cron element is a single component
of a cron expression. For example, the complete set of elements for the cron expression
30 0,6,12,18 * * *
would be {"30", "0", "6", "12", "18", "*", "*", "*"}
.field
- The field that this expression belongs to. Valid values are MINUTE
,
HOUR
, DAY_OF_MONTH
, MONTH
and DAY_OF_WEEK
.
ParseException
- if there was a problem parsing the supplied element.private ValueSet getValue(int value, char[] element, int i)
value
- The value of the first characterelement
- The character array we're extracting the value fromi
- The index into the array of the next character to process
private void addToLookup(int start, int end, int field, int interval) throws ParseException
start
- The starting value for the range. Supplying a value that is less than zero
will cause the minimum allowable value for the specified field to be used as the start value.end
- The maximum value that can be added (ie the upper bound). If the step size is
greater than one, this maximum value may not necessarily end up being added. Supplying a
value that is less than zero will cause the maximum allowable value for the specified field
to be used as the upper bound.field
- The field that the values should be added to.interval
- Specifies the step size for the range. Any values less than one will be
treated as a single step interval.
ParseException
private boolean isLeapYear(int year)
year
- The year to check
true
if the year is a leap year, false
otherwise.private int dayOfWeek(int day, int month, int year)
day
- The day of the month (1-31)month
- The month (1 - 12)year
- The year
private int numberOfDaysInMonth(int month, int year)
MIN_VALUE[MONTH] - MAX_VALUE[MONTH]
then the year will be adjusted accordingly and the correct number of days will still
be returned.
month
- The month of interest.year
- The year we are checking.
private int getDayOfWeekVal(char ch1, char[] element, int i) throws ParseException
element
- The character arrayi
- The index to start looking at
ParseException
private int getMonthVal(char ch1, char[] element, int i) throws ParseException
element
- The character arrayi
- The index to start looking at
ParseException
public String getExpressionSummary()
private String getExpressionSetSummary(int field)
Converts the internal datastructure that holds a particular cron field into
a human-readable list of values of the field's contents. For example, if the
DAY_OF_WEEK
field was submitted that had Sunday and Monday specified,
the string 0,1
would be returned.
If the field contains all possible values, *
will be returned.
field
- The field.
private ParseException makeParseException(String msg, char[] data, int offset)
ParseException
. The exception message is constructed by
taking the given message parameter and appending the supplied character data
to the end of it. for example, if msg == "Invalid character
encountered"
and data == {'A','g','u','s','t'}
, the resultant
error message would be "Invalid character encountered [Agust]"
.
msg
- The error messagedata
- The data that the messageoffset
- The offset into the data where the error was encountered.
ParseException
object.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |