/** * Constructor. * * @param period The period to divide the interval by * @param baseInterval The raw interval which is to be divided */ public IntervalPeriodIterator(@NotNull ReadablePeriod period, Interval baseInterval) { this.period = period; intervalStart = baseInterval.getStart(); intervalEnd = baseInterval.getEnd(); position = 0; currentPosition = boundaryAt(0); // Chronology accepts null periods, we must not do so or this iterator is non-terminating if (period == null) { throw new IllegalArgumentException("Period cannot be null"); } }
@Override public Interval next() { if (!hasNext()) { throw new NoSuchElementException(); } position += 1; DateTime nextPosition = ObjectUtils.min(intervalEnd, boundaryAt(position)); Interval result = new Interval(currentPosition, nextPosition); currentPosition = nextPosition; return result; }