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 iterator
  `I` - the type of elements in the inner and flattened iterators

All Implemented Interfaces:
  `Iterator<I>`

Direct Known Subclasses:
  `AddressIteratorAdapter`

public class FlattenedIterator<O,I> extends Object implements Iterator<I>
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 Summary

  Fields
  Modifier and Type
  Field
  Description
  `protected Iterator<? extends I>`
  `inner`
  `protected final Function<O,Iterator<? extends I>>`
  `innerFactory`
  `protected final Iterator<O>`
  `outer`
  `protected Iterator<? extends I>`
  `preppedInner`

- ## Constructor Summary

  Constructors
  Modifier
  Constructor
  Description
  `protected`
  `FlattenedIterator(Iterator<O> outer, Function<O,Iterator<? extends I>> innerFactory)`

- ## Method Summary

  Modifier and Type
  Method
  Description
  `boolean`
  `hasNext()`
  `I`
  `next()`
  `void`
  `remove()`
  `static <O, I> Iterator<I>`
  `start(Iterator<O> outer, Function<O,Iterator<? extends I>> innerFactory)`
  Create a flattened iterator

  ### Methods inherited from class java.lang.Object

  `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

  ### Methods inherited from interface java.util.Iterator

  `forEachRemaining`

- ## Field Details

  - ### outer

    protected final Iterator<O> outer

  - ### innerFactory

    protected final Function<O,Iterator<? extends I>> innerFactory

  - ### inner

    protected Iterator<? extends I> inner

  - ### preppedInner

    protected Iterator<? extends I> preppedInner

- ## Constructor Details

  - ### FlattenedIterator

    protected FlattenedIterator(Iterator<O> outer, Function<O,Iterator<? extends I>> innerFactory)

- ## Method Details

  - ### start

    public static <O, I> Iterator<I> start(Iterator<O> outer, Function<O,Iterator<? extends I>> innerFactory)
    Create a flattened iterator

    This iterates over each element of `outer` and applies the given `innerFactory` to 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 the `innerFactory` may return null to skip an outer element.

    Type Parameters:
      `O` - the type of elements in the outer iterator
      `I` - the type of elements in the inner and flattened iterators
    Parameters:
      `outer` - the outer iterator
      `innerFactory` - a mapping from outer elements to inner iterators
    Returns:
      the flattened iterator

  - ### hasNext

    public boolean hasNext()
    Specified by:
      `hasNext` in interface `Iterator<O>`

  - ### next

    public I next()
    Specified by:
      `next` in interface `Iterator<O>`

  - ### remove

    public void remove()
    Specified by:
      `remove` in interface `Iterator<O>`