Class RangeUnionIterator<K extends Comparable<K>,D extends CombinedValue<K>>

Type Parameters:
K - The type used to sort ranges.
D - The container type which is going to be returned by Iterator.next().
All Implemented Interfaces:
com.google.common.collect.PeekingIterator<D>, Closeable, AutoCloseable, Iterator<D>

public class RangeUnionIterator<K extends Comparable<K>,D extends CombinedValue<K>> extends RangeIterator<K,D>
Range Union Iterator is used to return sorted stream of elements from multiple RangeIterator instances. PriorityQueue is used as a sorting mechanism for the ranges, where each computeNext() operation would poll from the queue (and push when done), which returns range that contains the smallest element, because sorting is done on the moving window of range iteration RangeIterator.getCurrent(). Once retrieved the smallest element (return candidate) is attempted to be merged with other ranges, because there could be equal elements in adjacent ranges, such ranges are poll'ed only if their RangeIterator.getCurrent() equals to the return candidate.