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
-
Constructor Summary
ConstructorDescriptionTimeWindow
(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 TypeMethodDescriptionint
static String
getAsString
(TimeWindow hours, ZoneId zoneId) Gets the beginning hours and the end hours in the formatdd.MM.yyyy HH:mm:ss
and the zoneId.getBegin()
Gets the begin as instant.Gets the duration betweengetBegin()
andgetEnd()
.getEnd()
Gets the end as instant.long
Gets the begin in millis, the default value is 0L.long
Gets 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()
.long
Gets the time in millis betweengetHoursEndInMillis()
andgetHoursBeginInMillis()
.Gets theZoneId
,static boolean
hasOverlap
(TimeWindow w1, TimeWindow w2) Checks for overlap.boolean
Checks ifgetHoursBeginInMillis()
andgetHoursEndInMillis()
are the same as the one of the input.boolean
void
setHoursBeginInMillis
(long hoursBeginInMillis) Sets the begin in millis.void
setHoursEndInMillis
(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:
compareTo
in 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
Duration
between 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:ss
and 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 anInvalidElementCreationException
exception 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
-