Closed GoogleCodeExporter closed 9 years ago
Or simpler :
public E next() {
if (!hasNext()) {
throw new NoSuchElementException();
}
E smallest = null;
int pos = 0;
int i = 0;
for (final PeekingIterator<E> pi : iterators) {
if (pi.hasNext()) {
final E elt = pi.peek();
if (smallest == null || smallest.compareTo(elt) > 0) {
smallest = elt;
pos = i;
}
}
i++;
}
// next
iterators.get(pos).next();
return smallest;
}
Original comment by thierry...@gmail.com
on 15 Apr 2014 at 12:08
Are you aware of the existing method Iterators.concat(Iterator ...)?:
http://docs.guava-libraries.googlecode.com/git/javadoc/com/google/common/collect
/Iterators.html#concat%28java.util.Iterator...%29
Original comment by SeanPFl...@googlemail.com
on 15 Apr 2014 at 1:30
Well I was not aware of the method "concat". It looks great.
But I would say that it does not provide exactly the same thing. With concat,
you can not specify the order for example. And it works with copies.
Original comment by thierry...@gmail.com
on 15 Apr 2014 at 2:00
Is it really the case that this is a common enough need to be preferable to
just writing specific iterators for each case? For the particular example, we
already have Iterators.mergeSorted.
Original comment by lowas...@google.com
on 5 May 2014 at 8:13
This issue has been migrated to GitHub.
It can be found at https://github.com/google/guava/issues/<id>
Original comment by cgdecker@google.com
on 1 Nov 2014 at 4:09
Original comment by cgdecker@google.com
on 1 Nov 2014 at 4:17
Original comment by cgdecker@google.com
on 3 Nov 2014 at 9:07
Original issue reported on code.google.com by
thierry...@gmail.com
on 15 Apr 2014 at 11:29Attachments: