Package org.salespointframework.time
Class Interval
- java.lang.Object
-
- org.salespointframework.time.Interval
-
public final class Interval extends Object
Simple value object to represent time intervals. Note that whether the endpoints are included or not can vary between the offered methods.- Author:
- Oliver Drotbohm, Martin Morgenstern
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
Interval.IntervalBuilder
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
contains(LocalDateTime reference)
Returns whether the givenLocalDateTime
is contained in the currentInterval
.boolean
equals(Object o)
static Interval.IntervalBuilder
from(LocalDateTime start)
Starts building a newInterval
with the given start time.Duration
getDuration()
Returns the duration of the interval, with the end excluded.LocalDateTime
getEnd()
The end date of theInterval
.LocalDateTime
getStart()
The start date of theInterval
.int
hashCode()
boolean
overlaps(Interval reference)
Returns whether the currentInterval
overlaps with the given one.Duration
toDuration()
String
toString()
-
-
-
Method Detail
-
from
public static Interval.IntervalBuilder from(LocalDateTime start)
Starts building a newInterval
with the given start time.- Parameters:
start
- must not be null.- Returns:
- will never be null.
-
getDuration
public Duration getDuration()
Returns the duration of the interval, with the end excluded.- Returns:
- will never be null.
-
contains
public boolean contains(LocalDateTime reference)
Returns whether the givenLocalDateTime
is contained in the currentInterval
. The comparison includes start and end, i.e., the method treats this interval as closed.- Parameters:
reference
- must not be null.- Returns:
-
overlaps
public boolean overlaps(Interval reference)
Returns whether the currentInterval
overlaps with the given one. The comparison excludes start and end, i.e., the method treats both intervals as open.- Parameters:
reference
- must not be null.- Returns:
-
toDuration
public Duration toDuration()
- Returns:
-
getStart
public LocalDateTime getStart()
The start date of theInterval
.
-
getEnd
public LocalDateTime getEnd()
The end date of theInterval
.
-
-