Class SortedIterators


  • public final class SortedIterators
    extends java.lang.Object
    Few utility methods to construct skipping iterators
    Since:
    0.6.6
    Version:
    2.0
    Author:
    Pavel Klinov
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static <T> QueuedSortedIterator<T> queued​(java.util.Iterator<T> theIterator, java.util.Comparator<T> theComparator)  
      static <T> com.google.common.collect.PeekingIterator<T> union​(java.lang.Iterable<? extends java.util.Iterator<T>> theIterators, java.util.Comparator<T> theComparator)  
      static <T> java.util.Iterator<T> union​(java.util.Iterator<T> theIterator1, java.util.Iterator<T> theIterator2, java.util.Comparator<T> theComparator)
      Returns a sorted iterator that is the union of two given iterators where both of the base iterators comply with the given comparator.
      static <T> java.util.Iterator<T> union​(java.util.Iterator<T> theIterator1, java.util.Iterator<T> theIterator2, java.util.Comparator<T> theComparator, java.util.function.BiFunction<T,​T,​T> theMergeFunc)
      Returns a sorted iterator that is the union of two given iterators where both of the base iterators comply with the given comparator and performs the given merge operation when an element exists in both base iterators.
      static <T> SortedIterators.UnionBuilder<T> unionBuilder​(java.util.Comparator<T> theComparator, int theExpectedSize)  
      static <T> java.util.Iterator<T> unionMultiThreaded​(java.util.List<? extends java.util.Iterator<T>> theIterators, java.util.Comparator<T> theComparator, java.util.concurrent.ExecutorService theExecutor)  
      static <T> com.google.common.collect.PeekingIterator<T> uniqueIterator​(com.google.common.collect.PeekingIterator<T> theIterator, java.util.Comparator<? super T> theComparator)
      Collapses equivalent elements in an iterator by picking the first element.
      static <T> com.google.common.collect.PeekingIterator<T> uniqueIterator​(com.google.common.collect.PeekingIterator<T> theIterator, java.util.Comparator<T> theComparator, java.util.function.BiFunction<T,​T,​T> theFunction)
      Collapses the equivalent elements in a sorted iterator using a binary function.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Method Detail

      • queued

        public static <T> QueuedSortedIterator<T> queued​(java.util.Iterator<T> theIterator,
                                                         java.util.Comparator<T> theComparator)
      • union

        public static <T> java.util.Iterator<T> union​(java.util.Iterator<T> theIterator1,
                                                      java.util.Iterator<T> theIterator2,
                                                      java.util.Comparator<T> theComparator)
        Returns a sorted iterator that is the union of two given iterators where both of the base iterators comply with the given comparator. The base iterators may span overlapping ranges and contain common elements. The resulting iterator will return all elements in sorted order. The duplicate elements that exist in both iterators will be returned only once.
      • union

        public static <T> java.util.Iterator<T> union​(java.util.Iterator<T> theIterator1,
                                                      java.util.Iterator<T> theIterator2,
                                                      java.util.Comparator<T> theComparator,
                                                      java.util.function.BiFunction<T,​T,​T> theMergeFunc)
        Returns a sorted iterator that is the union of two given iterators where both of the base iterators comply with the given comparator and performs the given merge operation when an element exists in both base iterators. When a duplicate is found in both iterators only the result of the merge function will be included in the resulting iterator.
      • union

        public static <T> com.google.common.collect.PeekingIterator<T> union​(java.lang.Iterable<? extends java.util.Iterator<T>> theIterators,
                                                                             java.util.Comparator<T> theComparator)
      • unionBuilder

        public static <T> SortedIterators.UnionBuilder<T> unionBuilder​(java.util.Comparator<T> theComparator,
                                                                       int theExpectedSize)
      • unionMultiThreaded

        public static <T> java.util.Iterator<T> unionMultiThreaded​(java.util.List<? extends java.util.Iterator<T>> theIterators,
                                                                   java.util.Comparator<T> theComparator,
                                                                   java.util.concurrent.ExecutorService theExecutor)
      • uniqueIterator

        public static <T> com.google.common.collect.PeekingIterator<T> uniqueIterator​(com.google.common.collect.PeekingIterator<T> theIterator,
                                                                                      java.util.Comparator<T> theComparator,
                                                                                      java.util.function.BiFunction<T,​T,​T> theFunction)
        Collapses the equivalent elements in a sorted iterator using a binary function. If there are any equivalent elements in a sorted iterator as identified by a comparator then two values will be collapsed into one value using the provided function theFunction.apply(previous, next). If there are multiple equivalent elements in the iterator then the function will be repeatedly applied to return a single iterator. If the provided iterator is not sorted then only the subsequent equivalent elements will be collapsed.
      • uniqueIterator

        public static <T> com.google.common.collect.PeekingIterator<T> uniqueIterator​(com.google.common.collect.PeekingIterator<T> theIterator,
                                                                                      java.util.Comparator<? super T> theComparator)
        Collapses equivalent elements in an iterator by picking the first element. uniqueIterator(PeekingIterator, Comparator, BiFunction)