Class IsoRecurrence<I>

java.lang.Object
net.time4j.range.IsoRecurrence<I>
All Implemented Interfaces:
Iterable<I>

public class IsoRecurrence<I> extends Object implements Iterable<I>

Represents a sequence of recurrent finite intervals as defined by ISO-8601.

Since:
3.22/4.18
Author:
Meno Hochschild
  • 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 interval
      end - 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

      public static IsoRecurrence<DateInterval> of(int count, PlainDate start, PlainDate end)

      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 interval
      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 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 interval
      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, 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 interval
      end - 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

      public IsoRecurrence<I> withCount(int count)

      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

      public IsoRecurrence<I> 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

      public static IsoRecurrence<DateInterval> parseDateIntervals(String iso) throws ParseException

      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 ParseException

      Parses 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 and Iso8601Format.EXTENDED_DATE_TIME. A duration component will be parsed by Duration.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

      public static IsoRecurrence<MomentInterval> parseMomentIntervals(String iso) throws ParseException

      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 and Iso8601Format.EXTENDED_DATE_TIME_OFFSET. A duration component will be parsed by Duration.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

      public boolean equals(Object obj)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • toString

      public String 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
       
      Overrides:
      toString in class Object
      Returns:
      String
    • iterator

      public Iterator<I> iterator()
      Specified by:
      iterator in interface Iterable<I>
    • intervalStream

      public Stream<I> 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