Package com.complexible.common.collect
Class AbstractSkippingIterator<T>
- java.lang.Object
-
- com.complexible.common.collect.AbstractSkippingIterator<T>
-
- All Implemented Interfaces:
CloseableIterator<T>,PeekingSkippingIterator<T>,ResettableIterator<T>,SkippingIterator<T>,com.google.common.collect.PeekingIterator<T>,java.lang.AutoCloseable,java.util.Iterator<T>
- Direct Known Subclasses:
MarkResetSkippingIterator
public abstract class AbstractSkippingIterator<T> extends java.lang.Object implements PeekingSkippingIterator<T>, CloseableIterator<T>
Abstract
SkippingIteratorimplementation to help with concrete implementations. The remove function of this implementation throwsUnsupportedOperationExceptionand its size estimate isunknown.- Version:
- 2.2.1
- Author:
- Evren Sirin, Pavel Klinov, Michael Grove
-
-
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 Modifier and Type Field Description protected java.util.Comparator<T>mComparatorThe comparator which defines the order for skipping-
Fields inherited from interface com.complexible.common.collect.SkippingIterator
UNKNOWN_SIZE
-
-
Constructor Summary
Constructors Constructor Description AbstractSkippingIterator(java.util.Comparator<T> theComparator)
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected voidassertOpen()voidclose()java.util.Comparator<T>comparator()Returns the comparator for this iterator that specifies the order in which the elements are returned.protected abstract TcomputeNext()Return the next element to be returned by the iteratorprotected abstract TcomputeSkipTo(T theTarget)Returns the element that this iteration has skipped to ornullif it ran off the end.protected TcomputeSkipTo(T theTarget, T theBound)protected TendOfData()Signal that you're done iterating.longestimatedSize()Returns the estimated size of this iterator without advancing the iterator orSkippingIterator.UNKNOWN_SIZEif the estimate is not known.booleanhasNext()protected booleanisClosed()booleanisLessOrEqualThan(T theElement, T theBound)Tnext()Tpeek()Implementation of peeking to the next item returned by the iterator.protected abstract voidperformReset()voidremove()voidreset()Resets the iterator to the beginning so the followingIterator.next()call will return the first element in this iteration.protected voidresetState()booleanskipTo(T theElement)Moves the iterators position to the next element which is greater than or equal totheElement.booleanskipTo(T theElement, T theBound)Same contract asSkippingIterator.skipTo(Object)but skipping is bounded: if the implementation can determine that the next element after target is greater than the bound, it can return false.protected voidvalidateSkipTarget(T theTarget)
-
-
-
Field Detail
-
mComparator
protected final java.util.Comparator<T> mComparator
The comparator which defines the order for skipping
-
-
Constructor Detail
-
AbstractSkippingIterator
public AbstractSkippingIterator(java.util.Comparator<T> theComparator)
-
-
Method Detail
-
comparator
public java.util.Comparator<T> comparator()
Returns the comparator for this iterator that specifies the order in which the elements are returned.- Specified by:
comparatorin interfaceSkippingIterator<T>
-
estimatedSize
public long estimatedSize()
Returns the estimated size of this iterator without advancing the iterator orSkippingIterator.UNKNOWN_SIZEif the estimate is not known. The estimate is for the whole iterator and will not change after the iterator is advanced. There is no guarantee about the accuracy of the estimate.- Specified by:
estimatedSizein interfaceSkippingIterator<T>
-
remove
public void remove()
-
computeNext
protected abstract T computeNext()
Return the next element to be returned by the iterator- Returns:
- the next element
-
computeSkipTo
protected abstract T computeSkipTo(T theTarget)
Returns the element that this iteration has skipped to ornullif it ran off the end.- Parameters:
theTarget- the skipping target- Returns:
- the first element that is greater or equal to the skipping
target, or
nullif it doesn't exist.
-
next
public final T next()
-
endOfData
protected final T endOfData()
Signal that you're done iterating.- Returns:
- nothing, the result is ignored
-
hasNext
public final boolean hasNext()
- Specified by:
hasNextin interfacejava.util.Iterator<T>
-
close
public void close()
- Specified by:
closein interfacejava.lang.AutoCloseable- Specified by:
closein interfaceCloseableIterator<T>
-
peek
public final T peek()
Implementation of peeking to the next item returned by the iterator. Anyone wishing to expose this method simply need to also implement thePeekingIteratorinterface.- Specified by:
peekin interfacecom.google.common.collect.PeekingIterator<T>- Returns:
- the next element to be returned
-
skipTo
public final boolean skipTo(T theElement)
Description copied from interface:SkippingIteratorMoves the iterators position to the next element which is greater than or equal totheElement.- Specified by:
skipToin interfaceSkippingIterator<T>- Returns:
- true, if such an element exists (in which case the
Iterator.next()call will return it), false otherwise
-
skipTo
public final boolean skipTo(T theElement, T theBound)
Same contract asSkippingIterator.skipTo(Object)but skipping is bounded: if the implementation can determine that the next element after target is greater than the bound, it can return false. In other words, if the method returns false, no element between the target (incl.) and the bound (incl.) exists. If the method returns true, the next element is definitely greater or equal than the target, but may exceed the bound. If the method returns false, there's no guarantee on the state of the iterator. If it needs to be reused, it must be first reset.- Specified by:
skipToin interfaceSkippingIterator<T>- Parameters:
theElement- the targettheBound- the bound. null means no upper bound.- Returns:
- true, if an element that is greater than or equal to
theElementbut less than or equal totheBoundexists.
-
validateSkipTarget
protected void validateSkipTarget(T theTarget)
-
reset
public final void reset()
Resets the iterator to the beginning so the followingIterator.next()call will return the first element in this iteration.- Specified by:
resetin interfaceResettableIterator<T>
-
isClosed
protected boolean isClosed()
-
assertOpen
protected void assertOpen()
-
resetState
protected final void resetState()
-
performReset
protected abstract void performReset()
-
-