Package com.complexible.common.collect
Class SpoolingMarkResetIterator<T extends Copyable<T>>
- java.lang.Object
-
- com.complexible.common.collect.AbstractSkippingIterator<T>
-
- com.complexible.common.collect.SpoolingMarkResetIterator<T>
-
- All Implemented Interfaces:
CloseableIterator<T>
,Copyable<MarkResetIterator<T>>
,MarkResetIterator<T>
,PeekingSkippingIterator<T>
,ResettableIterator<T>
,SkippingIterator<T>
,com.google.common.collect.PeekingIterator<T>
,java.lang.AutoCloseable
,java.util.Iterator<T>
public class SpoolingMarkResetIterator<T extends Copyable<T>> extends AbstractSkippingIterator<T> implements MarkResetIterator<T>
A wrapper aroundMarkResetSkippingIterator
with bounded spooling: once themark(Copyable)
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>
-
-
Field Summary
-
Fields inherited from class com.complexible.common.collect.AbstractSkippingIterator
mComparator
-
Fields inherited from interface com.complexible.common.collect.SkippingIterator
UNKNOWN_SIZE
-
-
Constructor Summary
Constructors Constructor Description SpoolingMarkResetIterator(SkippingIterator<T> theIterator, int theSpoolLimit)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
close()
protected T
computeNext()
Return the next element to be returned by the iteratorprotected T
computeSkipTo(T theTarget)
Returns the element that this iteration has skipped to ornull
if it ran off the end.MarkResetIterator<T>
copy()
Create a deep copy of the object which does not share any references with the original.void
mark(T mark)
Creates a mark from the provided element.void
performReset()
void
resetToMark()
Rewinds the position of the iterator to the previously marked element.-
Methods inherited from class com.complexible.common.collect.AbstractSkippingIterator
assertOpen, comparator, computeSkipTo, endOfData, estimatedSize, hasNext, isClosed, isLessOrEqualThan, next, peek, remove, reset, resetState, skipTo, skipTo, validateSkipTarget
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface com.complexible.common.collect.ResettableIterator
reset
-
-
-
-
Constructor Detail
-
SpoolingMarkResetIterator
public SpoolingMarkResetIterator(SkippingIterator<T> theIterator, int theSpoolLimit)
-
-
Method Detail
-
computeNext
protected T computeNext()
Description copied from class:AbstractSkippingIterator
Return the next element to be returned by the iterator- Specified by:
computeNext
in classAbstractSkippingIterator<T extends Copyable<T>>
- Returns:
- the next element
-
computeSkipTo
protected T computeSkipTo(T theTarget)
Description copied from class:AbstractSkippingIterator
Returns the element that this iteration has skipped to ornull
if it ran off the end.- Specified by:
computeSkipTo
in classAbstractSkippingIterator<T extends Copyable<T>>
- Parameters:
theTarget
- the skipping target- Returns:
- the first element that is greater or equal to the skipping
target, or
null
if it doesn't exist.
-
mark
public void mark(T mark)
Description copied from interface:MarkResetIterator
Creates a mark from the provided element. Note: the reset-to-mark behavior is only guaranteed if the mark is a part of the iterator's output. Specific implementations may impose other restrictions, for example, on the mark being ahead or behind the current iterator's position.- Specified by:
mark
in interfaceMarkResetIterator<T extends Copyable<T>>
- Parameters:
mark
- the element to serve as a mark
-
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()
Description copied from class:AbstractSkippingIterator
- Specified by:
close
in interfacejava.lang.AutoCloseable
- Specified by:
close
in interfaceCloseableIterator<T extends Copyable<T>>
- Overrides:
close
in classAbstractSkippingIterator<T extends Copyable<T>>
-
performReset
public void performReset()
- Specified by:
performReset
in classAbstractSkippingIterator<T extends Copyable<T>>
-
-