Class 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 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 class
        startTimeSeconds - start time in seconds from midnight
        durationSeconds - 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 class
        description - description of this time period
        startTimeSeconds - start time of this time period
        durationSeconds - 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
        Specified by:
        getId in interface Idable
        Returns:
        id of this TimePeriod
      • setExternalId

        public void setExternalId​(String externalId)
        set the external id
        Specified by:
        setExternalId in interface ExternalIdable
        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 interface ExternalIdable
        Returns:
        xmlId
      • setXmlId

        public void setXmlId​(String xmlId)
        set the external id
        Specified by:
        setXmlId in interface ExternalIdable
        Parameters:
        xmlId - to set
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class Object
      • toString

        public String toString()
        Output this object as a String
        Overrides:
        toString in class Object
        Returns:
        String containing the value of this TimePeriod