Backport COLLECTIONS-261 to 3.2.2 git-svn-id: https://svn.apache.org/repos/asf/commons/proper/collections/branches/COLLECTIONS_3_2_X@1713293 13f79535-47bb-0310-9956-ffa450edef68
Project: http://git-wip-us.apache.org/repos/asf/commons-collections/repo Commit: http://git-wip-us.apache.org/repos/asf/commons-collections/commit/6a7d35de Tree: http://git-wip-us.apache.org/repos/asf/commons-collections/tree/6a7d35de Diff: http://git-wip-us.apache.org/repos/asf/commons-collections/diff/6a7d35de Branch: refs/heads/COLLECTIONS_3_2_X Commit: 6a7d35dea2a34069335126aa7e9d54b44c91c8b0 Parents: 46e5a83 Author: Thomas Neidhart <t...@apache.org> Authored: Sun Nov 8 21:04:34 2015 +0000 Committer: Thomas Neidhart <t...@apache.org> Committed: Sun Nov 8 21:04:34 2015 +0000 ---------------------------------------------------------------------- src/changes/changes.xml | 8 ++++---- .../org/apache/commons/collections/map/Flat3Map.java | 12 ++++++------ .../apache/commons/collections/map/TestFlat3Map.java | 15 +++++++++++++++ 3 files changed, 25 insertions(+), 10 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/commons-collections/blob/6a7d35de/src/changes/changes.xml ---------------------------------------------------------------------- diff --git a/src/changes/changes.xml b/src/changes/changes.xml index bccc7e1..9d3a1b7 100644 --- a/src/changes/changes.xml +++ b/src/changes/changes.xml @@ -42,6 +42,10 @@ <action issue="COLLECTIONS-266" dev="bayard" type="fix" due-to="Joerg Schaible"> "MultiKey" will now be correctly serialized/de-serialized. </action> + <action issue="COLLECTIONS-261" dev="bayard" type="fix" due-to="ori"> + "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-249" dev="bayard" type="fix" due-to="Joe Kelly"> "SetUniqueList.addAll(int, Collection)" now correctly add the collection at the provided index. @@ -85,10 +89,6 @@ <action issue="COLLECTIONS-304" dev="bayard" type="fix" due-to="RafaÅ Figas,Bjorn Townsend"> "SetUniqueList#set(int, Object)" will now correctly enforce the uniqueness constraint. </action> - <action issue="COLLECTIONS-261" dev="bayard" type="fix" due-to="ori"> - "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> --> </release> </body> http://git-wip-us.apache.org/repos/asf/commons-collections/blob/6a7d35de/src/java/org/apache/commons/collections/map/Flat3Map.java ---------------------------------------------------------------------- diff --git a/src/java/org/apache/commons/collections/map/Flat3Map.java b/src/java/org/apache/commons/collections/map/Flat3Map.java index 19085f1..b4349ec 100644 --- a/src/java/org/apache/commons/collections/map/Flat3Map.java +++ b/src/java/org/apache/commons/collections/map/Flat3Map.java @@ -416,7 +416,7 @@ public class Flat3Map implements IterableMap, Serializable, Cloneable { return old; } if (key2 == null) { - Object old = value3; + Object old = value2; hash2 = hash3; key2 = key3; value2 = value3; @@ -427,7 +427,7 @@ public class Flat3Map implements IterableMap, Serializable, Cloneable { return old; } if (key1 == null) { - Object old = value3; + Object old = value1; hash1 = hash3; key1 = key3; value1 = value3; @@ -448,7 +448,7 @@ public class Flat3Map implements IterableMap, Serializable, Cloneable { return old; } if (key1 == null) { - Object old = value2; + Object old = value1; hash1 = hash2; key1 = key2; value1 = value2; @@ -483,7 +483,7 @@ public class Flat3Map implements IterableMap, Serializable, Cloneable { return old; } if (hash2 == hashCode && key.equals(key2)) { - Object old = value3; + Object old = value2; hash2 = hash3; key2 = key3; value2 = value3; @@ -494,7 +494,7 @@ public class Flat3Map implements IterableMap, Serializable, Cloneable { return old; } if (hash1 == hashCode && key.equals(key1)) { - Object old = value3; + Object old = value1; hash1 = hash3; key1 = key3; value1 = value3; @@ -515,7 +515,7 @@ public class Flat3Map implements IterableMap, Serializable, Cloneable { return old; } if (hash1 == hashCode && key.equals(key1)) { - Object old = value2; + Object old = value1; hash1 = hash2; key1 = key2; value1 = value2; http://git-wip-us.apache.org/repos/asf/commons-collections/blob/6a7d35de/src/test/org/apache/commons/collections/map/TestFlat3Map.java ---------------------------------------------------------------------- diff --git a/src/test/org/apache/commons/collections/map/TestFlat3Map.java b/src/test/org/apache/commons/collections/map/TestFlat3Map.java index 427b7ae..b48a867 100644 --- a/src/test/org/apache/commons/collections/map/TestFlat3Map.java +++ b/src/test/org/apache/commons/collections/map/TestFlat3Map.java @@ -205,6 +205,21 @@ public class TestFlat3Map extends AbstractTestIterableMap { assertSame(TWO, cloned.get(TWENTY)); } + public void testCollections261() { + final Flat3Map m = new Flat3Map(); + m.put( Integer.valueOf(1), Integer.valueOf(1) ); + m.put( Integer.valueOf(0), Integer.valueOf(0) ); + assertEquals( Integer.valueOf(1), m.remove( Integer.valueOf(1) ) ); + assertEquals( Integer.valueOf(0), m.remove( Integer.valueOf(0) ) ); + + m.put( Integer.valueOf(2), Integer.valueOf(2) ); + m.put( Integer.valueOf(1), Integer.valueOf(1) ); + m.put( Integer.valueOf(0), Integer.valueOf(0) ); + assertEquals( Integer.valueOf(2), m.remove( Integer.valueOf(2) ) ); + assertEquals( Integer.valueOf(1), m.remove( Integer.valueOf(1) ) ); + assertEquals( Integer.valueOf(0), m.remove( Integer.valueOf(0) ) ); + } + public void testSerialisation0() throws Exception { Flat3Map map = new Flat3Map(); ByteArrayOutputStream bout = new ByteArrayOutputStream();