Class Schedule
java.lang.Object
ca.spottedleaf.common.time.Schedule
A Schedule is an object that can be used to maintain a periodic schedule for an event of interest.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidadvanceBy(long periods, long periodLength) Increases the last period by the specified number of periods and period length.longgetDeadline(long periodLength) Returns the next starting deadline for the event of interest to take place, given the provided period length.longReturns the last time the event of interest should have taken place.longgetPeriodsAhead(long periodLength, long time) Returns the number of times the event of interest should have taken place between the last period and the provided time given the period between each event.voidsetLastPeriod(long value) Updates the last period to the specified value.voidsetNextPeriod(long nextPeriod, long periodLength) Adjusts the last period so that the next starting deadline returned is the next period specified, given the provided period length.voidsetPeriodsAhead(long periodsToBeAhead, long periodLength, long time) Sets the last period so that it is the specified number of periods ahead given the specified time and period length.
-
Constructor Details
-
Schedule
public Schedule(long firstPeriod) Initialises a schedule with the provided period.- Parameters:
firstPeriod- The last time an event of interest occurred.- See Also:
-
-
Method Details
-
setLastPeriod
public void setLastPeriod(long value) Updates the last period to the specified value. This call sets the last "time" the event of interest took place at. Thus, the value returned bygetDeadline(long)is the provided time plus the period length provided togetDeadline.- Parameters:
value- The value to set the last period to.
-
getLastPeriod
public long getLastPeriod()Returns the last time the event of interest should have taken place. -
getPeriodsAhead
public long getPeriodsAhead(long periodLength, long time) Returns the number of times the event of interest should have taken place between the last period and the provided time given the period between each event.- Parameters:
periodLength- The length of the period between events in ns.time- The provided time.
-
getDeadline
public long getDeadline(long periodLength) Returns the next starting deadline for the event of interest to take place, given the provided period length.- Parameters:
periodLength- The provided period length.
-
setNextPeriod
public void setNextPeriod(long nextPeriod, long periodLength) Adjusts the last period so that the next starting deadline returned is the next period specified, given the provided period length.- Parameters:
nextPeriod- The specified next starting deadline.periodLength- The specified period length.
-
advanceBy
public void advanceBy(long periods, long periodLength) Increases the last period by the specified number of periods and period length. The specified number of periods may be< 0, in which case the last period will decrease.- Parameters:
periods- The specified number of periods.periodLength- The specified period length.
-
setPeriodsAhead
public void setPeriodsAhead(long periodsToBeAhead, long periodLength, long time) Sets the last period so that it is the specified number of periods ahead given the specified time and period length.- Parameters:
periodsToBeAhead- Specified number of periods to be ahead by.periodLength- The specified period length.time- The specified time.
-