Closed GoogleCodeExporter closed 9 years ago
Ok, I've looked up these Apache things. I think you're asking for this:
BEFORE:
for (Map.Entry<String, Integer> entry : map.entrySet()) {
doSomethingWith(entry.getKey(), entry.getValue());
}
AFTER:
MapIterator<String, Integer> it = Maps.iterate(map);
while (it.hasNext()) {
doSomethingWith(it.getKey(), it.getValue());
}
Have I got that right?
Original comment by kevin...@gmail.com
on 8 Jul 2008 at 3:49
Plus I think you want an IterableMap interface that extends Map with an
iterator()
method, so "Maps.iterate(map)" in the example above would become
"map.iterator()".
How much of the motivation for this is supposed performance gains?
Original comment by kevin...@gmail.com
on 8 Jul 2008 at 4:08
It's not clear what benefit MapIterator provides over iterating across the
entrySet()
directly. Besides, with Java 5+, it's better to use the improved for loops
instead of
iterators most of the time.
Now, if you prefer to use a MapIterator, it would be straightforward to write a
method that creates a MapIterator for an arbitrary Map. Such a method would
belong in
the Apache Commons Collections library, not of Google Collections.
Original comment by jared.l....@gmail.com
on 12 Jul 2008 at 1:32
Original issue reported on code.google.com by
alan.kt....@gmail.com
on 8 Jul 2008 at 3:07