Package com.dna.jopt.member.unit.hours
Class TimeWindow
java.lang.Object
com.dna.jopt.member.unit.hours.TimeWindow
- All Implemented Interfaces:
Serializable,Comparable<TimeWindow>
The Class TimeWindow.
- Since:
- Dec 16, 2019
- Version:
- Dec 16, 2019
- Author:
- Jens Richter
- See Also:
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionTimeWindow(long hoursBeginMillis, long hoursEndMillis, ZoneId zoneId) Instantiates a new time window.TimeWindow(Instant hoursBegin, Instant hoursEnd, ZoneId zoneId) Instantiates a new time window.TimeWindow(ZonedDateTime hoursBegin, ZonedDateTime hoursEnd) Instantiates a new time window. -
Method Summary
Modifier and TypeMethodDescriptionintstatic StringgetAsString(TimeWindow hours, ZoneId zoneId) Gets the beginning hours and the end hours in the formatdd.MM.yyyy HH:mm:ssand the zoneId.getBegin()Gets the begin as instant.Gets the duration betweengetBegin()andgetEnd().getEnd()Gets the end as instant.longGets the begin in millis, the default value is 0L.longGets the end in millis, the default value is 0L.com.google.common.collect.Range<Instant>getRange()Gets the range that contains all values betweengetBegin()andgetEnd().longGets the time in millis betweengetHoursEndInMillis()andgetHoursBeginInMillis().Gets theZoneId,static booleanhasOverlap(TimeWindow w1, TimeWindow w2) Checks for overlap.booleanChecks ifgetHoursBeginInMillis()andgetHoursEndInMillis()are the same as the one of the input.booleanvoidsetHoursBeginInMillis(long hoursBeginInMillis) Sets the begin in millis.voidsetHoursEndInMillis(long hoursEndInMillis) Sets the end in millis.toString()static List<TimeWindow>validateOverlapAndSort(List<TimeWindow> windows) Validate overlap and sort by start.
-
Field Details
-
START
The Comparator for START.
-
-
Constructor Details
-
TimeWindow
Instantiates a new time window.- Parameters:
hoursBegin- the hours beginhoursEnd- the hours end
-
TimeWindow
Instantiates a new time window.- Parameters:
hoursBegin- the hours beginhoursEnd- the hours endzoneId- the zone id
-
TimeWindow
Instantiates a new time window.- Parameters:
hoursBeginMillis- the hours begin millishoursEndMillis- the hours end milliszoneId- the zone id
-
-
Method Details
-
getHoursBeginInMillis
public long getHoursBeginInMillis()Gets the begin in millis, the default value is 0L.- Returns:
- the long hoursBeginInSecs
-
getHoursEndInMillis
public long getHoursEndInMillis()Gets the end in millis, the default value is 0L.- Returns:
- the long hoursBeginInSecs
-
setHoursBeginInMillis
public void setHoursBeginInMillis(long hoursBeginInMillis) Sets the begin in millis.- Parameters:
hoursBeginInMillis- the new hours begin in millis
-
setHoursEndInMillis
public void setHoursEndInMillis(long hoursEndInMillis) Sets the end in millis.- Parameters:
hoursEndInMillis- the new hours end in millis
-
getBegin
Gets the begin as instant.- Returns:
- the begin
-
getEnd
Gets the end as instant.- Returns:
- the begin
-
getCenter
-
getZonedEnd
-
getZonedBegin
-
getZonedCenter
-
toString
-
getZoneId
Gets theZoneId,If through deserialization the zoneId is null, the system default is returned.
- Returns:
- the zoneId
-
compareTo
- Specified by:
compareToin interfaceComparable<TimeWindow>
-
getStart2EndDurationMillis
public long getStart2EndDurationMillis()Gets the time in millis betweengetHoursEndInMillis()andgetHoursBeginInMillis().- Returns:
- the time between the two points in millis
-
getRange
Gets the range that contains all values betweengetBegin()andgetEnd().- Returns:
- the
range<instant>between the two instants
-
getDuration
Gets the duration betweengetBegin()andgetEnd().- Returns:
- the
Durationbetween the two instants
-
hasSameStartAndEnd
Checks ifgetHoursBeginInMillis()andgetHoursEndInMillis()are the same as the one of the input.- Parameters:
o- the TimeWindow input to check with the set parameters- Returns:
- the boolean if the given timeWindow o is the same as the set parameters
-
getAsString
Gets the beginning hours and the end hours in the formatdd.MM.yyyy HH:mm:ssand the zoneId.- Parameters:
hours- the time windowzoneId- the zoneId- Returns:
- the beginning and the end of the hours in the format dd.MM.yyyy HH:mm:ss
-
isFitting
-
validateOverlapAndSort
Validate overlap and sort by start. Throws anInvalidElementCreationExceptionexception in case input windows are overlapping.- Parameters:
windows- the windows- Returns:
- the list
-
hasOverlap
Checks for overlap.- Parameters:
w1- the w 1w2- the w 2- Returns:
- true, if successful
-