Class IsoRecurrence<I>
- All Implemented Interfaces:
Iterable<I>
Represents a sequence of recurrent finite intervals as defined by ISO-8601.
- Since:
- 3.22/4.18
- Author:
- Meno Hochschild
-
Method Summary
Modifier and TypeMethodDescriptionboolean
int
getCount()
Obtains the count of recurrent intervals.int
hashCode()
Obtains an ordered stream of recurrent intervals.boolean
Queries if the resulting interval stream describes a backwards running sequence.boolean
isEmpty()
Queries if the count of intervals is zero.boolean
Queries if the count of intervals is unlimited.iterator()
static IsoRecurrence<MomentInterval>
of(int count, Duration<?> duration, Moment end, ZonalOffset offset)
Creates a recurrent backward sequence of moment intervals having given duration.static IsoRecurrence<TimestampInterval>
of(int count, Duration<?> duration, PlainTimestamp end)
Creates a recurrent backward sequence of timestamp intervals having given duration.static IsoRecurrence<DateInterval>
of(int count, Duration<? extends IsoDateUnit> duration, PlainDate end)
Creates a recurrent backward sequence of date intervals having given duration.static IsoRecurrence<MomentInterval>
of(int count, Moment start, Duration<?> duration, ZonalOffset offset)
Creates a recurrent sequence of moment intervals having given duration.static IsoRecurrence<MomentInterval>
of(int count, Moment start, Moment end, ZonalOffset offset)
Creates a recurrent sequence of moment intervals having the duration of first timestamp interval in years, months, days, hours, minutes, seconds and nanoseconds.static IsoRecurrence<DateInterval>
of(int count, PlainDate start, Duration<? extends IsoDateUnit> duration)
Creates a recurrent sequence of date intervals having given duration.static IsoRecurrence<DateInterval>
Creates a recurrent sequence of date intervals having the duration of first interval in years, months and days.static IsoRecurrence<TimestampInterval>
of(int count, PlainTimestamp start, Duration<?> duration)
Creates a recurrent sequence of timestamp intervals having given duration.static IsoRecurrence<TimestampInterval>
of(int count, PlainTimestamp start, PlainTimestamp end)
Creates a recurrent sequence of timestamp intervals having the duration of first timestamp interval in years, months, days, hours, minutes, seconds and nanoseconds.static IsoRecurrence<DateInterval>
parseDateIntervals(String iso)
Parses a string like "R5/2016-04-01/2016-04-30" or "R5/2016-04-01/P1M" to a sequence of recurrent date intervals.static IsoRecurrence<MomentInterval>
parseMomentIntervals(String iso)
Parses a string like "R5/2016-04-01T10:45Z/30T23:59" to a sequence of recurrent moment intervals.static IsoRecurrence<TimestampInterval>
Parses a string like "R5/2016-04-01T10:45/2016-04-30T23:59" to a sequence of recurrent timestamp intervals.toString()
Yields a representation in extended ISO-format.withCount(int count)
Creates a copy with given modified count.Creates a copy with an unlimited count of recurrent intervals.Methods inherited from interface java.lang.Iterable
forEach, spliterator
-
Method Details
-
of
public static IsoRecurrence<DateInterval> of(int count, PlainDate start, Duration<? extends IsoDateUnit> duration)Creates a recurrent sequence of date intervals having given duration.
- Parameters:
count
- the count of repeating intervals (>= 0
)start
- denotes the start of first interval (inclusive)duration
- represents the duration of every repeating interval- Returns:
- sequence of recurrent closed date intervals
- Throws:
IllegalArgumentException
- if the count is negative or the duration is not positive
-
of
public static IsoRecurrence<DateInterval> of(int count, Duration<? extends IsoDateUnit> duration, PlainDate end)Creates a recurrent backward sequence of date intervals having given duration.
- Parameters:
count
- the count of repeating intervals (>= 0
)duration
- represents the negative duration of every repeating intervalend
- denotes the end of first interval (inclusive)- Returns:
- sequence of recurrent closed date intervals
- Throws:
IllegalArgumentException
- if the count is negative or the duration is not positive
-
of
Creates a recurrent sequence of date intervals having the duration of first interval in years, months and days.
- Parameters:
count
- the count of repeating intervals (>= 0
)start
- denotes the start of first interval (inclusive)end
- denotes the end of first interval (inclusive)- Returns:
- sequence of recurrent closed date intervals
- Throws:
IllegalArgumentException
- if the count is negative or if start is not before end
-
of
public static IsoRecurrence<TimestampInterval> of(int count, PlainTimestamp start, Duration<?> duration)Creates a recurrent sequence of timestamp intervals having given duration.
- Parameters:
count
- the count of repeating intervals (>= 0
)start
- denotes the start of first interval (inclusive)duration
- represents the duration of every repeating interval- Returns:
- sequence of recurrent half-open plain timestamp intervals
- Throws:
IllegalArgumentException
- if the count is negative or the duration is not positive
-
of
public static IsoRecurrence<TimestampInterval> of(int count, Duration<?> duration, PlainTimestamp end)Creates a recurrent backward sequence of timestamp intervals having given duration.
- Parameters:
count
- the count of repeating intervals (>= 0
)duration
- represents the negative duration of every repeating intervalend
- denotes the end of first interval (exclusive)- Returns:
- sequence of recurrent half-open plain timestamp intervals
- Throws:
IllegalArgumentException
- if the count is negative or the duration is not positive
-
of
public static IsoRecurrence<TimestampInterval> of(int count, PlainTimestamp start, PlainTimestamp end)Creates a recurrent sequence of timestamp intervals having the duration of first timestamp interval in years, months, days, hours, minutes, seconds and nanoseconds.
- Parameters:
count
- the count of repeating intervals (>= 0
)start
- denotes the start of first interval (inclusive)end
- denotes the end of first interval (exclusive)- Returns:
- sequence of recurrent half-open plain timestamp intervals
- Throws:
IllegalArgumentException
- if the count is negative or if start is not before end
-
of
public static IsoRecurrence<MomentInterval> of(int count, Moment start, Duration<?> duration, ZonalOffset offset)Creates a recurrent sequence of moment intervals having given duration.
- Parameters:
count
- the count of repeating intervals (>= 0
)start
- denotes the start of first interval (inclusive)duration
- represents the duration of every repeating intervaloffset
- time zone offset in full minutes- Returns:
- sequence of recurrent half-open plain timestamp intervals
- Throws:
IllegalArgumentException
- if the count is negative or the duration is not positive
-
of
public static IsoRecurrence<MomentInterval> of(int count, Duration<?> duration, Moment end, ZonalOffset offset)Creates a recurrent backward sequence of moment intervals having given duration.
- Parameters:
count
- the count of repeating intervals (>= 0
)duration
- represents the negative duration of every repeating intervalend
- denotes the end of first interval (exclusive)offset
- time zone offset in full minutes- Returns:
- sequence of recurrent half-open plain timestamp intervals
- Throws:
IllegalArgumentException
- if the count is negative or the duration is not positive
-
of
public static IsoRecurrence<MomentInterval> of(int count, Moment start, Moment end, ZonalOffset offset)Creates a recurrent sequence of moment intervals having the duration of first timestamp interval in years, months, days, hours, minutes, seconds and nanoseconds.
- Parameters:
count
- the count of repeating intervals (>= 0
)start
- denotes the start of first interval (inclusive)end
- denotes the end of first interval (exclusive)offset
- time zone offset in full minutes- Returns:
- sequence of recurrent half-open moment intervals
- Throws:
IllegalArgumentException
- if the count is negative or if start is not before end
-
getCount
public int getCount()Obtains the count of recurrent intervals.
- Returns:
- non-negative count of recurrent intervals or
-1
if infinite
-
withCount
Creates a copy with given modified count.
- Parameters:
count
- non-negative count of recurrent intervals- Returns:
- modified copy or this instance if not modified
- Throws:
IllegalArgumentException
- if the argument is negative
-
withInfiniteCount
Creates a copy with an unlimited count of recurrent intervals.
This method mainly exists to satisfy the requirements of ISO-8601. However: Special care must be taken to avoid infinite loops or streams.
- Returns:
- modified copy or this instance if not modified
-
isBackwards
public boolean isBackwards()Queries if the resulting interval stream describes a backwards running sequence.
- Returns:
- boolean
-
isEmpty
public boolean isEmpty()Queries if the count of intervals is zero.
- Returns:
- boolean
-
isInfinite
public boolean isInfinite()Queries if the count of intervals is unlimited.
- Returns:
- boolean
-
parseDateIntervals
Parses a string like "R5/2016-04-01/2016-04-30" or "R5/2016-04-01/P1M" to a sequence of recurrent date intervals.
- Parameters:
iso
- canonical representation of recurrent date intervals- Returns:
- parsed sequence of recurrent closed date intervals
- Throws:
ParseException
- in any case of inconsistencies
-
parseTimestampIntervals
public static IsoRecurrence<TimestampInterval> parseTimestampIntervals(String iso) throws ParseExceptionParses a string like "R5/2016-04-01T10:45/2016-04-30T23:59" to a sequence of recurrent timestamp intervals.
Supported ISO-formats for timestamp parts are
Iso8601Format.BASIC_DATE_TIME
andIso8601Format.EXTENDED_DATE_TIME
. A duration component will be parsed byDuration.parsePeriod(String)
.- Parameters:
iso
- canonical representation of recurrent intervals- Returns:
- parsed sequence of recurrent half-open timestamp intervals
- Throws:
ParseException
- in any case of inconsistencies
-
parseMomentIntervals
Parses a string like "R5/2016-04-01T10:45Z/30T23:59" to a sequence of recurrent moment intervals.
Supported ISO-formats for moment parts are
Iso8601Format.BASIC_DATE_TIME_OFFSET
andIso8601Format.EXTENDED_DATE_TIME_OFFSET
. A duration component will be parsed byDuration.parsePeriod(String)
.- Parameters:
iso
- canonical representation of recurrent intervals- Returns:
- parsed sequence of recurrent half-open moment intervals
- Throws:
ParseException
- in any case of inconsistencies
-
equals
-
hashCode
public int hashCode() -
toString
Yields a representation in extended ISO-format.
Examples:
System.out.println( IsoRecurrence.of(5, PlainDate.of(2016, 8, 12), Duration.of(3, CalendarUnit.WEEKS)); // R5/2016-08-12/P3W System.out.println( IsoRecurrence.of(0, PlainTimestamp.of(2016, 8, 12, 10, 45), PlainTimestamp.of(2016, 8, 12, 12, 0) .withInfiniteCount()); // R/2016-08-12T10:45/2016-08-12T12:00
-
iterator
-
intervalStream
Obtains an ordered stream of recurrent intervals.
- Returns:
- Stream
- Since:
- 4.18
- See Also:
Spliterator.DISTINCT
,Spliterator.IMMUTABLE
,Spliterator.NONNULL
,Spliterator.ORDERED
,Spliterator.SIZED
,Spliterator.SUBSIZED
-