java.lang.Object
io.aiven.commons.util.collections.ExtendedIterator<T>
- Type Parameters:
T- The type of object returned from the iterator.
- All Implemented Interfaces:
Iterator<T>
An ExtendedIterator is an Iterator wrapping around a plain (or presented as plain) Iterator. The
wrapping allows the usual operations found on streams (filtering, concatenating, mapping) to be
done on an Iterator derived from some other source. It also provides convenience methods for
common operations.
-
Method Summary
Modifier and TypeMethodDescription<U extends Collection<T>>
UaddTo(U collection) A method to add the remaining elements in the iterator an arbitrary collection.<X extends T>
ExtendedIterator<T>Chains theotheriterator to the end of this one.static <T> ExtendedIterator<T>Answer an ExtendedIterator returning the elements ofit.static <T> ExtendedIterator<T>Answer an ExtendedIterator wrapped round aStream.static <T> ExtendedIterator<T>createNoRemove(Iterator<T> it) Answer an ExtendedIterator wrapped roundit, which does not permit.remove()even ifitdoes.static ExtendedIterator<?>An empty Extended iteratorFilter this iterator using a predicate.static <T> ExtendedIterator<T>Given an Iterator that returns Iterators, this creates an Iterator over the next level values.voidforEachRemaining(Consumer<? super T> action) booleanhasNext()<U> ExtendedIterator<U>Map the elements of the iterator to a now type.next()voidremove()Returns the next item and removes it from the iterator.
-
Method Details
-
createNoRemove
Answer an ExtendedIterator wrapped roundit, which does not permit.remove()even ifitdoes.- Type Parameters:
T- The object type returned by the iterator.- Parameters:
it- The Iterator to wrap.- Returns:
- an Extended iterator on
it
-
create
Answer an ExtendedIterator wrapped round aStream. The extended iterator does not permit.remove().The stream should not be used directly. The effect of doing so is undefined.
- Type Parameters:
T- The object type returned by the iterator.- Parameters:
stream- the Stream to create an iterator from.- Returns:
- an Extended iterator on the
streamiterator.
-
flatten
Given an Iterator that returns Iterators, this creates an Iterator over the next level values. Similar to list splicing in lisp.- Type Parameters:
T- The object type returned by the iterator.- Parameters:
it- An iterator of iterators.- Returns:
- An iterator over the logical concatenation of the inner iterators.
-
emptyIterator
An empty Extended iterator- Returns:
- An empty Extended iterator.
-
create
Answer an ExtendedIterator returning the elements ofit. Ifitis itself an ExtendedIterator, return that; otherwise wrapit.- Type Parameters:
T- The object type returned by the iterator.- Parameters:
it- The iterator to wrap.- Returns:
- An Extended iterator wrapping
it
-
hasNext
public boolean hasNext() -
next
-
forEachRemaining
- Specified by:
forEachRemainingin interfaceIterator<T>
-
remove
public void remove() -
removeNext
Returns the next item and removes it from the iterator.- Returns:
- the next item from the iterator.
-
andThen
Chains theotheriterator to the end of this one.- Type Parameters:
X- The type of object returned from the other iterator.- Parameters:
other- the other iterator to extend this iterator with.- Returns:
- A new iterator returning the contents of
thisiterator followed by the contents ofother{ iterator.}
-
filter
Filter this iterator using a predicate. Only items for which the predicate returnstruewill be included in the result.- Parameters:
predicate- The predicate to filter the items with.- Returns:
- An iterator filtered by the predicate.
-
map
Map the elements of the iterator to a now type.- Type Parameters:
U- The object type to return.- Parameters:
function- The function to map elements of<T>to type<U>.- Returns:
- An Extended iterator that returns a
<U>for very<T>in the original iterator.
-
addTo
A method to add the remaining elements in the iterator an arbitrary collection. This method consumes the iterator.- Type Parameters:
U- A collection of objects of type<T>.- Parameters:
collection- THe collection to add elements to.- Returns:
- the
collectionwith the elements added.
-