Class FlatIterator<X,​Y>

java.lang.Object
de.zabuza.fastcdc4j.internal.util.FlatIterator<X,​Y>
Type Parameters:
X - The type contained in the outer iterator, either already an iterator or used to produce iterators using a given function
Y - The type contained in the inner iterators, also the final type contained in this iterator
All Implemented Interfaces:
java.util.Iterator<Y>

public final class FlatIterator<X,​Y>
extends java.lang.Object
implements java.util.Iterator<Y>
Iterator that flattens an iterator over other iterators. The given iterator is consumed on-the-fly.

Use new FlatIterator(outer, Function::identity) if FlatIterator is already the inner iterator.

Author:
Daniel Tischner <zabuza.dev@gmail.com>
  • Constructor Summary

    Constructors 
    Constructor Description
    FlatIterator​(java.util.Iterator<? extends X> outerIterator, java.util.function.Function<? super X,​? extends java.util.Iterator<Y>> provider)
    Creates a new flat iterator that flattens the given iterator on-the-fly.
  • Method Summary

    Modifier and Type Method Description
    boolean hasNext()  
    Y next()  

    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, remove
  • Constructor Details

    • FlatIterator

      public FlatIterator​(java.util.Iterator<? extends X> outerIterator, java.util.function.Function<? super X,​? extends java.util.Iterator<Y>> provider)
      Creates a new flat iterator that flattens the given iterator on-the-fly.
      Parameters:
      outerIterator - The source iterator used to generate inner iterators from, not null
      provider - Function that provides the final inner iterators based on the outer iterators data, not null
  • Method Details

    • hasNext

      public boolean hasNext()
      Specified by:
      hasNext in interface java.util.Iterator<X>
    • next

      public Y next()
      Specified by:
      next in interface java.util.Iterator<X>