Package com.complexible.common.collect
Class SpoolingMarkResetIterator<T extends Copyable<T>>
java.lang.Object
com.complexible.common.collect.SpoolingMarkResetIterator<T>
- All Implemented Interfaces:
CloseableIterator<T>,Copyable<MarkResetIterator<T>>,MarkResetIterator<T>,ResettableIterator<T>,RestrictedMarkResetIterator<T>,AutoCloseable,Iterator<T>
public class SpoolingMarkResetIterator<T extends Copyable<T>>
extends Object
implements RestrictedMarkResetIterator<T>
A wrapper around
MarkResetSkippingIterator with bounded spooling: once the mark(T) method has been called, the iterator
will start spooling until one of the following conditions occurs:
1) the spooling threshold is reached, in which case the iterator switches to the skipping-based mark-reset
behavior.
2) the resetToMark() method is called, in which case the iterator starts returning the spooled elements.
Note: this implementation should only be used when marking the last returned element. Otherwise it is not able to retrieve the elements that are
between the mark and the current position after calling the resetToMark() method.
Similarly to MarkResetSkippingIterator this implementation does not close the base iterator.- Since:
- 8.0
- Author:
- Pavel Klinov
-
Nested Class Summary
Nested classes/interfaces inherited from interface com.complexible.common.base.CloseableIterator
CloseableIterator.AbstractCloseableIterator<T>, CloseableIterator.DelegatingCloseableIterator<T>, CloseableIterator.EmptyCloseableIterator<T> -
Constructor Summary
ConstructorsConstructorDescriptionSpoolingMarkResetIterator(PeekingSkippingIterator<T> theIterator, int theSpoolLimit) -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()copy()Create a deep copy of the object which does not share any references with the original.booleanhasNext()voidCreates a mark from the provided element.next()voidreset()Resets the iterator to the beginning so the followingIterator.next()call will return the first element in this iteration.voidRewinds the position of the iterator to the previously marked element.voidMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface java.util.Iterator
forEachRemaining, remove
-
Constructor Details
-
SpoolingMarkResetIterator
-
-
Method Details
-
restrict
- Specified by:
restrictin interfaceRestrictedMarkResetIterator<T extends Copyable<T>>
-
next
-
hasNext
public boolean hasNext() -
mark
Description copied from interface:MarkResetIteratorCreates a mark from the provided element.- Specified by:
markin interfaceMarkResetIterator<T extends Copyable<T>>
-
resetToMark
public void resetToMark()Description copied from interface:MarkResetIteratorRewinds the position of the iterator to the previously marked element.- Specified by:
resetToMarkin interfaceMarkResetIterator<T extends Copyable<T>>
-
close
public void close()- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseableIterator<T extends Copyable<T>>
-
reset
public void reset()Description copied from interface:ResettableIteratorResets the iterator to the beginning so the followingIterator.next()call will return the first element in this iteration.- Specified by:
resetin interfaceResettableIterator<T extends Copyable<T>>
-
copy
Description copied from interface:CopyableCreate a deep copy of the object which does not share any references with the original.
-