org.powertac.common.repo
Class TimeslotRepo

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

@Repository
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 Summary
TimeslotRepo()
          standard constructor
 
Method Summary
 int count()
          Returns the number of timeslots that have been successfully created.
 void createInitialTimeslots()
          Creates timeslots to fill in the time from sim start to the current time.
 int currentSerialNumber()
          Returns the serial number of the current timeslot
 Timeslot currentTimeslot()
          Note that this scheme for finding the current timeslot relies on a timeslot sequence that does not have gaps between sim start and the current time.
 List<Timeslot> enabledTimeslots()
          Returns the list of enabled timeslots, starting with the first by serial number.
 Timeslot findByInstant(org.joda.time.Instant time)
          Returns the timeslot (if any) corresponding to a particular Instant.
 Timeslot findBySerialNumber(int serialNumber)
          Returns the timeslot (if any) with the given serial number.
 Timeslot findOrCreateBySerialNumber(int serialNumber)
          Returns the timeslot (if any) with the given serial number.
 Timeslot makeTimeslot(org.joda.time.Instant startTime)
          Creates a timeslot with the given start time.
 void recycle()
          Implementations must clear out the repository in preparation for a new simulation.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

TimeslotRepo

public TimeslotRepo()
standard constructor

Method Detail

makeTimeslot

public Timeslot makeTimeslot(org.joda.time.Instant startTime)
Creates a timeslot with the given start time. It is assumed that timeslots are created in sequence; therefore the sequence number of the new timeslot is simply the count of timeslots already created, and an error will be logged (and null returned) if the start time of a new timeslot is not equal to the end time of the last timeslot in the list. Note that new timeslots are always created in the "enabled" state.


currentTimeslot

public Timeslot currentTimeslot()
Note that this scheme for finding the current timeslot relies on a timeslot sequence that does not have gaps between sim start and the current time.


currentSerialNumber

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


findBySerialNumber

public Timeslot findBySerialNumber(int serialNumber)
Returns the timeslot (if any) with the given serial number.


findOrCreateBySerialNumber

public Timeslot findOrCreateBySerialNumber(int serialNumber)
Returns the timeslot (if any) 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.


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.


count

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


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


Copyright © 2012. All Rights Reserved.