commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bay...@apache.org
Subject svn commit: r711591 - in /commons/proper/collections/trunk/src: java/org/apache/commons/collections/list/SetUniqueList.java test/org/apache/commons/collections/list/TestSetUniqueList.java
Date Wed, 05 Nov 2008 15:47:43 GMT
Author: bayard
Date: Wed Nov  5 07:47:43 2008
New Revision: 711591

URL: http://svn.apache.org/viewvc?rev=711591&view=rev
Log:
Applying Bjorn Townsend's unit test and my fix for COLLECTIONS-304 - fixing SetUniqueList
so the set method doesn't let the uniqueness get out of sync

Modified:
    commons/proper/collections/trunk/src/java/org/apache/commons/collections/list/SetUniqueList.java
    commons/proper/collections/trunk/src/test/org/apache/commons/collections/list/TestSetUniqueList.java

Modified: commons/proper/collections/trunk/src/java/org/apache/commons/collections/list/SetUniqueList.java
URL: http://svn.apache.org/viewvc/commons/proper/collections/trunk/src/java/org/apache/commons/collections/list/SetUniqueList.java?rev=711591&r1=711590&r2=711591&view=diff
==============================================================================
--- commons/proper/collections/trunk/src/java/org/apache/commons/collections/list/SetUniqueList.java
(original)
+++ commons/proper/collections/trunk/src/java/org/apache/commons/collections/list/SetUniqueList.java
Wed Nov  5 07:47:43 2008
@@ -220,14 +220,16 @@
     public Object set(int index, Object object) {
         int pos = indexOf(object);
         Object removed = super.set(index, object);
-        if (pos == -1 || pos == index) {
-            return removed;
+
+        if (pos != -1 && pos != index) {
+            // the object is already in the uniq list
+            // (and it hasn't been swapped with itself)
+            super.remove(pos);  // remove the duplicate by index
         }
-        
-        // the object is already in the uniq list
-        // (and it hasn't been swapped with itself)
-        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
+
         return removed;  // return the item deleted by the set
     }
 

Modified: commons/proper/collections/trunk/src/test/org/apache/commons/collections/list/TestSetUniqueList.java
URL: http://svn.apache.org/viewvc/commons/proper/collections/trunk/src/test/org/apache/commons/collections/list/TestSetUniqueList.java?rev=711591&r1=711590&r2=711591&view=diff
==============================================================================
--- commons/proper/collections/trunk/src/test/org/apache/commons/collections/list/TestSetUniqueList.java
(original)
+++ commons/proper/collections/trunk/src/test/org/apache/commons/collections/list/TestSetUniqueList.java
Wed Nov  5 07:47:43 2008
@@ -443,4 +443,31 @@
 //        writeExternalFormToDisk((java.io.Serializable) collection, "D:/dev/collections/data/test/SetUniqueList.fullCollection.version3.1.obj");
 //    }
 
+    public void testCollections304() {
+        List list = new LinkedList();
+        SetUniqueList decoratedList = SetUniqueList.decorate(list);
+        String s1 = "Apple";
+        String s2 = "Lemon";
+        String s3 = "Orange";
+        String s4 = "Strawberry";
+
+        decoratedList.add(s1);
+        decoratedList.add(s2);
+        decoratedList.add(s3);
+
+        assertEquals(3, decoratedList.size());
+
+        decoratedList.set(1, s4);
+
+        assertEquals(3, decoratedList.size());
+
+        decoratedList.add(1, s4);
+
+        assertEquals(3, decoratedList.size());
+
+        decoratedList.add(1, s2);
+
+        assertEquals(4, decoratedList.size());
+    }
+
 }



Mime
View raw message