Class CombinedIterator<E>

  • Type Parameters:
    E - the element type of the iterator
    All Implemented Interfaces:
    java.util.Iterator<E>

    public class CombinedIterator<E>
    extends java.lang.Object
    implements java.util.Iterator<E>
    An Iterator that combines the contents of various other Iterators. The provided Iterators will be followed one by one, until the last Iterator has no remaining elements.
    Author:
    Matthew Wakeling
    • Field Summary

      Fields 
      Modifier and Type Field Description
      protected java.util.Iterator<? extends E> currentIterator  
      protected java.util.Iterator<java.util.Iterator<? extends E>> iteratorIterator  
    • Constructor Summary

      Constructors 
      Constructor Description
      CombinedIterator​(java.util.List<java.util.Iterator<? extends E>> iterators)
      Constructs a CombinedIterator from a List of Iterators.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      boolean hasNext()
      E next()
      void remove()
      This operation is not supported.
      • 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 Detail

      • iteratorIterator

        protected java.util.Iterator<java.util.Iterator<? extends E>> iteratorIterator
      • currentIterator

        protected java.util.Iterator<? extends E> currentIterator
    • Constructor Detail

      • CombinedIterator

        public CombinedIterator​(java.util.List<java.util.Iterator<? extends E>> iterators)
        Constructs a CombinedIterator from a List of Iterators. The provided Iterators should be in a state where the desired elements are present. The act of iterating through this combined iterator will result in the provided Iterators being iterated.
        Parameters:
        iterators - a List of Iterators to be followed in order
    • Method Detail

      • hasNext

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

        public E next()
        Specified by:
        next in interface java.util.Iterator<E>
      • remove

        public void remove()
        This operation is not supported.
        Specified by:
        remove in interface java.util.Iterator<E>