In many projects I find myself implementing my own IterableInterval class which implements Iterable<datetime>. Just thought it may be a welcome addition.
Thanks for a great library! I'm an evangelist. Eric Winter, Rochester, MN, USA</datetime>
public class IterableInverval extends AbstractInterval implements Iterable<datetime> {
private final Interval interval;
private final Period period; </datetime>
public IterableInverval(Interval interval, Period period){
this.interval = interval;
this.period = (period != null ? period : Period.days(1));
}
public IterableInverval(DateTime start, DateTime end, Period spread){
this(new Interval(start, end), spread);
}
public Iterator<DateTime> iterator() {
return new Iterator<DateTime>(){
private DateTime next = interval.getStart();
public boolean hasNext() {
return interval.getEnd()==null || interval.getEnd().isAfter(next);
}
public DateTime next() {
if(!hasNext()) throw new NoSuchElementException("There are no more dates in the range.");
DateTime oldNext = next;
next = next.plus(period);
return oldNext;
}
public void remove() {
throw new UnsupportedOperationException();
}
};
}
public Period getPeriod(){
return this.period;
}
@Override
public Interval toInterval(){
return interval;
}
public Chronology getChronology() {
return this.interval.getChronology();
}
public long getEndMillis() {
return this.interval.getEndMillis();
}
public long getStartMillis() {
return this.interval.getStartMillis();
}
}
An interesting idea, worth pursuing,