Package nl.vpro.util
Interface CountedIterator<T>
- All Superinterfaces:
AutoCloseable
,CloseableIterator<T>
,Counted
,Iterator<T>
- All Known Subinterfaces:
CountedPeekingIterator<T>
- All Known Implementing Classes:
BasicWrappedIterator
,CallbackIterator
,CountedMaxOffsetIterator
,LazyIterator
,MergedSortedIterator
,TailAdder
,WrappedIterator
An iterator that is also aware of the current position
getCount()
, and optionally of the size of the object that is iterated getSize()
, and also optionally of a 'total' size (in case this iterator presents some sub-collection) getTotalSize()
.- Since:
- 0.31
- Author:
- Michiel Meeuwissen
-
Nested Class Summary
Nested classes/interfaces inherited from interface nl.vpro.util.CloseableIterator
CloseableIterator.WrappedCloseableIterator<S>, CloseableIterator.WrappedPeekingCloseableIterator<S>
-
Method Summary
Modifier and TypeMethodDescriptiondefault void
close()
getCount()
The current position.getSize()
The size, if known, of the collection this iterator is representingIf the iterator is in some way restricted you may also want to report a total size, representing the unrestricted size.static <C> CountedIterator<C>
static <S> CountedIterator<S>
of
(Collection<S> wrapped) static <C> CountedIterator<C>
of
(AtomicLong size, Iterator<C> wrapped) static <S> CountedIterator<S>
default CountedPeekingIterator<T>
peeking()
If you need a guavaPeekingIterator
, this will make you one.static <S> CountedPeekingIterator<S>
peeking
(CountedIterator<S> wrapped) default Spliterator<T>
Returns this iterator asSpliterator
.stream()
Methods inherited from interface java.util.Iterator
forEachRemaining, hasNext, next, remove
-
Method Details
-
of
-
peeking
-
of
-
of
-
of
-
getSize
The size, if known, of the collection this iterator is representing -
getCount
Long getCount()The current position. Will return1
after first successfull call toIterator.next()
,2
after the second one, and so on. It will return0
before the first call. -
getTotalSize
If the iterator is in some way restricted you may also want to report a total size, representing the unrestricted size.The default implementation is
getSize()
. -
spliterator
Returns this iterator asSpliterator
. -
close
- Specified by:
close
in interfaceAutoCloseable
- Throws:
Exception
-
stream
- Specified by:
stream
in interfaceCloseableIterator<T>
-
peeking
If you need a guavaPeekingIterator
, this will make you one. It remains also aCountedIterator
- Specified by:
peeking
in interfaceCloseableIterator<T>
-