Class TimeslotRepo

java.lang.Object
org.powertac.common.repo.TimeslotRepo
All Implemented Interfaces:
DomainRepo

@Service
public class TimeslotRepo
extends Object
implements DomainRepo
Repository for Timeslots. Timeslots are created with makeTimeslot(). Several query methods are supported, including currentTimeslot(), enabledTimeslots(), and findBySerialNumber(). The implementation makes a strong assumption that timeslots are created in sequence, and that each timeslot starts when the previous timeslots ends.
Author:
John Collins
  • Constructor Details

  • Method Details

    • makeTimeslot

      public Timeslot makeTimeslot​(org.joda.time.Instant startTime)
      Creates a timeslot with the given start time. The sequence number of the timeslot is the number of timeslots since the simulation base time.
    • currentTimeslot

      public Timeslot currentTimeslot()
      Returns the timeslot for the current time.
    • currentSerialNumber

      public int currentSerialNumber()
      Returns the serial number of the current timeslot
    • findBySerialNumber

      public Timeslot findBySerialNumber​(int serialNumber)
      Returns the timeslot with the given serial number.
    • findOrCreateBySerialNumber

      public Timeslot findOrCreateBySerialNumber​(int serialNumber)
      Returns the timeslot with the given serial number.
    • createInitialTimeslots

      public void createInitialTimeslots()
      Creates timeslots to fill in the time from sim start to the current time. This is needed to initialize brokers.
    • findByInstant

      public Timeslot findByInstant​(org.joda.time.Instant time)
      Returns the timeslot (if any) corresponding to a particular Instant.
    • getTimeslotIndex

      public int getTimeslotIndex​(org.joda.time.Instant time)
      Converts time to timeslot index without actually creating a timeslot
    • getNext

      public Timeslot getNext​(Timeslot slot)
      Returns the following timeslot.
    • enabledTimeslots

      public List<Timeslot> enabledTimeslots()
      Returns the list of enabled timeslots, starting with the first by serial number. This code depends on the set of enabled timeslots being contiguous in the serial number sequence, and on a disabled timeslot never being re-enabled.
    • isTimeslotEnabled

      public boolean isTimeslotEnabled​(Timeslot ts)
      True just in case the specified timeslot is enabled.
    • isTimeslotEnabled

      public boolean isTimeslotEnabled​(int index)
      True just in case the timeslot with the given index is enabled.
    • count

      public int count()
      Returns the number of timeslots that have been successfully created.
    • add

      public void add​(Timeslot timeslot)
      Adds a timeslot that already exists. Visibility is public to support logfile analysis, should not be used in other contexts.
    • getTimeForIndex

      public org.joda.time.Instant getTimeForIndex​(int index)
      Converts int timeslot index to Instant
    • getDateTimeForIndex

      public org.joda.time.DateTime getDateTimeForIndex​(int index)
      Converts int timeslot index to DateTime in UTC timezone
    • recycle

      public void recycle()
      Description copied from interface: DomainRepo
      Implementations must clear out the repository in preparation for a new simulation.
      Specified by:
      recycle in interface DomainRepo