Backport COLLECTIONS-217 to 3.2.2

git-svn-id: https://svn.apache.org/repos/asf/commons/proper/collections/branches/COLLECTIONS_3_2_X@1713290 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Thomas Neidhart 2015-11-08 20:21:27 +00:00
parent c0da312f34
commit 46e5a83207
3 changed files with 68 additions and 4 deletions

View File

@ -53,6 +53,10 @@
<action issue="COLLECTIONS-219" dev="scolebourne" type="fix" due-to="Tom Leccese">
"CollectionUtils#removeAll" wrongly called "ListUtils#retainAll".
</action>
<action issue="COLLECTIONS-217" dev="scolebourne" type="fix" due-to="Matt Bishop">
Calling "setValue(Object)" on any Entry returned by a "Flat3Map" will now
correctly set the value for the current entry.
</action>
<!-- Bugfixes planned to backport from 4.0
@ -85,10 +89,6 @@
"Flat3Map#remove(Object)" will now return the correct value mapped to the removed key
if the size of the map is less or equal 3.
</action>
<action issue="COLLECTIONS-217" dev="scolebourne" type="fix" due-to="Matt Bishop">
Calling "setValue(Object)" on any Entry returned by a "Flat3Map" will now
correctly set the value for the current entry.
</action>
-->
</release>
</body>

View File

@ -804,10 +804,13 @@ public class Flat3Map implements IterableMap, Serializable, Cloneable {
switch (nextIndex) {
case 3:
parent.value3 = value;
break;
case 2:
parent.value2 = value;
break;
case 1:
parent.value1 = value;
break;
}
return old;
}

View File

@ -20,6 +20,7 @@ import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.util.Iterator;
import java.util.Map;
import junit.framework.Test;
@ -40,8 +41,10 @@ public class TestFlat3Map extends AbstractTestIterableMap {
private static final Integer ONE = new Integer(1);
private static final Integer TWO = new Integer(2);
private static final Integer THREE = new Integer(3);
private static final String TEN = "10";
private static final String TWENTY = "20";
private static final String THIRTY = "30";
public TestFlat3Map(String testName) {
super(testName);
@ -59,6 +62,64 @@ public class TestFlat3Map extends AbstractTestIterableMap {
return new Flat3Map();
}
//-----------------------------------------------------------------------
public void testEntryIteratorSetValue1() throws Exception {
final Flat3Map map = new Flat3Map();
map.put(ONE, TEN);
map.put(TWO, TWENTY);
map.put(THREE, THIRTY);
final Iterator it = map.entrySet().iterator();
final Map.Entry entry = (Map.Entry) it.next();
entry.setValue("NewValue");
assertEquals(3, map.size());
assertEquals(true, map.containsKey(ONE));
assertEquals(true, map.containsKey(TWO));
assertEquals(true, map.containsKey(THREE));
assertEquals("NewValue", map.get(ONE));
assertEquals(TWENTY, map.get(TWO));
assertEquals(THIRTY, map.get(THREE));
}
public void testEntryIteratorSetValue2() throws Exception {
final Flat3Map map = new Flat3Map();
map.put(ONE, TEN);
map.put(TWO, TWENTY);
map.put(THREE, THIRTY);
final Iterator it = map.entrySet().iterator();
it.next();
final Map.Entry entry = (Map.Entry) it.next();
entry.setValue("NewValue");
assertEquals(3, map.size());
assertEquals(true, map.containsKey(ONE));
assertEquals(true, map.containsKey(TWO));
assertEquals(true, map.containsKey(THREE));
assertEquals(TEN, map.get(ONE));
assertEquals("NewValue", map.get(TWO));
assertEquals(THIRTY, map.get(THREE));
}
public void testEntryIteratorSetValue3() throws Exception {
final Flat3Map map = new Flat3Map();
map.put(ONE, TEN);
map.put(TWO, TWENTY);
map.put(THREE, THIRTY);
final Iterator it = map.entrySet().iterator();
it.next();
it.next();
final Map.Entry entry = (Map.Entry) it.next();
entry.setValue("NewValue");
assertEquals(3, map.size());
assertEquals(true, map.containsKey(ONE));
assertEquals(true, map.containsKey(TWO));
assertEquals(true, map.containsKey(THREE));
assertEquals(TEN, map.get(ONE));
assertEquals(TWENTY, map.get(TWO));
assertEquals("NewValue", map.get(THREE));
}
//-----------------------------------------------------------------------
public void testEquals1() {
Flat3Map map1 = new Flat3Map();