Class Frequency
- java.lang.Object
-
- dk.netarkivet.harvester.datamodel.Frequency
-
- Direct Known Subclasses:
DailyFrequency
,HourlyFrequency
,MinuteFrequency
,MonthlyFrequency
,WeeklyFrequency
public abstract class Frequency extends 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
Constructors Constructor Description 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
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description boolean
equals(Object o)
Autogenerated equals.abstract Date
getFirstEvent(Date startTime)
Given a starting time, tell us when the first event should happen.static Frequency
getNewInstance(int timeunit, boolean anytime, int numtimeunits, Integer minute, Integer hour, Integer dayofweek, Integer dayofmonth)
Get a new instance of Frequency.abstract Date
getNextEvent(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 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 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 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 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.
-
-
-
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 eventsisAnytime
- Whether it's at a specified time in the period- Throws:
ArgumentNotValid
- if numUnits if 0 or negative
-
-
Method Detail
-
getNextEvent
public abstract Date getNextEvent(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 Date getFirstEvent(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(Object o)
Autogenerated equals.
-
hashCode
public int hashCode()
Autogenerated hashcode method.
-
getOnMinute
public abstract 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 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 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 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, Integer minute, Integer hour, Integer dayofweek, 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 frequencyanytime
- 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 eventsminute
- 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.
-
-