Class DutySchedule


  • public class DutySchedule
    extends Object
    This class holds information on the duty schedules that users can have. Converstion between different formats of the duty schedule information are possible, as is the comparison between a Calendar passed in and the start and stop times of each day in a duty schedule.
    Author:
    Jason Johns , OpenNMS
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static String[] DAY_NAMES
      A list of names to abbreviate the days of the week
      static int FRIDAY
      Constant FRIDAY=4
      static int MONDAY
      A series of constants to identify the days of the week as used by the DutySchedule class
      static int SATURDAY
      Constant SATURDAY=5
      static int SUNDAY
      Constant SUNDAY=6
      static int THURSDAY
      Constant THURSDAY=3
      static int TUESDAY
      Constant TUESDAY=1
      static int WEDNESDAY
      Constant WEDNESDAY=2
    • Constructor Summary

      Constructors 
      Constructor Description
      DutySchedule()
      Default constructor, builds the BitSet used to identify the days of the week that are set.
      DutySchedule​(String aSchedule)
      This constructor is designed to build a new DutySchedule from a String representation formatted as such.
      DutySchedule​(List<Boolean> schedule, int start, int end)
      This constructor is designed to convert from a Vector filled with 7 Boolean objects and two String objects into the BitSet and integer start and stop time.
      DutySchedule​(Vector<Object> aSchedule)
      This constructor is designed to convert from a Vector filled with 7 Boolean objects and two String objects into the BitSet and integer start and stop time.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      Vector<Object> getAsVector()
      This method formats the DutySchedule as a vector populated with the first seven objects as Booleans set to indicate what days of the week are stored, and the last two objects as Strings that reflect the start time and stop time respectively.
      int getStartTime()
      This method return the start time as an integer
      int getStopTime()
      This method return the stop time as an integer
      boolean hasDay​(int aDay)
      hasDay
      boolean isInSchedule​(Calendar aTime)
      This method decides if a given time falls within the duty schedule contained in this object.
      boolean isInSchedule​(Date time)
      isInSchedule
      long nextInSchedule​(Calendar nTime)
      This method decides if a given time falls within the duty schedule contained in this object.
      void setDay​(int aDay)
      This method sets the BitSet that tracks what days this DutySchedule applies to.
      void setEndHour​(int anHour)
      This method sets the stop time of this DutySchedule
      void setStartHour​(int anHour)
      This method sets the start time of this DutySchedule
      String toString()
      This method returns the DutySchedule formatted as a string that the DutySchedule(String) constructor could parse.
    • Field Detail

      • MONDAY

        public static final int MONDAY
        A series of constants to identify the days of the week as used by the DutySchedule class
        See Also:
        Constant Field Values
      • DAY_NAMES

        public static final String[] DAY_NAMES
        A list of names to abbreviate the days of the week
    • Constructor Detail

      • DutySchedule

        public DutySchedule()
        Default constructor, builds the BitSet used to identify the days of the week that are set.
      • DutySchedule

        public DutySchedule​(Vector<Object> aSchedule)
        This constructor is designed to convert from a Vector filled with 7 Boolean objects and two String objects into the BitSet and integer start and stop time. Very useful for the ModifyUser screen when it is converting from a table display to save the information to a string format for the users.xml.
        Parameters:
        aSchedule - filled with 7 Boolean objects and two String objects
      • DutySchedule

        public DutySchedule​(List<Boolean> schedule,
                            int start,
                            int end)
        This constructor is designed to convert from a Vector filled with 7 Boolean objects and two String objects into the BitSet and integer start and stop time. Very useful for the ModifyUser screen when it is converting from a table display to save the information to a string format for the users.xml.
        Parameters:
        schedule - a List object.
        start - a int.
        end - a int.
      • DutySchedule

        public DutySchedule​(String aSchedule)
        This constructor is designed to build a new DutySchedule from a String representation formatted as such. - eg. MoWeFr800-1700, TuTh900-1500.
        Parameters:
        aSchedule - the string to convert to a new DutySchedule
    • Method Detail

      • setDay

        public void setDay​(int aDay)
        This method sets the BitSet that tracks what days this DutySchedule applies to.
        Parameters:
        aDay - the day index to set in the BitSet
      • getStartTime

        public int getStartTime()
        This method return the start time as an integer
        Returns:
        The start time of this DutySchedule.
      • getStopTime

        public int getStopTime()
        This method return the stop time as an integer
        Returns:
        The stop time of this DutySchedule.
      • getAsVector

        public Vector<Object> getAsVector()
        This method formats the DutySchedule as a vector populated with the first seven objects as Booleans set to indicate what days of the week are stored, and the last two objects as Strings that reflect the start time and stop time respectively. This method gives a Vector that can be passed to the DutySchedule(Vector) constructor to create a new DutySchedule
        Returns:
        A Vector properly formatted to reflect this DutySchedule.
      • isInSchedule

        public boolean isInSchedule​(Calendar aTime)
        This method decides if a given time falls within the duty schedule contained in this object. It creates two partial Calendars from the Calendar that is passed in and then sets the start time for one and the end time for the other. Then in a loop it reassigns the day of week according to the BitSet. It makes a comparison to see if the argument Calendar is between the start and stop times and returns true immediately if it is.
        Parameters:
        aTime - The time to check.
        Returns:
        True if the Calendar is contained in the duty schedule. false if it isn't.
      • nextInSchedule

        public long nextInSchedule​(Calendar nTime)
        This method decides if a given time falls within the duty schedule contained in this object. If so, it returns 0 milliseconds. If not it returns the number of milliseconds until the next on-duty period begins. It creates two partial Calendars from the Calendar that is passed in and then sets the start time for one and the end time for the other. Then in a loop it reassigns the day of week according to the BitSet. If the day is today, it makes a comparison of the argument Calendar and the start and stop times to determine the return value. If the day is not today it calculates the time between now and the day and start time of the duty schedule, saving the smallest of these as the return value as we iterate through the BitSet.???
        Parameters:
        nTime - The time to check.
        Returns:
        long - number of milliseconds
      • setStartHour

        public void setStartHour​(int anHour)
        This method sets the start time of this DutySchedule
        Parameters:
        anHour - The hour in military time to set the start time for the DutySchedule.
      • setEndHour

        public void setEndHour​(int anHour)
        This method sets the stop time of this DutySchedule
        Parameters:
        anHour - The hour in military time to set the end time for the DutySchedule.
      • toString

        public String toString()
        This method returns the DutySchedule formatted as a string that the DutySchedule(String) constructor could parse. The string will be formatted as such: - eg. MoWeFr800-1700, TuTh900-1500.
        Overrides:
        toString in class Object
        Returns:
        A string representation of this DutySchedule.
      • isInSchedule

        public boolean isInSchedule​(Date time)

        isInSchedule

        Parameters:
        time - a Date object.
        Returns:
        a boolean.
      • hasDay

        public boolean hasDay​(int aDay)

        hasDay

        Parameters:
        aDay - a int.
        Returns:
        a boolean.