Class Schedule

java.lang.Object
ca.spottedleaf.common.time.Schedule

public final class Schedule extends Object
A Schedule is an object that can be used to maintain a periodic schedule for an event of interest.
  • Constructor Summary

    Constructors
    Constructor
    Description
    Schedule(long firstPeriod)
    Initialises a schedule with the provided period.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    advanceBy(long periods, long periodLength)
    Increases the last period by the specified number of periods and period length.
    long
    getDeadline(long periodLength)
    Returns the next starting deadline for the event of interest to take place, given the provided period length.
    long
    Returns the last time the event of interest should have taken place.
    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.
    void
    setLastPeriod(long value)
    Updates the last period to the specified value.
    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.
    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.

    Methods inherited from class Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • 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 by getDeadline(long) is the provided time plus the period length provided to getDeadline.
      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.