Class MergedIterator<T extends java.lang.Comparable<T>>

  • All Implemented Interfaces:
    java.util.Iterator<T>

    public final class MergedIterator<T extends java.lang.Comparable<T>>
    extends java.lang.Object
    implements java.util.Iterator<T>
    Provides a merged sorted view from several sorted iterators.

    If built with removeDuplicates set to true and an element appears in multiple iterators then it is deduplicated, that is this iterator returns the sorted union of elements.

    If built with removeDuplicates set to false then all elements in all iterators are returned.

    Caveats:

    • The behavior is undefined if the iterators are not actually sorted.
    • Null elements are unsupported.
    • If removeDuplicates is set to true and if a single iterator contains duplicates then they will not be deduplicated.
    • When elements are deduplicated it is not defined which one is returned.
    • If removeDuplicates is set to false then the order in which duplicates are returned isn't defined.
    • Constructor Summary

      Constructors 
      Constructor Description
      MergedIterator​(boolean removeDuplicates, java.util.Iterator<T>... iterators)  
      MergedIterator​(java.util.Iterator<T>... iterators)  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      boolean hasNext()  
      T next()  
      void remove()  
      • Methods inherited from class java.lang.Object

        equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
      • Methods inherited from interface java.util.Iterator

        forEachRemaining
    • Constructor Detail

      • MergedIterator

        public MergedIterator​(java.util.Iterator<T>... iterators)
      • MergedIterator

        public MergedIterator​(boolean removeDuplicates,
                              java.util.Iterator<T>... iterators)
    • Method Detail

      • hasNext

        public boolean hasNext()
        Specified by:
        hasNext in interface java.util.Iterator<T extends java.lang.Comparable<T>>
      • next

        public T next()
        Specified by:
        next in interface java.util.Iterator<T extends java.lang.Comparable<T>>
      • remove

        public void remove()
        Specified by:
        remove in interface java.util.Iterator<T extends java.lang.Comparable<T>>