dk.netarkivet.harvester.datamodel
Class Frequency

java.lang.Object
  extended by dk.netarkivet.harvester.datamodel.Frequency
Direct Known Subclasses:
DailyFrequency, HourlyFrequency, MonthlyFrequency, WeeklyFrequency

public abstract class Frequency
extends java.lang.Object

This class defines various frequencies at which things can happen, such as midnight every day, 13:45 the first monday of a month, etc.


Constructor Summary
Frequency(int numUnits, boolean isAnytime)
          Initialise a frequency with information about how many periods between events, and whether it's at a specified time in the period.
 
Method Summary
 boolean equals(java.lang.Object o)
          Autogenerated equals.
abstract  java.util.Date getFirstEvent(java.util.Date startTime)
          Given a starting time, tell us when the first event should happen.
static Frequency getNewInstance(int timeunit, boolean anytime, int numtimeunits, java.lang.Integer minute, java.lang.Integer hour, java.lang.Integer dayofweek, java.lang.Integer dayofmonth)
          Get a new instance of Frequency.
abstract  java.util.Date getNextEvent(java.util.Date lastEvent)
          Given when the last event happened, tell us when the next event should happen (even if the new event is in the past).
 int getNumUnits()
          Returns the number of periods between events.
abstract  java.lang.Integer getOnDayOfMonth()
          Return the exact day of month event should happen on, or null if this is an anyTime event or doesn't define what day of month it should happen on.
abstract  java.lang.Integer getOnDayOfWeek()
          Return the exact day of week event should happen on, or null if this is an anyTime event or doesn't define what day of week it should happen on.
abstract  java.lang.Integer getOnHour()
          Return the exact hour event should happen on, or null if this is an anyTime event or doesn't define what hour it should happen on.
abstract  java.lang.Integer getOnMinute()
          Return the exact minute event should happen on, or null if this is an anyTime event or doesn't define what minute it should happen on.
 int hashCode()
          Autogenerated hashcode method.
 boolean isAnytime()
          Returns whether this frequency allows events to happen any time of day, rather than at a specific time.
abstract  int ordinal()
          Return an integer that can be used to identify the kind of frequency.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Frequency

public Frequency(int numUnits,
                 boolean isAnytime)
Initialise a frequency with information about how many periods between events, and whether it's at a specified time in the period. The actual length of the period is defined by subclasses

Parameters:
numUnits - Number of periods between events
isAnytime - Whether it's at a specified time in the period
Throws:
ArgumentNotValid - if numUnits if 0 or negative
Method Detail

getNextEvent

public abstract java.util.Date getNextEvent(java.util.Date lastEvent)
Given when the last event happened, tell us when the next event should happen (even if the new event is in the past). The time of the next event is guaranteed to be later that lastEvent. For certain frequencies (e.g. once a day, any time of day), the time of the next event is derived from lastEvent, for others (e.g. once a day at 13:00) the time of the next event is the first matching time after lastEvent. These methods are used by the schedule methods for calculating when events should happen.

Parameters:
lastEvent - A time from which the next event should be calculated.
Returns:
At what point the event should happen next.

getFirstEvent

public abstract java.util.Date getFirstEvent(java.util.Date startTime)
Given a starting time, tell us when the first event should happen. This method is used by the schedule methods for calculating when events should happen.

Parameters:
startTime - The earliest time the event can happen.
Returns:
At what point the event should happen the first time.

getNumUnits

public int getNumUnits()
Returns the number of periods between events.

Returns:
that number

isAnytime

public boolean isAnytime()
Returns whether this frequency allows events to happen any time of day, rather than at a specific time.

Returns:
true if the events may happen at any time.

equals

public boolean equals(java.lang.Object o)
Autogenerated equals.

Overrides:
equals in class java.lang.Object
Parameters:
o - The object to compare with
Returns:
Whether objects are equal

hashCode

public int hashCode()
Autogenerated hashcode method.

Overrides:
hashCode in class java.lang.Object
Returns:
the hashcode

getOnMinute

public abstract java.lang.Integer getOnMinute()
Return the exact minute event should happen on, or null if this is an anyTime event or doesn't define what minute it should happen on.

Returns:
the exact minute event should happen on

getOnHour

public abstract java.lang.Integer getOnHour()
Return the exact hour event should happen on, or null if this is an anyTime event or doesn't define what hour it should happen on.

Returns:
the exact hour event should happen on

getOnDayOfWeek

public abstract java.lang.Integer getOnDayOfWeek()
Return the exact day of week event should happen on, or null if this is an anyTime event or doesn't define what day of week it should happen on.

Returns:
the exact day of week event should happen on

getOnDayOfMonth

public abstract java.lang.Integer getOnDayOfMonth()
Return the exact day of month event should happen on, or null if this is an anyTime event or doesn't define what day of month it should happen on.

Returns:
the exact day of month event should happen on

ordinal

public abstract int ordinal()
Return an integer that can be used to identify the kind of frequency. No two subclasses should use the same integer

Returns:
Return an integer that can be used to identify the kind of frequency

getNewInstance

public static Frequency getNewInstance(int timeunit,
                                       boolean anytime,
                                       int numtimeunits,
                                       java.lang.Integer minute,
                                       java.lang.Integer hour,
                                       java.lang.Integer dayofweek,
                                       java.lang.Integer dayofmonth)
Get a new instance of Frequency. The type of Frequency (either Hourly, Daily, Monthly, or Weekly) returned depends on the 'timeunit' argument.

Parameters:
timeunit - The type or frequency
anytime - Allow events to start anytime. If false, the starting point is described precisely. If true, the starting point will be immediately.
numtimeunits - The number of periods between events
minute - A given minute. Used to create hourly, daily, and monthly frequencies, if anytime is false.
hour - A given hour. Used to create hourly, daily, and monthly frequencies, if anytime is false.
dayofweek - A given day of the week. Used only to create weekly frequencies, if anytime is false.
dayofmonth - A given day of month. Used only to create monthly frequencies, if anytime is false.
Returns:
a new instance of the Frequency class.
Throws:
ArgumentNotValid - If the given timeunit is illegal, or the values of timeunit and numtimeunits is negative.
NotImplementedException - If we can't yet make a Frequency for a legal timeunit.