Package org.planit.demands
Class Demands.TimePeriods
- java.lang.Object
-
- org.planit.demands.Demands.TimePeriods
-
- All Implemented Interfaces:
Iterable<TimePeriod>
- Enclosing class:
- Demands
public class Demands.TimePeriods extends Object implements Iterable<TimePeriod>
Inner class to register and store time periods for the current demand object- Author:
- garym
-
-
Constructor Summary
Constructors Constructor Description TimePeriods()
Constructor
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description SortedSet<TimePeriod>
asSortedSetByStartTime()
Returns a set of all registered time periods sorted by the start time, i.e., the way th time period is comparableTimePeriod
createAndRegisterNewTimePeriod(long externalId, String description, long startTimeSeconds, long durationSeconds)
Factory method to create and register a new time period on the demandsTimePeriod
getFirst()
Collect the first registered time period.int
getNumberOfTimePeriods()
Collect the number of registered time periodsTimePeriod
getTimePeriodByExternalId(Object externalId)
Retrieve a TimePeriod by its external Id This method is not efficient, since it loops through all the registered time periods in order to find the required time period.TimePeriod
getTimePeriodByExternalId(Object externalId, boolean convertToLong)
Retrieve a TimePeriod by its external Id This method has the option to convert the external Id parameter into a long value, to find the time period when time period objects use long values for external ids.TimePeriod
getTimePeriodById(long id)
Retrieve a time period by its idIterator<TimePeriod>
iterator()
Iterator for time periods (non-sorted)protected void
registerTimePeriod(TimePeriod timePeriod)
Register a time period-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface java.lang.Iterable
forEach, spliterator
-
-
-
-
Method Detail
-
registerTimePeriod
protected void registerTimePeriod(TimePeriod timePeriod)
Register a time period- Parameters:
timePeriod
- time period to be registered
-
createAndRegisterNewTimePeriod
public TimePeriod createAndRegisterNewTimePeriod(long externalId, String description, long startTimeSeconds, long durationSeconds) throws PlanItException
Factory method to create and register a new time period on the demands- Parameters:
externalId
- the external id for this time perioddescription
- the description for this time periodstartTimeSeconds
- the start time in seconds since midnight (00:00)durationSeconds
- the duration in seconds since start time- Returns:
- new time period created
- Throws:
PlanItException
- thrown if start time and/or duration are invalid
-
getTimePeriodById
public TimePeriod getTimePeriodById(long id)
Retrieve a time period by its id- Parameters:
id
- id of the time period- Returns:
- retrieved time period
-
getNumberOfTimePeriods
public int getNumberOfTimePeriods()
Collect the number of registered time periods- Returns:
- numver of time periods
-
getFirst
public TimePeriod getFirst()
Collect the first registered time period. This is not necessarily the earliest time period.- Returns:
- first registered time period
-
asSortedSetByStartTime
public SortedSet<TimePeriod> asSortedSetByStartTime()
Returns a set of all registered time periods sorted by the start time, i.e., the way th time period is comparable- Returns:
- Set of all registered time periods
-
iterator
public Iterator<TimePeriod> iterator()
Iterator for time periods (non-sorted)- Specified by:
iterator
in interfaceIterable<TimePeriod>
- Returns:
- iterator
-
getTimePeriodByExternalId
public TimePeriod getTimePeriodByExternalId(Object externalId, boolean convertToLong)
Retrieve a TimePeriod by its external Id This method has the option to convert the external Id parameter into a long value, to find the time period when time period objects use long values for external ids.- Parameters:
externalId
- the external Id of the specified time periodconvertToLong
- if true, the external Id is converted into a long before beginning the search- Returns:
- the retrieved time period, or null if no time period was found
-
getTimePeriodByExternalId
public TimePeriod getTimePeriodByExternalId(Object externalId)
Retrieve a TimePeriod by its external Id This method is not efficient, since it loops through all the registered time periods in order to find the required time period.- Parameters:
externalId
- the external Id of the specified time period- Returns:
- the retrieved time period, or null if no time period was found
-
-