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 aroundMarkResetSkippingIterator
with 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-based
mark-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 toMarkResetSkippingIterator
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
Constructors Constructor Description SpoolingMarkResetIterator(PeekingSkippingIterator<T> theIterator, int theSpoolLimit)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
close()
RestrictedMarkResetIterator<T>
copy()
Create a deep copy of the object which does not share any references with the original.boolean
hasNext()
void
mark(T mark)
Creates a mark from the provided element.T
next()
void
reset()
Resets the iterator to the beginning so the followingIterator.next()
call will return the first element in this iteration.void
resetToMark()
Rewinds the position of the iterator to the previously marked element.void
restrict(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:
restrict
in interfaceRestrictedMarkResetIterator<T extends Copyable<T>>
-
hasNext
public boolean hasNext()
-
mark
public void mark(T mark)
Description copied from interface:MarkResetIterator
Creates a mark from the provided element.- Specified by:
mark
in interfaceMarkResetIterator<T extends Copyable<T>>
-
resetToMark
public void resetToMark()
Description copied from interface:MarkResetIterator
Rewinds the position of the iterator to the previously marked element.- Specified by:
resetToMark
in interfaceMarkResetIterator<T extends Copyable<T>>
-
close
public void close()
- Specified by:
close
in interfacejava.lang.AutoCloseable
- Specified by:
close
in interfaceCloseableIterator<T extends Copyable<T>>
-
reset
public void reset()
Description copied from interface:ResettableIterator
Resets the iterator to the beginning so the followingIterator.next()
call will return the first element in this iteration.- Specified by:
reset
in interfaceResettableIterator<T extends Copyable<T>>
-
copy
public RestrictedMarkResetIterator<T> copy()
Description copied from interface:Copyable
Create a deep copy of the object which does not share any references with the original.
-
-