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>,java.lang.AutoCloseable,java.util.Iterator<T>
public class SpoolingMarkResetIterator<T extends Copyable<T>> extends java.lang.Object implements RestrictedMarkResetIterator<T>
A wrapper aroundMarkResetSkippingIteratorwith bounded spooling: once themark(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 theskipping-basedmark-reset behavior. 2) theresetToMark()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 theresetToMark()method. Similarly toMarkResetSkippingIteratorthis 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
Constructors Constructor Description SpoolingMarkResetIterator(PeekingSkippingIterator<T> theIterator, int theSpoolLimit)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclose()RestrictedMarkResetIterator<T>copy()Create a deep copy of the object which does not share any references with the original.booleanhasNext()voidmark(T mark)Creates a mark from the provided element.Tnext()voidreset()Resets the iterator to the beginning so the followingIterator.next()call will return the first element in this iteration.voidresetToMark()Rewinds the position of the iterator to the previously marked element.voidrestrict(java.util.function.Predicate<T> restriction)
-
-
-
Constructor Detail
-
SpoolingMarkResetIterator
public SpoolingMarkResetIterator(PeekingSkippingIterator<T> theIterator, int theSpoolLimit)
-
-
Method Detail
-
restrict
public void restrict(java.util.function.Predicate<T> restriction)
- Specified by:
restrictin interfaceRestrictedMarkResetIterator<T extends Copyable<T>>
-
hasNext
public boolean hasNext()
-
mark
public void mark(T 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 interfacejava.lang.AutoCloseable- 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
public RestrictedMarkResetIterator<T> copy()
Description copied from interface:CopyableCreate a deep copy of the object which does not share any references with the original.
-
-