Package cn.boboweike.carrot.scheduling
Class Schedule
- java.lang.Object
-
- cn.boboweike.carrot.scheduling.Schedule
-
- All Implemented Interfaces:
Comparable<Schedule>
- Direct Known Subclasses:
CronExpression,Interval
public abstract class Schedule extends Object implements Comparable<Schedule>
-
-
Field Summary
Fields Modifier and Type Field Description static intSMALLEST_SCHEDULE_IN_SECONDS
-
Constructor Summary
Constructors Constructor Description Schedule()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description intcompareTo(Schedule schedule)Compare twoScheduleobjects based on next occurrence.booleanequals(Object obj)inthashCode()abstract Instantnext(Instant createdAtInstant, Instant currentInstant, ZoneId zoneId)Calculates the next occurrence based on the creation time and the provided base time.Instantnext(Instant createdAt, ZoneId zoneId)Calculates the next occurrence based on the creation time and the current time.abstract voidvalidateSchedule()
-
-
-
Field Detail
-
SMALLEST_SCHEDULE_IN_SECONDS
public static final int SMALLEST_SCHEDULE_IN_SECONDS
- See Also:
- Constant Field Values
-
-
Method Detail
-
next
public Instant next(Instant createdAt, ZoneId zoneId)
Calculates the next occurrence based on the creation time and the current time.- Parameters:
createdAt- Instant object when the schedule was first createdzoneId- the zone for which to calculate the schedule- Returns:
- Instant of the next occurrence.
-
next
@VisibleFor("testing") public abstract Instant next(Instant createdAtInstant, Instant currentInstant, ZoneId zoneId)
Calculates the next occurrence based on the creation time and the provided base time.- Parameters:
createdAtInstant- Instant object when the schedule was first createdcurrentInstant- Instant object used to calculate next occurrence (normally Instant.now()).zoneId- the zone for which to calculate the schedule- Returns:
- Instant of the next occurrence.
-
validateSchedule
public abstract void validateSchedule()
-
compareTo
public int compareTo(Schedule schedule)
Compare twoScheduleobjects based on next occurrence.The next occurrences are calculated based on the current time.
- Specified by:
compareToin interfaceComparable<Schedule>- Parameters:
schedule- theScheduleto be compared.- Returns:
- the value
0if thisSchedulenext occurrence is equal to the argumentSchedulenext occurrence; a value less than0if thisSchedulenext occurrence is before the argumentSchedulenext occurrence; and a value greater than0if thisSchedulenext occurrence is after the argumentSchedulenext occurrence.
-
-