java.time
You are using nasty old legacy classes that are now superseded by java.time classes.
DayOfWeek
The java.time.DayOfWeek class is an enumeration that already defines seven objects, one for each day of the week. They are numbered in the standard order of ISO 8601, 1-7 for Monday through Sunday.
Make WeekTimeSlot class
It seems that you want to introduce the general idea of ββthe day of the week and time of day. You do not nail certain points on the timeline. Therefore, to start and stop, only the LocalTime class is LocalTime . This class has no date and no time zone.
I suggest defining a class with at least three members:
You can also track the length of time for each slot, rather than re-calculate at run time.
Enumerations are intended for a limited number of objects whose values ββare known at compile time. I expect your values ββto change at runtime for different semesters / quarters. Therefore, it is not suitable for transfers.
EnumMap
If you want to group slots by day of the week, use EnumMap . This Map implementation is optimized for use when key values ββare enumerated objects. You would map a DayOfWeek object to a List<WeekTimeSlot> .
This Map implementation takes up very little memory and is very fast.
Timeline Moment
If you need to apply these slots to a specific point on a specific day on the actual timeline, use LocalTime along with LocalDate and ZoneId to get ZonedDateTime .
You can find the Interval class from ThreeTen-Extra , an extension of the java.time classes. This class represents the time interval between a pair of moments on the timeline.
source share