Class SimpleInterval<T>
- Type Parameters:
T
- generic type of timepoints on the underlying timeline
- All Implemented Interfaces:
Serializable
,ChronoInterval<T>
Generic interval class suitable for any type of timepoints on a timeline.
Represents an interval with following simplified features:
- If calendrical, then always closed else half-open with inclusive start and exclusive end.
- Supports infinite boundaries (exception to half-open-state or closed-state).
- Can be adapted to any foreign type as long as a timeline can be implemented.
- Can be used in conjunction with
IntervalCollection
andIntervalTree
.
This class is mainly intended to adapt foreign types like java.util.Date
. It is serializable
as long as the underlying timeline is serializable.
- Since:
- 3.25/4.21
- Author:
- Meno Hochschild
- See Also:
- Serialized Form
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic class
Serves for the creation of generic simple intervals on a timeline. -
Method Summary
Modifier and TypeMethodDescriptionboolean
abuts(ChronoInterval<T> other)
Queries if this interval abuts the other one such that there is neither any overlap nor any gap between.static SimpleInterval<Instant>
Creates a new interval between given boundaries.static SimpleInterval<Date>
Creates a new interval between given boundaries.boolean
contains(ChronoInterval<T> other)
Does this interval contain the other one?boolean
Queries if given time point belongs to this interval.boolean
findIntersection(ChronoInterval<T> other)
Obtains the intersection of this interval and other one if present.getEnd()
Yields the upper bound of this interval.getStart()
Yields the lower bound of this interval.int
hashCode()
boolean
Is this interval after the given time point?boolean
isBefore(ChronoInterval<T> other)
Is this interval before the other one?boolean
Is this interval before the given time point?boolean
isEmpty()
Determines if this interval is empty.static <T> SimpleInterval.Factory<T>
Defines a timeline on which new generic intervals can be created.static SimpleInterval.Factory<Instant>
Defines a timeline on which new intervals for the typejava.time.Instant
can be created.static SimpleInterval.Factory<Date>
Defines a timeline on which new intervals for the typejava.util.Date
can be created.print(ChronoPrinter<T> printer)
Prints this interval using a localized interval pattern.print(ChronoPrinter<T> printer, String intervalPattern)
Prints this interval in a custom format.static SimpleInterval<Instant>
Creates a new interval since given start.static SimpleInterval<Date>
Creates a new interval since given start.toString()
Returns a string in technical notation (suitable for debugging purposes).static SimpleInterval<Instant>
Creates a new interval until given end.static SimpleInterval<Date>
Creates a new interval until given end.Methods inherited from interface net.time4j.range.ChronoInterval
intersects, isAfter, isFinite
-
Method Details
-
between
Creates a new interval between given boundaries.
- Parameters:
start
- the start of interval (inclusive)end
- the end of interval (exclusive)- Returns:
- new interval (half-open)
-
between
Creates a new interval between given boundaries.
- Parameters:
start
- the start of interval (inclusive)end
- the end of interval (exclusive)- Returns:
- new interval (half-open)
- See Also:
MomentInterval.between(Instant, Instant)
-
since
Creates a new interval since given start.
- Parameters:
start
- the start of interval (inclusive)- Returns:
- new interval (half-open and infinite)
-
since
Creates a new interval since given start.
- Parameters:
start
- the start of interval (inclusive)- Returns:
- new interval (half-open and infinite)
- See Also:
MomentInterval.since(Instant)
-
until
Creates a new interval until given end.
- Parameters:
end
- the end of interval (exclusive)- Returns:
- new interval (open and infinite)
-
until
Creates a new interval until given end.
- Parameters:
end
- the end of interval (exclusive)- Returns:
- new interval (open and infinite)
- See Also:
MomentInterval.until(Instant)
-
onTraditionalTimeLine
Defines a timeline on which new intervals for the type
java.util.Date
can be created.- Returns:
- singleton interval factory
-
onInstantTimeLine
Defines a timeline on which new intervals for the type
java.time.Instant
can be created.- Returns:
- singleton interval factory
-
on
Defines a timeline on which new generic intervals can be created.
- Type Parameters:
T
- generic type of timepoints on the underlying timeline- Parameters:
timeLine
- the timeline definition- Returns:
- new interval factory
- Since:
- 5.0
-
getStart
Description copied from interface:ChronoInterval
Yields the lower bound of this interval.
- Specified by:
getStart
in interfaceChronoInterval<T>
- Returns:
- start interval boundary
-
getEnd
Description copied from interface:ChronoInterval
Yields the upper bound of this interval.
- Specified by:
getEnd
in interfaceChronoInterval<T>
- Returns:
- end interval boundary
-
isEmpty
public boolean isEmpty()Description copied from interface:ChronoInterval
Determines if this interval is empty.
- Specified by:
isEmpty
in interfaceChronoInterval<T>
- Returns:
true
if this interval does not contain any time point elsefalse
-
contains
Description copied from interface:ChronoInterval
Queries if given time point belongs to this interval.
- Specified by:
contains
in interfaceChronoInterval<T>
- Parameters:
temporal
- time point to be queried- Returns:
true
if given time point belongs to this interval elsefalse
-
contains
Description copied from interface:ChronoInterval
Does this interval contain the other one?
An interval cannot contain infinite intervals but can contain an empty interval if it contains the start anchor of the empty interval.
- Specified by:
contains
in interfaceChronoInterval<T>
- Parameters:
other
- another interval whose relation to this interval is to be investigated- Returns:
true
if this interval contains the other one elsefalse
- See Also:
ChronoInterval.intersects(ChronoInterval)
-
isAfter
Description copied from interface:ChronoInterval
Is this interval after the given time point?
- Specified by:
isAfter
in interfaceChronoInterval<T>
- Parameters:
temporal
- reference time point- Returns:
true
if this interval is after given time point elsefalse
-
isBefore
Description copied from interface:ChronoInterval
Is this interval before the given time point?
- Specified by:
isBefore
in interfaceChronoInterval<T>
- Parameters:
temporal
- reference time point- Returns:
true
if this interval is before given time point elsefalse
-
isBefore
Description copied from interface:ChronoInterval
Is this interval before the other one?
- Specified by:
isBefore
in interfaceChronoInterval<T>
- Parameters:
other
- another interval whose relation to this interval is to be investigated- Returns:
true
if this interval is before the other one elsefalse
-
abuts
Description copied from interface:ChronoInterval
Queries if this interval abuts the other one such that there is neither any overlap nor any gap between.
Note: Empty intervals never abut.
- Specified by:
abuts
in interfaceChronoInterval<T>
- Parameters:
other
- another interval which might abut this interval- Returns:
true
if there is no intersection and no gap between elsefalse
-
findIntersection
Obtains the intersection of this interval and other one if present.
Note that the return type of the method is for the older version line v3.25 or later just
SimpleInterval<T>
, possibly returningnull
.- Parameters:
other
- another interval which might have an intersection with this interval- Returns:
- a wrapper around the found intersection or an empty wrapper
- Since:
- 4.21
- See Also:
Optional.isPresent()
,ChronoInterval.intersects(ChronoInterval)
-
print
Prints this interval using a localized interval pattern.
If given printer does not contain a reference to a locale then the interval pattern "{0}/{1}" will be used.
- Parameters:
printer
- format object for printing start and end- Returns:
- localized formatted string
- See Also:
print(ChronoPrinter, String)
,FormatPatternProvider.getIntervalPattern(Locale)
-
print
Prints this interval in a custom format.
- Parameters:
printer
- format object for printing start and end componentsintervalPattern
- interval pattern containing placeholders {0} and {1} (for start and end)- Returns:
- formatted string in given pattern format
-
equals
-
hashCode
public int hashCode() -
toString
Returns a string in technical notation (suitable for debugging purposes).
-