You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by ch...@apache.org on 2017/07/11 17:55:47 UTC

[17/50] commons-collections git commit: Backport COLLECTIONS-444 to 3.2.2.

Backport COLLECTIONS-444 to 3.2.2.

git-svn-id: https://svn.apache.org/repos/asf/commons/proper/collections/branches/COLLECTIONS_3_2_X@1713299 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/be671392
Tree: http://git-wip-us.apache.org/repos/asf/commons-collections/tree/be671392
Diff: http://git-wip-us.apache.org/repos/asf/commons-collections/diff/be671392

Branch: refs/heads/COLLECTIONS_3_2_X
Commit: be67139289c7167ed393537543b29041f88ca086
Parents: 7f947f9
Author: Thomas Neidhart <tn...@apache.org>
Authored: Sun Nov 8 21:35:53 2015 +0000
Committer: Thomas Neidhart <tn...@apache.org>
Committed: Sun Nov 8 21:35:53 2015 +0000

----------------------------------------------------------------------
 src/changes/changes.xml                            |  8 ++++----
 .../commons/collections/list/SetUniqueList.java    | 10 +++++-----
 .../collections/list/TestSetUniqueList.java        | 17 ++++++++++++++++-
 3 files changed, 25 insertions(+), 10 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/commons-collections/blob/be671392/src/changes/changes.xml
----------------------------------------------------------------------
diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index 1445d73..88e5724 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -29,6 +29,10 @@
       permission to read system properties, the "File#separator" field will
       be used instead.
     </action>
+    <action issue="COLLECTIONS-444" dev="tn" type="fix" due-to="Thomas Vahrst, John Vasileff">
+      SetUniqueList.set(int, Object) now works correctly if the object to be inserted
+      is already placed at the given position.
+    </action>
     <action issue="COLLECTIONS-350" dev="bayard" type="fix" due-to="Michael Akerman">
       Removed debug output in "MapUtils#getNumber(Map)".
     </action>
@@ -78,10 +82,6 @@
       Tree traversal with a TreeListIterator will not be affected anymore by
       the removal of an element directly after a call to previous().
     </action>
-    <action issue="COLLECTIONS-444" dev="tn" type="fix" due-to="Thomas Vahrst, John Vasileff">
-      SetUniqueList.set(int, E) now works correctly if the object to be inserted
-      is already placed at the given position.
-    </action>
     <action issue="COLLECTIONS-359" dev="bayard" type="fix" due-to="Mark Shead">
       "ListUtils#intersection(List, List)" will now also work correctly if there
       are duplicate elements in the provided lists.

http://git-wip-us.apache.org/repos/asf/commons-collections/blob/be671392/src/java/org/apache/commons/collections/list/SetUniqueList.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/commons/collections/list/SetUniqueList.java b/src/java/org/apache/commons/collections/list/SetUniqueList.java
index 13a870e..27ad6ee 100644
--- a/src/java/org/apache/commons/collections/list/SetUniqueList.java
+++ b/src/java/org/apache/commons/collections/list/SetUniqueList.java
@@ -216,17 +216,17 @@ public class SetUniqueList extends AbstractSerializableListDecorator {
     public Object set(int index, Object object) {
         int pos = indexOf(object);
         Object removed = super.set(index, object);
-
+        
         if (pos != -1 && pos != index) {
             // the object is already in the unique list
             // (and it hasn't been swapped with itself)
-            super.remove(pos);  // remove the duplicate by index
+            super.remove(pos); // remove the duplicate by index
         }
 
-        set.add(object);      // add the new item to the unique set
-        set.remove(removed);  // remove the item deleted by the set
+        set.remove(removed); // remove the item deleted by the set
+        set.add(object); // add the new item to the unique set
 
-        return removed;  // return the item deleted by the set
+        return removed; // return the item deleted by the set        
     }
 
     public boolean remove(Object object) {

http://git-wip-us.apache.org/repos/asf/commons-collections/blob/be671392/src/test/org/apache/commons/collections/list/TestSetUniqueList.java
----------------------------------------------------------------------
diff --git a/src/test/org/apache/commons/collections/list/TestSetUniqueList.java b/src/test/org/apache/commons/collections/list/TestSetUniqueList.java
index 086027c..b8bfdcc 100644
--- a/src/test/org/apache/commons/collections/list/TestSetUniqueList.java
+++ b/src/test/org/apache/commons/collections/list/TestSetUniqueList.java
@@ -486,7 +486,22 @@ public class TestSetUniqueList extends AbstractTestList {
         decoratedList.add(1, s2);
         assertEquals(4, decoratedList.size());
     }
-    
+
+    public void testSetCollections444() {
+        final SetUniqueList lset = new SetUniqueList(new ArrayList(), new HashSet());
+        // Duplicate element
+        final Integer obj1 = new Integer(1);
+        final Integer obj2 = new Integer(2);
+        lset.add(obj1);
+        lset.add(obj2);
+        lset.set(0, obj1);
+        assertEquals(2, lset.size());
+        assertSame(obj1, lset.get(0));
+        assertSame(obj2, lset.get(1));
+        assertTrue(lset.contains(obj1));
+        assertTrue(lset.contains(obj2));
+    }
+
     //-----------------------------------------------------------------------
     public String getCompatibilityVersion() {
         return "3.1";