maidh91 / guava-libraries

Automatically exported from code.google.com/p/guava-libraries
Apache License 2.0
0 stars 0 forks source link

Iterables.consumingIterable(Iterable): special case or overload for PriorityQueue #432

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
It would be nice if one could use consumingIterable to read and remove all 
elements from a PriorityQueue in the queue's order.

Officially (according to the PriorityQueue spec) the iterator's ordering is 
arbitrary and removing every element is not a special case; However in the 
three JREs I tried it on it does in fact return the elements in order.

Rather than rely on this undocumented behaviour it would be safer to wrap the 
queue in a new Iterator.

Because the returned Iterator would not be equivalent to 
Iterators.consumingIterator(Iterator) (contrary to the current documentation of 
consumingIterable) an overload might be preferable to a run-time type check

Original issue reported on code.google.com by fin...@gmail.com on 27 Sep 2010 at 2:05

GoogleCodeExporter commented 9 years ago
Interesting point.  I think in this case I would simply rely on the observed 
behavior, and add a unit test to alert me if it ever changes.  We might want to 
mention the case of PQs in the consumingItera* docs, though, since I actually 
always saw them as a primary use case for the method (didn't even realize this 
behavior was not promised).

Original comment by kevinb@google.com on 28 Sep 2010 at 1:40

GoogleCodeExporter commented 9 years ago

Original comment by boppenh...@google.com on 15 Oct 2010 at 9:44

GoogleCodeExporter commented 9 years ago
Fixed in r143.

Original comment by boppenh...@google.com on 7 Dec 2010 at 3:23

GoogleCodeExporter commented 9 years ago

Original comment by kevinb@google.com on 18 Jan 2011 at 8:38

GoogleCodeExporter commented 9 years ago

Original comment by kevinb@google.com on 24 Jan 2011 at 9:33

GoogleCodeExporter commented 9 years ago
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:15

GoogleCodeExporter commented 9 years ago

Original comment by cgdecker@google.com on 3 Nov 2014 at 9:09