Author: tn
Date: Wed Apr 17 18:12:48 2013
New Revision: 1469016

URL: http://svn.apache.org/r1469016
Log:
[COLLECTIONS-444] Apply fix as suggested by John Vasileff.

Modified:
    commons/proper/collections/trunk/src/changes/changes.xml
    
commons/proper/collections/trunk/src/main/java/org/apache/commons/collections4/list/SetUniqueList.java
    
commons/proper/collections/trunk/src/test/java/org/apache/commons/collections4/list/SetUniqueListTest.java

Modified: commons/proper/collections/trunk/src/changes/changes.xml
URL: 
http://svn.apache.org/viewvc/commons/proper/collections/trunk/src/changes/changes.xml?rev=1469016&r1=1469015&r2=1469016&view=diff
==============================================================================
--- commons/proper/collections/trunk/src/changes/changes.xml (original)
+++ commons/proper/collections/trunk/src/changes/changes.xml Wed Apr 17 
18:12:48 2013
@@ -65,7 +65,7 @@
     <action issue="COLLECTIONS-396" dev="tn" type="add" due-to="Jeff 
Rodriguez">
       Added "LazyIteratorChain" iterator.
     </action>
-    <action issue="COLLECTIONS-444" dev="tn" type="fix" due-to="Thomas Vahrst">
+    <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>

Modified: 
commons/proper/collections/trunk/src/main/java/org/apache/commons/collections4/list/SetUniqueList.java
URL: 
http://svn.apache.org/viewvc/commons/proper/collections/trunk/src/main/java/org/apache/commons/collections4/list/SetUniqueList.java?rev=1469016&r1=1469015&r2=1469016&view=diff
==============================================================================
--- 
commons/proper/collections/trunk/src/main/java/org/apache/commons/collections4/list/SetUniqueList.java
 (original)
+++ 
commons/proper/collections/trunk/src/main/java/org/apache/commons/collections4/list/SetUniqueList.java
 Wed Apr 17 18:12:48 2013
@@ -214,7 +214,7 @@ public class SetUniqueList<E> extends Ab
      * Sets the value at the specified index avoiding duplicates.
      * <p>
      * The object is set into the specified index. Afterwards, any previous
-     * duplicate is removed If the object is not already in the list then a
+     * duplicate is removed. If the object is not already in the list then a
      * normal set occurs. If it is present, then the old version is removed.
      * 
      * @param index
@@ -229,15 +229,14 @@ public class SetUniqueList<E> extends Ab
         final E removed = super.set(index, object);
 
         if (pos != -1 && pos != index) {
-            // the object is already in the uniq list
+            // the object is already in the unique list
             // (and it hasn't been swapped with itself)
             super.remove(pos); // remove the duplicate by index
-            set.remove(removed); // remove the item deleted by the set
-        } else if (pos == -1) {
-            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
     }
 

Modified: 
commons/proper/collections/trunk/src/test/java/org/apache/commons/collections4/list/SetUniqueListTest.java
URL: 
http://svn.apache.org/viewvc/commons/proper/collections/trunk/src/test/java/org/apache/commons/collections4/list/SetUniqueListTest.java?rev=1469016&r1=1469015&r2=1469016&view=diff
==============================================================================
--- 
commons/proper/collections/trunk/src/test/java/org/apache/commons/collections4/list/SetUniqueListTest.java
 (original)
+++ 
commons/proper/collections/trunk/src/test/java/org/apache/commons/collections4/list/SetUniqueListTest.java
 Wed Apr 17 18:12:48 2013
@@ -613,7 +613,6 @@ public class SetUniqueListTest<E> extend
         assertTrue(lset.contains(obj2));
     }
 
-    @SuppressWarnings("serial")
     class SetUniqueList307 extends SetUniqueList<E> {
         /**
          * Generated serial version ID.


Reply via email to