> from: Henri Yandell <[EMAIL PROTECTED]>
> On Wed, 8 Jan 2003, Stephen Colebourne wrote:
#1)
> > public interface MapIterator extends Iterator, Map.Entry {
> > // copied from extends
> > public boolean hasNext();
> > public Map.Entry next(); // implementation returns the map iterator, as
> > that implements Map.Entry
> > public Object remove();
> > public Object getKey();
> > public Object getValue();
> > public void setValue();
> > // on this interface
> > public void reset();
> > }
#2)
> > The MapIterator interface could vary from that above. One alternative is to
> > not extend Iterator or Map.Entry:
> > public interface MapIterator {
> > public boolean hasNext();
> > public Object nextKey();
> > public Object removeKey();
> > public Object getValue();
> > public void setValue();
> > public void reset();
> > }
#3)
> public interface MapIterator extends ResetableIterator {
> public boolean hasNext();
> public Object next();
> public Object remove();
> public Object getValue();
> public void setValue();
> public void reset();
> }
>
> ie) Like calling Map.keys(), but with the additional power that you can
> still do the value-thing. Biggest problem with this one is that it's not
> as blatant that next() returns the key.
We could add getKey(). next() advances the iterator and returns the next key. getKey()
gets the current key, getValue() gets the current value.
Hen > I like the fact that someone can still use the #1 as a normal
> iterator, in which next() returns the object to be viewed. In the second
> one, the Iterator idiom seems to be trickier. Then again, the second can
> have a better performance and doesn't involve the highly painful
> Map.Entry.
#1 doesn't involve a Map.Entry creation each time, as the iterator IS the Map.Entry.
One object, where the values change each time the next() method is called.
> > Useful?
>
> I think so. Can you JSR it up, get Map.Entry deprecated and one of these
> interfaces put in place? :)
LOL. Actually, I still think Map.Entry has its place, it just shouldn't be the main
access point to a Map. Hopefully my implementation will work well too;-)
Stephen
--
To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>