I would like to propose the addition of two new interfaces to [collections]. These are prompted by a list comment a while back that Sun defined maps "as a list of pairs rather than a pair of lists".
(not terribly relevant but...) http://www.mail-archive.com/[email protected]/msg13059.html So... public interface IterableMap extends Map { public MapIterator mapIterator(); } 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(); } Thus: for (MapIterator it = map.mapIterator(); it.hasNext(); ) { it.next(); doSomething(it.getKey(), it.getValue()); } This will allow new Map implementations that are 'a pair of lists'. I have one in mind. For some implementations this will be much more efficient than using entrySet().iterator(). And an adaptor can easily be built to JDK maps. 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(); } I think that the first proposal is more generally useful however. Useful? Stephen -- To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]> For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>
