harmony-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Paulex Yang <paulex.y...@gmail.com>
Subject Re: [classlib][luni] A problem about behavior of EnumMap
Date Tue, 29 Aug 2006 08:15:55 GMT
Spark Shen wrote:
> Hi All:
> When I develop EnumMap,I find EnumMap strange on RI. As the following 
> code describes, the method entrySet() of EnumMap returns a set view of 
> mappings contained in this map. Then we get the set's iterator and use 
> the iterator's next() method to get an Entry which contains one 
> mapping. But if we use next() method again to get another Entry, the 
> previous Entry will also point to the next Entry.
>
> import java.util.EnumMap;
> import java.util.Iterator;
> import java.util.Map;
> import java.util.Set;
>
> import junit.framework.TestCase;
>
> public class EnumMapTest extends TestCase{
>    enum Size {
>        Small, Middle, Big {
>        };
>    }
>    public void test_entrySet() {
>        EnumMap enumSizeMap = new EnumMap(Size.class);
>        enumSizeMap.put(Size.Middle, 1);
>        enumSizeMap.put(Size.Big, null);
>
>        Set set = enumSizeMap.entrySet();
>        Iterator iter = set.iterator();
>        Map.Entry entry = (Map.Entry) iter.next();
>        assertEquals(Size.Middle, entry.getKey());
>        Map.Entry entry1 = (Map.Entry) iter.next();
>        assertEquals(Size.Big, entry.getKey());
>        assertSame(entry,entry1);
>    }
> }
> I guess on RI, the returned iterator maintains a reference to current 
> entry and returns this reference in iter.next() method.
> I do not think RI's  behavior makes sense here. So I suggest not to 
> follow RI on the behavior.
+1 from me.
>
>
> Best regards
>


-- 
Paulex Yang
China Software Development Lab
IBM



---------------------------------------------------------------------
Terms of use : http://incubator.apache.org/harmony/mailing.html
To unsubscribe, e-mail: harmony-dev-unsubscribe@incubator.apache.org
For additional commands, e-mail: harmony-dev-help@incubator.apache.org


Mime
View raw message