Package com.complexible.common.collect

# Class SortedIterators

java.lang.Object
com.complexible.common.collect.SortedIterators

public final class SortedIterators extends Object
Few utility methods to construct skipping iterators

Since:
  0.6.6
Version:
  2.0
Author:
  Pavel Klinov

- ## Nested Class Summary

  Nested Classes
  Modifier and Type
  Class
  Description
  `static class`
  `SortedIterators.UnionBuilder<T>`

- ## Method Summary

  Modifier and Type
  Method
  Description
  `static <T> QueuedSortedIterator<T>`
  `queued(Iterator<T> theIterator, Comparator<T> theComparator)`
  `static <T> com.google.common.collect.PeekingIterator<T>`
  `union(Iterable<? extends Iterator<T>> theIterators, Comparator<T> theComparator)`
  `static <T> Iterator<T>`
  `union(Iterator<T> theIterator1, Iterator<T> theIterator2, 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> Iterator<T>`
  `union(Iterator<T> theIterator1, Iterator<T> theIterator2, Comparator<T> theComparator, 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(Comparator<T> theComparator, int theExpectedSize)`
  `static <T> Iterator<T>`
  `unionMultiThreaded(List<? extends Iterator<T>> theIterators, Comparator<T> theComparator, ExecutorService theExecutor)`
  `static <T> com.google.common.collect.PeekingIterator<T>`
  `uniqueIterator(com.google.common.collect.PeekingIterator<T> theIterator, 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, Comparator<T> theComparator, 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 Details

  - ### queued

    public static <T> QueuedSortedIterator<T> queued(Iterator<T> theIterator, Comparator<T> theComparator)

  - ### union

    public static <T> Iterator<T> union(Iterator<T> theIterator1, Iterator<T> theIterator2, 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> Iterator<T> union(Iterator<T> theIterator1, Iterator<T> theIterator2, Comparator<T> theComparator, 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(Iterable<? extends Iterator<T>> theIterators, Comparator<T> theComparator)

  - ### unionBuilder

    public static <T> SortedIterators.UnionBuilder<T> unionBuilder(Comparator<T> theComparator, int theExpectedSize)

  - ### unionMultiThreaded

    public static <T> Iterator<T> unionMultiThreaded(List<? extends Iterator<T>> theIterators, Comparator<T> theComparator, ExecutorService theExecutor)

  - ### uniqueIterator

    public static <T> com.google.common.collect.PeekingIterator<T> uniqueIterator(com.google.common.collect.PeekingIterator<T> theIterator, Comparator<T> theComparator, 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, Comparator<? super T> theComparator)
    Collapses equivalent elements in an iterator by picking the first element. `uniqueIterator(PeekingIterator, Comparator, BiFunction)`