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
IntervalCollectionandIntervalTree.
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
Nested ClassesModifier and TypeClassDescriptionstatic classServes for the creation of generic simple intervals on a timeline. -
Method Summary
Modifier and TypeMethodDescriptionbooleanabuts(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.booleancontains(ChronoInterval<T> other)Does this interval contain the other one?booleanQueries if given time point belongs to this interval.booleanfindIntersection(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.inthashCode()booleanIs this interval after the given time point?booleanisBefore(ChronoInterval<T> other)Is this interval before the other one?booleanIs this interval before the given time point?booleanisEmpty()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.Instantcan be created.static SimpleInterval.Factory<Date>Defines a timeline on which new intervals for the typejava.util.Datecan 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.Datecan be created.- Returns:
- singleton interval factory
-
onInstantTimeLine
Defines a timeline on which new intervals for the type
java.time.Instantcan 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:ChronoIntervalYields the lower bound of this interval.
- Specified by:
getStartin interfaceChronoInterval<T>- Returns:
- start interval boundary
-
getEnd
Description copied from interface:ChronoIntervalYields the upper bound of this interval.
- Specified by:
getEndin interfaceChronoInterval<T>- Returns:
- end interval boundary
-
isEmpty
public boolean isEmpty()Description copied from interface:ChronoIntervalDetermines if this interval is empty.
- Specified by:
isEmptyin interfaceChronoInterval<T>- Returns:
trueif this interval does not contain any time point elsefalse
-
contains
Description copied from interface:ChronoIntervalQueries if given time point belongs to this interval.
- Specified by:
containsin interfaceChronoInterval<T>- Parameters:
temporal- time point to be queried- Returns:
trueif given time point belongs to this interval elsefalse
-
contains
Description copied from interface:ChronoIntervalDoes 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:
containsin interfaceChronoInterval<T>- Parameters:
other- another interval whose relation to this interval is to be investigated- Returns:
trueif this interval contains the other one elsefalse- See Also:
ChronoInterval.intersects(ChronoInterval)
-
isAfter
Description copied from interface:ChronoIntervalIs this interval after the given time point?
- Specified by:
isAfterin interfaceChronoInterval<T>- Parameters:
temporal- reference time point- Returns:
trueif this interval is after given time point elsefalse
-
isBefore
Description copied from interface:ChronoIntervalIs this interval before the given time point?
- Specified by:
isBeforein interfaceChronoInterval<T>- Parameters:
temporal- reference time point- Returns:
trueif this interval is before given time point elsefalse
-
isBefore
Description copied from interface:ChronoIntervalIs this interval before the other one?
- Specified by:
isBeforein interfaceChronoInterval<T>- Parameters:
other- another interval whose relation to this interval is to be investigated- Returns:
trueif this interval is before the other one elsefalse
-
abuts
Description copied from interface:ChronoIntervalQueries 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:
abutsin interfaceChronoInterval<T>- Parameters:
other- another interval which might abut this interval- Returns:
trueif 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).
-