RFR(s): 8072726: add adapter to convert Enumeration to Iterator
Paul Sandoz
paul.sandoz at oracle.com
Mon May 18 10:20:39 UTC 2015
Hi Stuart,
I would like to suggest some tweaks to the specification to get across this method is transitioning control of traversal from enumeration to iterator. How about:
Returns an iterator that traverses the remaining elements covered by this enumeration.
Traversal is undefined if this enumeration is operated on after the call to {@code asIterator}.
I suspect the use of PermissionCollection in the apiNote is a little too obscure and highlighting an area that i don't think deserves so much attention :-)
In your example i am not sure the source is IMMUTABLE, it's possible to add permissions if the collection is not marked read-only. It's not even clear whether ORDERED is relevant here, some implementations are backed by a HashMap (see BasicPermissionCollection) and the enumeration is derived from the map's values. Hence I am ambivalent about exposing such a Stream example, it exposes too many details that are tricky to get right.
ClassLoader.getResources would be better if it were not for IOException.
I would be inclined to go for Zip/JarFile.entries, and that would also give us the opportunity to highlight the stream returning method that could be used instead, therefore we can avoid mentioning about constructing a stream from an enumeration/iterator and move developers away from Enumeration altogether in this case.
A good stream-ification task would be to identify cases in the JDK where only an Enumeration is returned and additionally provide stream-returning methods, so perhaps PermissionCollection and ClassLoader are good candidates.
Paul.
On May 16, 2015, at 2:37 AM, Stuart Marks <stuart.marks at oracle.com> wrote:
> Hi all,
>
> Please review this small API enhancement to add a default method "asIterator()" to Enumeration that converts it into an Iterator.
>
> Webrev:
>
> http://cr.openjdk.java.net/~smarks/reviews/8072726/webrev.0/
>
> Bug:
>
> https://bugs.openjdk.java.net/browse/JDK-8072726
>
> Thanks,
>
> s'marks
More information about the core-libs-dev
mailing list