DaveAKing / guava-libraries

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

Create a helper function Enumerations.asIterable() #1399

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
Please create a helper function to turn an java.util.Enumeration into a 
java.util.Iterable so I can write:

    Enumeration<Type> foo = ...
    for( Type e : Enumerations.asIterable(foo) ) { ... }

Original issue reported on code.google.com by adigu...@gmail.com on 3 May 2013 at 7:48

GoogleCodeExporter commented 9 years ago
What about:
for (TimeUnit unit : EnumSet.allOf(TimeUnit.class)) { ... }

Original comment by k...@kloover.com on 3 May 2013 at 8:06

GoogleCodeExporter commented 9 years ago
Or even:
for (TimeUnit unit : TimeUnit.values()) { ... }

Original comment by k...@kloover.com on 3 May 2013 at 8:08

GoogleCodeExporter commented 9 years ago
Enumeration<Type> foo = ...
Iterators.forEnumeration(foo)

and then use Iterables or FluentIterable to do your stuff.

Original comment by amer...@gmail.com on 3 May 2013 at 8:23

GoogleCodeExporter commented 9 years ago
to comment #1 and #2:

java.util.Enumeration != java.lang.Enum

Original comment by SeanPFl...@googlemail.com on 3 May 2013 at 9:50

GoogleCodeExporter commented 9 years ago
The issue with this is that Enumeration is single-use, like Iterator. So while 
you can create an Iterator from an Enumeration, you can't create a proper 
Iterable from one any more than you can from an Iterator.

Original comment by cgdec...@gmail.com on 3 May 2013 at 12:12

GoogleCodeExporter commented 9 years ago
Indeed, the Iterator as Iterable view is listed in the idea graveyard, and this 
would seem to fall into the same category.

Original comment by wasserman.louis on 3 May 2013 at 3:53

GoogleCodeExporter commented 9 years ago

Original comment by cgdec...@gmail.com on 3 May 2013 at 5:52

GoogleCodeExporter commented 9 years ago
This issue has been migrated to GitHub.

It can be found at https://github.com/google/guava/issues/<issue id>

Original comment by cgdecker@google.com on 1 Nov 2014 at 4:12

GoogleCodeExporter commented 9 years ago

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