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
 void add(Timeslot timeslot)
          Adds a timeslot that already exists.
 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()
          Returns the timeslot for 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 with the given serial number.
 Timeslot findOrCreateBySerialNumber(int serialNumber)
          Returns the timeslot with the given serial number.
 Timeslot getNext(Timeslot slot)
          Returns the following timeslot.
 org.joda.time.Instant getTimeForIndex(int index)
          Converts int timeslot index to time
 int getTimeslotIndex(org.joda.time.Instant time)
          Converts time to timeslot index without actually creating a timeslot
 boolean isTimeslotEnabled(int index)
          True just in case the timeslot with the given index is enabled.
 boolean isTimeslotEnabled(Timeslot ts)
          True just in case the specified timeslot is enabled.
 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. 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 time


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 © 2013. All Rights Reserved.