Package org.planit.time
Class TimePeriod
- java.lang.Object
-
- org.planit.time.TimePeriod
-
- All Implemented Interfaces:
Comparable<Idable>
,ExternalIdable
,Idable
public class TimePeriod extends Object implements ExternalIdable
Represents a time period within the day. Used to determine the duration and start time of trips for example We internally adopt seconds as the unit- Author:
- markr
-
-
Constructor Summary
Constructors Constructor Description TimePeriod(IdGroupingToken groupId, long startTimeSeconds, long durationSeconds)
ConstructorTimePeriod(IdGroupingToken groupId, String description, long startTimeSeconds, long durationSeconds)
Constructor
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static Comparator<TimePeriod>
comparatorByStartTime()
custom comparator not by id but based on the start time and when equal durationstatic long
convertHoursToSeconds(double hoursFromMidnight)
Convert hours to (whole) secondsstatic long
convertHoursToSeconds(String fourDigitHour)
Convert duration to seconds given start time using the 24-hour clockstatic float
convertSecondsToHours(int secondsFromMidnight)
Convert seconds to 24h format from midnight to secondsboolean
equals(Object o)
String
getDescription()
Return the descriptionlong
getDurationSeconds()
Return the duration in secondsString
getExternalId()
get external id of the entitylong
getId()
Return the id of this time periodlong
getStartTimeSeconds()
Return the start timeString
getXmlId()
the id exposed to users as the "normal" id in the PLANit native xml formatint
hashCode()
void
setExternalId(String externalId)
set the external idvoid
setXmlId(String xmlId)
set the external idString
toString()
Output this object as a String-
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface org.planit.utils.id.ExternalIdable
hasExternalId, hasXmlId
-
Methods inherited from interface org.planit.utils.id.Idable
compareTo, idEquals, idHashCode
-
-
-
-
Constructor Detail
-
TimePeriod
public TimePeriod(IdGroupingToken groupId, long startTimeSeconds, long durationSeconds) throws PlanItException
Constructor- Parameters:
groupId
- contiguous id generation within this group for instances of this classstartTimeSeconds
- start time in seconds from midnightdurationSeconds
- duration in seconds- Throws:
PlanItException
- thrown if error
-
TimePeriod
public TimePeriod(IdGroupingToken groupId, String description, long startTimeSeconds, long durationSeconds) throws PlanItException
Constructor- Parameters:
groupId
- contiguous id generation within this group for instances of this classdescription
- description of this time periodstartTimeSeconds
- start time of this time perioddurationSeconds
- duration of this time period- Throws:
PlanItException
- thrown if error
-
-
Method Detail
-
comparatorByStartTime
public static Comparator<TimePeriod> comparatorByStartTime()
custom comparator not by id but based on the start time and when equal duration- Returns:
- comparator by start time
-
convertHoursToSeconds
public static long convertHoursToSeconds(String fourDigitHour) throws PlanItException
Convert duration to seconds given start time using the 24-hour clock- Parameters:
fourDigitHour
- start time in 24-hour clock format (four digits exactly)- Returns:
- duration in seconds
- Throws:
PlanItException
- thrown if the input time is not in the correct format
-
convertHoursToSeconds
public static long convertHoursToSeconds(double hoursFromMidnight)
Convert hours to (whole) seconds- Parameters:
hoursFromMidnight
- the hours from midnight- Returns:
- secondsFromMidnight the seconds from midnight
-
convertSecondsToHours
public static float convertSecondsToHours(int secondsFromMidnight)
Convert seconds to 24h format from midnight to seconds- Parameters:
secondsFromMidnight
- seconds from midnight- Returns:
- hours from midnight
-
getStartTimeSeconds
public long getStartTimeSeconds()
Return the start time- Returns:
- start time
-
getDurationSeconds
public long getDurationSeconds()
Return the duration in seconds- Returns:
- duration
-
getDescription
public String getDescription()
Return the description- Returns:
- description of this TimePeriod
-
getId
public long getId()
Return the id of this time period
-
getExternalId
public String getExternalId()
get external id of the entity- Specified by:
getExternalId
in interfaceExternalIdable
- Returns:
- external id
-
setExternalId
public void setExternalId(String externalId)
set the external id- Specified by:
setExternalId
in interfaceExternalIdable
- Parameters:
externalId
- to set
-
getXmlId
public String getXmlId()
the id exposed to users as the "normal" id in the PLANit native xml format- Specified by:
getXmlId
in interfaceExternalIdable
- Returns:
- xmlId
-
setXmlId
public void setXmlId(String xmlId)
set the external id- Specified by:
setXmlId
in interfaceExternalIdable
- Parameters:
xmlId
- to set
-
-