Package org.powertac.common.repo
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 Summary
Constructors Constructor Description TimeslotRepo()standard constructor
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidadd(Timeslot timeslot)Adds a timeslot that already exists.intcount()Returns the number of timeslots that have been successfully created.voidcreateInitialTimeslots()Creates timeslots to fill in the time from sim start to the current time.intcurrentSerialNumber()Returns the serial number of the current timeslotTimeslotcurrentTimeslot()Returns the timeslot for the current time.List<Timeslot>enabledTimeslots()Returns the list of enabled timeslots, starting with the first by serial number.TimeslotfindByInstant(org.joda.time.Instant time)Returns the timeslot (if any) corresponding to a particular Instant.TimeslotfindBySerialNumber(int serialNumber)Returns the timeslot with the given serial number.TimeslotfindOrCreateBySerialNumber(int serialNumber)Returns the timeslot with the given serial number.org.joda.time.DateTimegetDateTimeForIndex(int index)Converts int timeslot index to DateTime in UTC timezoneTimeslotgetNext(Timeslot slot)Returns the following timeslot.org.joda.time.InstantgetTimeForIndex(int index)Converts int timeslot index to InstantintgetTimeslotIndex(org.joda.time.Instant time)Converts time to timeslot index without actually creating a timeslotbooleanisTimeslotEnabled(int index)True just in case the timeslot with the given index is enabled.booleanisTimeslotEnabled(Timeslot ts)True just in case the specified timeslot is enabled.TimeslotmakeTimeslot(org.joda.time.Instant startTime)Creates a timeslot with the given start time.voidrecycle()Implementations must clear out the repository in preparation for a new simulation.
-
-
-
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
-
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:DomainRepoImplementations must clear out the repository in preparation for a new simulation.- Specified by:
recyclein interfaceDomainRepo
-
-