我不认为有任何现成的用于joda-time或Java Calendar
API的迭代器,但是使用joda是如此简单,您应该使用它。例如,在暂停几个月后重新熟悉了joda之后,我在大约10分钟的时间内完成了此 *** 作:
public class InstantIterator implements Iterator<Instant>, Iterable<Instant> { private Instant current; private final Instant original; private Duration skip; private List<Instant> skipThese; public InstantIterator(Instant startFrom, Duration skip) { this.current = original = startFrom; this.skip = skip; skipThese = new Vector<Instant>(); } public boolean hasNext() { return true; } public Instant next() { Instant currentNext = current.toInstant(); current = current.plus(skip); while (skipThese.contains(currentNext)) { currentNext = current.toInstant(); current = current.plus(skip); } return currentNext; } public void remove() { skipThese.add(current.toInstant()); } public Iterator<Instant> iterator() { return this; } public void rewind() { current = original.toInstant(); } public void resetRemoved() { skipThese.clear(); } public void resetIterator() { rewind(); resetRemoved(); }}
乔达时间真棒:-)
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)