Package dev.enola.common.time
Record Class Interval
java.lang.Object
java.lang.Record
dev.enola.common.time.Interval
- Record Components:
start- the start instant, inclusiveend- the end instant, exclusive
Interval of time on the time-line from a start to an end instant.
The start is inclusive, and the end exclusive ("half-open").
The end instant is always greater than or equal to the start instant.
Intervals are intentionally not Comparable.
This is inspired by:
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionend()Gets the end of this time interval, exclusive.static IntervalObtains an instance of Interval with unbounded start and the specified end instant.final booleanIndicates whether some other object is "equal to" this one.final inthashCode()Returns a hash code value for this object.booleanisEmpty()Checks if the range is empty.booleanChecks if the end of the interval is unbounded (i.e.booleanChecks if the start of the interval is unbounded (i.e.static IntervalObtains an instance of Interval from the start and end instant.start()Gets the start of this time interval, inclusive.static IntervalstartingAt(Instant startInclusive) Obtains an instance of Interval with the specified start instant and unbounded end.toString()Outputs this interval as aStringin ISO-8601 compliant format, such as e.g.
-
Field Details
-
ALL
An interval over the whole time-line.
-
-
Constructor Details
-
Interval
Deprecated.The static factory method should be preferred.Constructor, identical toof(Instant, Instant).
-
-
Method Details
-
of
Obtains an instance of Interval from the start and end instant.- Parameters:
startInclusive- the start instant, inclusive,Instant.MINtreated as unbounded, not nullendExclusive- the end instant, exclusive,Instant.MAXtreated as unbounded, not null- Returns:
- the half-open interval, not null
-
startingAt
Obtains an instance of Interval with the specified start instant and unbounded end.- Parameters:
startInclusive- the start instant, inclusive, not null- Returns:
- a new Instant with the specified start instant, not null
-
endAt
Obtains an instance of Interval with unbounded start and the specified end instant.- Parameters:
endExclusive- the end instant, exclusive, not null- Returns:
- a new Instant with the specified end instant, not null
-
start
Gets the start of this time interval, inclusive.This will return
Instant.MINif the range is unbounded at the start. In this case, the range includes all dates into the far-past.- Returns:
- the start of the time interval, inclusive, not null
-
end
Gets the end of this time interval, exclusive.This will return
Instant.MAXif the range is unbounded at the end. In this case, the range includes all dates into the far-future.- Returns:
- the end of the time interval, exclusive, not null
-
isUnboundedStart
Checks if the start of the interval is unbounded (i.e. equalsInstant.MIN).- Returns:
- true if start is unbounded
-
isUnboundedEnd
Checks if the end of the interval is unbounded (i.e. equalsInstant.MAX).- Returns:
- true if end is unbounded
-
isEmpty
Checks if the range is empty.An empty range occurs when the start date equals the inclusive end date.
- Returns:
- true if the range is empty
-
toString
Outputs this interval as aStringin ISO-8601 compliant format, such as e.g.2007-12-03T10:15:30/2007-12-04T10:15:30.An
ALLis printed as -1000000000-01-01T00:00:00Z/+1000000000-12-31T23:59:59.999999999Z; other Intervals with an unbounded start or end date similarly. -
hashCode
Returns a hash code value for this object. The value is derived from the hash code of each of the record components. -
equals
Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. All components in this record class are compared withObjects::equals(Object,Object).
-