yangxu998 / guava-libraries

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

AbstractIterator should implement PeekingIterator directly #596

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
As part of the Supplier-as-Iterator suggestion I posted in issue 584, I had to 
create an shim subclass of AbstractIterator in order to get the PeekingIterator 
interface implemented.

It occurred to me that AbstractIterator works just fine as a PeekingIterator 
regardless of concrete implementation. IMHO AbstractIterator should simply 
implement PeekingIterator directly, rather than requiring a subclass to do so 
explicitly (as the comment on AbstractIterator.peek() suggests).

Original issue reported on code.google.com by tv@duh.org on 6 Apr 2011 at 1:40

GoogleCodeExporter commented 9 years ago
That would increase the memory overhead of all implementations, whether they 
need peeking or not.

Original comment by jim.andreou on 6 Apr 2011 at 2:23

GoogleCodeExporter commented 9 years ago
"Jim" :-) slight misunderstanding here.  AbstractIterator *does* have the 
peek() functionality already, it simply doesn't declare that it implements 
PeekingIterator.

I voted strongly in favor of having AbstractIterator classes choose explicitly 
when they wish to export the PeekingIterator interface.  The need to expose 
peek() should be very, very rare, but if all AbstractIterators expose it 
automatically we've elevated its perceived importance/popularity a lot for no 
good reason.  This is just a judgment call.  We made it, and right now this 
issue isn't bringing any new information to light, so I'm inclined to stick 
with it.

Original comment by kevinb@google.com on 6 Apr 2011 at 2:37

GoogleCodeExporter commented 9 years ago
Ah, that will teach me not to respond from the phone when the source code is 
too many taps away to bother double-checking! I guess my comment is about a 
parallel universe and can be safely ignored then.

Hmm, right, let me pick a new name for 2011, this is getting old :p

Original comment by jim.andreou on 6 Apr 2011 at 4:16

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