CronCalendar (Quartz Parent POM 2.0.1 API)

Quartz Java



org.quartz.impl.calendar Class CronCalendar

java.lang.Object
  extended by org.quartz.impl.calendar.BaseCalendar
      extended by org.quartz.impl.calendar.CronCalendar
All Implemented Interfaces:
Serializable, Cloneable, Calendar

public class CronCalendar
extends BaseCalendar

This implementation of the Calendar excludes the set of times expressed by a given CronExpression. For example, you could use this calendar to exclude all but business hours (8AM - 5PM) every day using the expression "* * 0-7,18-23 ? * *".

It is important to remember that the cron expression here describes a set of times to be excluded from firing. Whereas the cron expression in CronTrigger describes a set of times that can be included for firing. Thus, if a CronTrigger has a given cron expression and is associated with a CronCalendar with the same expression, the calendar will exclude all the times the trigger includes, and they will cancel each other out.

Author:
Aaron Craven
See Also:
Serialized Form

Field Summary
 
Fields inherited from interface org.quartz.Calendar
MONTH
 
Constructor Summary
CronCalendar(Calendar baseCalendar, String expression)
          Create a CronCalendar with the given cron expression and baseCalendar.
CronCalendar(Calendar baseCalendar, String expression, TimeZone timeZone)
          Create a CronCalendar with the given cron exprssion, baseCalendar, and TimeZone.
CronCalendar(String expression)
          Create a CronCalendar with the given cron expression and no baseCalendar.
 
Method Summary
 Object clone()
           
 CronExpression getCronExpression()
          Returns the object representation of the cron expression that defines the dates and times this calendar excludes.
 long getNextIncludedTime(long timeInMillis)
          Determines the next time included by the CronCalendar after the specified time.
 TimeZone getTimeZone()
          Returns the time zone for which the CronExpression of this CronCalendar will be resolved.
 boolean isTimeIncluded(long timeInMillis)
          Determines whether the given time (in milliseconds) is 'included' by the BaseCalendar
 void setCronExpression(CronExpression expression)
          Sets the cron expression for the calendar to a new value
 void setCronExpression(String expression)
          Sets the cron expression for the calendar to a new value
 void setTimeZone(TimeZone timeZone)
          Sets the time zone for which the CronExpression of this CronCalendar will be resolved.
 String toString()
          Returns a string representing the properties of the CronCalendar
 
Methods inherited from class org.quartz.impl.calendar.BaseCalendar
createJavaCalendar, createJavaCalendar, getBaseCalendar, getDescription, getEndOfDayJavaCalendar, getStartOfDayJavaCalendar, setBaseCalendar, setDescription
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

CronCalendar

public CronCalendar(String expression)
             throws ParseException
Create a CronCalendar with the given cron expression and no baseCalendar.

Parameters:
expression - a String representation of the desired cron expression
Throws:
ParseException


CronCalendar

public CronCalendar(Calendar baseCalendar,
                    String expression)
             throws ParseException
Create a CronCalendar with the given cron expression and baseCalendar.

Parameters:
baseCalendar - the base calendar for this calendar instance – see BaseCalendar for more information on base calendar functionality
expression - a String representation of the desired cron expression
Throws:
ParseException


CronCalendar

public CronCalendar(Calendar baseCalendar,
                    String expression,
                    TimeZone timeZone)
             throws ParseException
Create a CronCalendar with the given cron exprssion, baseCalendar, and TimeZone.

Parameters:
baseCalendar - the base calendar for this calendar instance – see BaseCalendar for more information on base calendar functionality
expression - a String representation of the desired cron expression
timeZone - Specifies for which time zone the expression should be interpreted, i.e. the expression 0 0 10 * * ?, is resolved to 10:00 am in this time zone. If timeZone is null then TimeZone.getDefault() will be used.
Throws:
ParseException

Method Detail

clone

public Object clone()
Specified by:
clone in interface Calendar
Overrides:
clone in class BaseCalendar

getTimeZone

public TimeZone getTimeZone()
Returns the time zone for which the CronExpression of this CronCalendar will be resolved.

Overrides BaseCalendar.getTimeZone() to defer to its CronExpression.

Overrides:
getTimeZone in class BaseCalendar
Returns:
This Calendar's timezone, null if Calendar should use the TimeZone.getDefault()

setTimeZone

public void setTimeZone(TimeZone timeZone)
Sets the time zone for which the CronExpression of this CronCalendar will be resolved. If timeZone is null then TimeZone.getDefault() will be used.

Overrides BaseCalendar.setTimeZone(TimeZone) to defer to its CronExpression.

Overrides:
setTimeZone in class BaseCalendar
Parameters:
timeZone - The time zone to use for this Calendar, null if TimeZone.getDefault() should be used

isTimeIncluded

public boolean isTimeIncluded(long timeInMillis)
Determines whether the given time (in milliseconds) is 'included' by the BaseCalendar

Specified by:
isTimeIncluded in interface Calendar
Overrides:
isTimeIncluded in class BaseCalendar
Parameters:
timeInMillis - the date/time to test
Returns:
a boolean indicating whether the specified time is 'included' by the CronCalendar
See Also:
Calendar.isTimeIncluded(long)

getNextIncludedTime

public long getNextIncludedTime(long timeInMillis)
Determines the next time included by the CronCalendar after the specified time.

Specified by:
getNextIncludedTime in interface Calendar
Overrides:
getNextIncludedTime in class BaseCalendar
Parameters:
timeInMillis - the initial date/time after which to find an included time
Returns:
the time in milliseconds representing the next time included after the specified time.
See Also:
Calendar.getNextIncludedTime(long)

toString

public String toString()
Returns a string representing the properties of the CronCalendar

Overrides:
toString in class Object
Returns:
the properteis of the CronCalendar in a String format

getCronExpression

public CronExpression getCronExpression()
Returns the object representation of the cron expression that defines the dates and times this calendar excludes.

Returns:
the cron expression
See Also:
CronExpression

setCronExpression

public void setCronExpression(String expression)
                       throws ParseException
Sets the cron expression for the calendar to a new value

Parameters:
expression - the new string value to build a cron expression from
Throws:
ParseException - if the string expression cannot be parsed

setCronExpression

public void setCronExpression(CronExpression expression)
Sets the cron expression for the calendar to a new value

Parameters:
expression - the new cron expression


Copyright 2001-2011, Terracotta, Inc.