Spark Shen wrote:
Spark Shen 写道:
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.
I want to adopt the behavior described below because it seems more
reasonable.
The previous Entry should not point to the next Entry when the
iterator's next() is invoked. And then the methods of the Class Entry,
such as getKey(), getValue() ,setValue() etc,
will act on the different objects.
Based on my implement,I expect the following test cases pass on
Harmony.(Some of them will fail on RI.)
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 entry1 = (Map.Entry) iter.next();
Map.Entry entry2 = (Map.Entry) iter.next();
assertEquals(Size.Middle, entry1.getKey());
assertEquals(1, entry1.getValue());
enumSizeMap.remove(Size.Middle);
try {
entry1.setValue(0);
fail("Should throw IllegalStateException"); //$NON-NLS-1$
} catch (IllegalStateException e) {
// Expected
}
assertEquals(1, set.size());
entry2.setValue(2);
assertEquals(Size.Big, entry2.getKey());
assertEquals(2, entry2.getValue());
}
Sounds reasonable, what's RI's behavior on the entries
getKey()/getValue()/setValue() then (i.e., which asserts fails on RI)?
Best regards
--
Paulex Yang
China Software Development Lab
IBM
---------------------------------------------------------------------
Terms of use : http://incubator.apache.org/harmony/mailing.html
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]