Package org.redisson.executor
Class CronExpression
- java.lang.Object
-
- org.redisson.executor.CronExpression
-
- All Implemented Interfaces:
Serializable,Cloneable
public final class CronExpression extends Object implements Serializable, Cloneable
- Author:
- Sharada Jambula, James House, Contributions from Mads Henderson, Refactoring from CronTrigger to CronExpression by Aaron Craven
- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description protected static IntegerALL_SPECprotected static intALL_SPEC_INTprotected static intDAY_OF_MONTHprotected static intDAY_OF_WEEKprotected static Map<String,Integer>dayMapprotected TreeSet<Integer>daysOfMonthprotected TreeSet<Integer>daysOfWeekprotected booleanexpressionParsedprotected static intHOURprotected TreeSet<Integer>hoursprotected intlastdayOffsetprotected booleanlastdayOfMonthprotected booleanlastdayOfWeekstatic intMAX_YEARprotected static intMINUTEprotected TreeSet<Integer>minutesprotected static intMONTHprotected static Map<String,Integer>monthMapprotected TreeSet<Integer>monthsprotected booleannearestWeekdayprotected static IntegerNO_SPECprotected static intNO_SPEC_INTprotected intnthdayOfWeekprotected static intSECONDprotected TreeSet<Integer>secondsprotected static intYEARprotected TreeSet<Integer>years
-
Constructor Summary
Constructors Constructor Description CronExpression(String cronExpression)Constructs a newCronExpressionbased on the specified parameter.CronExpression(CronExpression expression)Constructs a newCronExpressionas a copy of an existing instance.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description protected voidaddToSet(int val, int end, int incr, int type)protected voidbuildExpression(String expression)protected intcheckNext(int pos, String s, int val, int type)Objectclone()Deprecated.protected intfindNextWhiteSpace(int i, String s)StringgetCronExpression()protected intgetDayOfWeekNumber(String s)protected StringgetExpressionSetSummary(ArrayList<Integer> list)protected StringgetExpressionSetSummary(Set<Integer> set)StringgetExpressionSummary()DategetFinalFireTime()protected intgetLastDayOfMonth(int monthNum, int year)protected intgetMonthNumber(String s)DategetNextInvalidTimeAfter(Date date)Returns the next date/time after the given date/time which does not satisfy the expressionDategetNextValidTimeAfter(Date date)Returns the next date/time after the given date/time which satisfies the cron expression.protected intgetNumericValue(String s, int i)DategetTimeAfter(Date afterTime)DategetTimeBefore(Date endTime)TimeZonegetTimeZone()Returns the time zone for which thisCronExpressionwill be resolved.protected org.redisson.executor.ValueSetgetValue(int v, String s, int i)protected booleanisLeapYear(int year)booleanisSatisfiedBy(Date date)Indicates whether the given date satisfies the cron expression.static booleanisValidExpression(String cronExpression)Indicates whether the specified cron expression can be parsed into a valid cron expressionprotected voidsetCalendarHour(Calendar cal, int hour)Advance the calendar to the particular hour paying particular attention to daylight saving problems.voidsetTimeZone(TimeZone timeZone)Sets the time zone for which thisCronExpressionwill be resolved.protected intskipWhiteSpace(int i, String s)protected intstoreExpressionVals(int pos, String s, int type)StringtoString()Returns the string representation of theCronExpressionstatic voidvalidateExpression(String cronExpression)
-
-
-
Field Detail
-
SECOND
protected static final int SECOND
- See Also:
- Constant Field Values
-
MINUTE
protected static final int MINUTE
- See Also:
- Constant Field Values
-
HOUR
protected static final int HOUR
- See Also:
- Constant Field Values
-
DAY_OF_MONTH
protected static final int DAY_OF_MONTH
- See Also:
- Constant Field Values
-
MONTH
protected static final int MONTH
- See Also:
- Constant Field Values
-
DAY_OF_WEEK
protected static final int DAY_OF_WEEK
- See Also:
- Constant Field Values
-
YEAR
protected static final int YEAR
- See Also:
- Constant Field Values
-
ALL_SPEC_INT
protected static final int ALL_SPEC_INT
- See Also:
- Constant Field Values
-
NO_SPEC_INT
protected static final int NO_SPEC_INT
- See Also:
- Constant Field Values
-
ALL_SPEC
protected static final Integer ALL_SPEC
-
NO_SPEC
protected static final Integer NO_SPEC
-
lastdayOfWeek
protected transient boolean lastdayOfWeek
-
nthdayOfWeek
protected transient int nthdayOfWeek
-
lastdayOfMonth
protected transient boolean lastdayOfMonth
-
nearestWeekday
protected transient boolean nearestWeekday
-
lastdayOffset
protected transient int lastdayOffset
-
expressionParsed
protected transient boolean expressionParsed
-
MAX_YEAR
public static final int MAX_YEAR
-
-
Constructor Detail
-
CronExpression
public CronExpression(String cronExpression)
Constructs a newCronExpressionbased on the specified parameter.- Parameters:
cronExpression- String representation of the cron expression the new object should represent
-
CronExpression
public CronExpression(CronExpression expression)
Constructs a newCronExpressionas a copy of an existing instance.- Parameters:
expression- The existing cron expression to be copied
-
-
Method Detail
-
isSatisfiedBy
public boolean isSatisfiedBy(Date date)
Indicates whether the given date satisfies the cron expression. Note that milliseconds are ignored, so two Dates falling on different milliseconds of the same second will always have the same result here.- Parameters:
date- the date to evaluate- Returns:
- a boolean indicating whether the given date satisfies the cron expression
-
getNextValidTimeAfter
public Date getNextValidTimeAfter(Date date)
Returns the next date/time after the given date/time which satisfies the cron expression.- Parameters:
date- the date/time at which to begin the search for the next valid date/time- Returns:
- the next valid date/time
-
getNextInvalidTimeAfter
public Date getNextInvalidTimeAfter(Date date)
Returns the next date/time after the given date/time which does not satisfy the expression- Parameters:
date- the date/time at which to begin the search for the next invalid date/time- Returns:
- the next valid date/time
-
getTimeZone
public TimeZone getTimeZone()
Returns the time zone for which thisCronExpressionwill be resolved.- Returns:
- time zone
-
setTimeZone
public void setTimeZone(TimeZone timeZone)
Sets the time zone for which thisCronExpressionwill be resolved.- Parameters:
timeZone- object
-
toString
public String toString()
Returns the string representation of theCronExpression
-
isValidExpression
public static boolean isValidExpression(String cronExpression)
Indicates whether the specified cron expression can be parsed into a valid cron expression- Parameters:
cronExpression- the expression to evaluate- Returns:
- a boolean indicating whether the given expression is a valid cron expression
-
validateExpression
public static void validateExpression(String cronExpression) throws ParseException
- Throws:
ParseException
-
buildExpression
protected void buildExpression(String expression) throws ParseException
- Throws:
ParseException
-
storeExpressionVals
protected int storeExpressionVals(int pos, String s, int type) throws ParseException- Throws:
ParseException
-
checkNext
protected int checkNext(int pos, String s, int val, int type) throws ParseException- Throws:
ParseException
-
getCronExpression
public String getCronExpression()
-
getExpressionSummary
public String getExpressionSummary()
-
skipWhiteSpace
protected int skipWhiteSpace(int i, String s)
-
findNextWhiteSpace
protected int findNextWhiteSpace(int i, String s)
-
addToSet
protected void addToSet(int val, int end, int incr, int type) throws ParseException- Throws:
ParseException
-
getValue
protected org.redisson.executor.ValueSet getValue(int v, String s, int i)
-
getNumericValue
protected int getNumericValue(String s, int i)
-
getMonthNumber
protected int getMonthNumber(String s)
-
getDayOfWeekNumber
protected int getDayOfWeekNumber(String s)
-
setCalendarHour
protected void setCalendarHour(Calendar cal, int hour)
Advance the calendar to the particular hour paying particular attention to daylight saving problems.- Parameters:
cal- the calendar to operate onhour- the hour to set
-
getFinalFireTime
public Date getFinalFireTime()
-
isLeapYear
protected boolean isLeapYear(int year)
-
getLastDayOfMonth
protected int getLastDayOfMonth(int monthNum, int year)
-
clone
@Deprecated public Object clone()
Deprecated.
-
-