Package generic.util
Class FlattenedIterator<O,I>
java.lang.Object
generic.util.FlattenedIterator<O,I>
- Type Parameters:
O- the type of elements in the outer iteratorI- the type of elements in the inner and flattened iterators
- All Implemented Interfaces:
Iterator<I>
- Direct Known Subclasses:
AddressIteratorAdapter
Given an "outer" iterator and a mapping from its elements to "inner" iterators, this is a
flattened iterator over elements from the inner iterators.
-
Field Details
-
outer
-
innerFactory
-
inner
-
preppedInner
-
-
Constructor Details
-
FlattenedIterator
-
-
Method Details
-
start
public static <O,I> Iterator<I> start(Iterator<O> outer, Function<O, Iterator<? extends I>> innerFactory) Create a flattened iteratorThis iterates over each element of
outerand applies the giveninnerFactoryto generate an "inner" iterator. The returned iterator will produce elements from the inner iterators as if concatentated. This is essentially a flat-map operation on iterators. Note theinnerFactorymay return null to skip an outer element.- Type Parameters:
O- the type of elements in the outer iteratorI- the type of elements in the inner and flattened iterators- Parameters:
outer- the outer iteratorinnerFactory- a mapping from outer elements to inner iterators- Returns:
- the flattened iterator
-
hasNext
public boolean hasNext() -
next
-
remove
public void remove()
-