/guava/guava/src/com/google/common/collect/Iterators.java
Comparator<PeekingIterator<T>> heapComparator =( PeekingIterator<T> o2, PeekingIterator<T> o1) -> itemComparator.compare( o1.peek( ) , o2.peek( ) ) ;
Comparator<PeekingIterator<T>> heapComparator = ( PeekingIterator<T> o1, PeekingIterator<T> o2 ) -> itemComparator.compare ( o1.peek ( ) , o2.peek ( ) ) ;
return new MergingIterator<>(iterators, comparator); } private static class MergingIterator<T extends @Nullable Object> extends UnmodifiableIterator<T> { final Queue<PeekingIterator<T>> queue; public MergingIterator( Iterable<? extends Iterator<? extends T>> iterators, Comparator<? super T> itemComparator) { <extra_id_0> queue = new PriorityQueue<>(2, heapComparator); for (Iterator<? extends T> iterator : iterators) { if (iterator.hasNext()) { queue.add(Iterators.peekingIterator(iterator)); } }