org.oddjob.schedules
Class ConstrainedSchedule

java.lang.Object
  extended by org.oddjob.schedules.AbstractSchedule
      extended by org.oddjob.schedules.ConstrainedSchedule
All Implemented Interfaces:
Serializable, RefineableSchedule, Schedule
Direct Known Subclasses:
DailySchedule, MonthlySchedule, WeeklySchedule, YearlySchedule

public abstract class ConstrainedSchedule
extends AbstractSchedule

A base class for a Schedule which has a from and a to date.

See Also:
Serialized Form
Author:
Rob Gordon

Constructor Summary
ConstrainedSchedule()
           
 
Method Summary
protected abstract  Calendar fromCalendar(Date referenceDate, TimeZone timeZone)
          Provide a Calendar for the start of the constraint.
protected abstract  CalendarUnit intervalBetween()
          Sub classes must provide a unit which is what must be added to move the schedule on.
protected  Interval lastInterval(ScheduleContext context)
          Calculate the last interval.
 ScheduleResult nextDue(ScheduleContext context)
          For a given date a schedule will provide the interval this schedule should next be scheduled in.
protected  Interval nextInterval(ScheduleContext context)
          Calculate the next interval, without children.
protected  Calendar shiftFromCalendar(Calendar calendar, int intervals)
          Shift the from Calendar by an interval.
protected  Calendar shiftToCalendar(Calendar calendar, int intervals)
          Shift the to Calendar by an interval.
protected abstract  Calendar toCalendar(Date referenceDate, TimeZone timeZone)
          Provide a Calendar for the end of the constraint.
abstract  String toString()
          Force sub classes to override toString.
 
Methods inherited from class org.oddjob.schedules.AbstractSchedule
getRefinement, setRefinement
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

ConstrainedSchedule

public ConstrainedSchedule()
Method Detail

fromCalendar

protected abstract Calendar fromCalendar(Date referenceDate,
                                         TimeZone timeZone)
Provide a Calendar for the start of the constraint.

Parameters:
referenceDate - The date/time now.
timeZone - The time zone.
Returns:
A calendar for the from time.

toCalendar

protected abstract Calendar toCalendar(Date referenceDate,
                                       TimeZone timeZone)
Provide a Calendar for the end of the constraint.

Parameters:
referenceDate - The date/time now.
timeZone - The time zone.
Returns:
A calendar for the end time.

intervalBetween

protected abstract CalendarUnit intervalBetween()
Sub classes must provide a unit which is what must be added to move the schedule on. I.e. the equivalent of a day, week, month etc.

Returns:

nextInterval

protected final Interval nextInterval(ScheduleContext context)
Calculate the next interval, without children.

Parameters:
context -
Returns:

lastInterval

protected final Interval lastInterval(ScheduleContext context)
Calculate the last interval.

Parameters:
context -
Returns:

shiftFromCalendar

protected Calendar shiftFromCalendar(Calendar calendar,
                                     int intervals)
Shift the from Calendar by an interval. The subclass fromCalendar is used to re-adjust the shifted calendar. This is needed in at least these situations:

shiftToCalendar

protected Calendar shiftToCalendar(Calendar calendar,
                                   int intervals)
Shift the to Calendar by an interval. The subclass toCalendar is used to re-adjust the shifted calendar for the reasons given in shiftFromCalendar(Calendar, int)

Parameters:
calendar -
intervals -
Returns:

nextDue

public ScheduleResult nextDue(ScheduleContext context)
Description copied from interface: Schedule
For a given date a schedule will provide the interval this schedule should next be scheduled in.

If the schedule is never due again for the given date, null is returned.

Returns:
The next due interval for the schedule.

toString

public abstract String toString()
Force sub classes to override toString.

Overrides:
toString in class Object
Returns:
A description of the schedule.