return new IteratorBasedIterator(iterators);
}
private IteratorBasedIterator(Collection<DocIdSetIterator> iterators) throws IOException {
final DocIdSetIterator[] sortedIterators = iterators.toArray(new DocIdSetIterator[iterators.size()]);
new InPlaceMergeSorter() {
@Override
protected int compare(int i, int j) {
return Long.compare(sortedIterators[i].cost(), sortedIterators[j].cost());
}