You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by tn...@apache.org on 2013/02/25 22:47:49 UTC
svn commit: r1449914 - in /commons/proper/collections/trunk/src:
changes/changes.xml
main/java/org/apache/commons/collections/list/SetUniqueList.java
test/java/org/apache/commons/collections/list/SetUniqueListTest.java
Author: tn
Date: Mon Feb 25 21:47:48 2013
New Revision: 1449914
URL: http://svn.apache.org/r1449914
Log:
[COLLECTIONS-444] SetUniqueList.set now works correctly when the object to be inserted is already at the same place. Thanks to Thomas Vahrst.
Modified:
commons/proper/collections/trunk/src/changes/changes.xml
commons/proper/collections/trunk/src/main/java/org/apache/commons/collections/list/SetUniqueList.java
commons/proper/collections/trunk/src/test/java/org/apache/commons/collections/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=1449914&r1=1449913&r2=1449914&view=diff
==============================================================================
--- commons/proper/collections/trunk/src/changes/changes.xml (original)
+++ commons/proper/collections/trunk/src/changes/changes.xml Mon Feb 25 21:47:48 2013
@@ -22,6 +22,10 @@
<body>
<release version="4.0" date="TBA" description="Next release">
+ <action issue="COLLECTIONS-444" dev="tn" type="fix" due-to="Thomas Vahrst">
+ SetUniqueList.set(int, E) now works correctly if the object to be inserted
+ is already placed at the given position.
+ </action>
<action issue="COLLECTIONS-441" dev="tn" type="fix" due-to="Thomas Vahrst">
MultiKeyMap.clone() now correctly calls super.clone().
</action>
Modified: commons/proper/collections/trunk/src/main/java/org/apache/commons/collections/list/SetUniqueList.java
URL: http://svn.apache.org/viewvc/commons/proper/collections/trunk/src/main/java/org/apache/commons/collections/list/SetUniqueList.java?rev=1449914&r1=1449913&r2=1449914&view=diff
==============================================================================
--- commons/proper/collections/trunk/src/main/java/org/apache/commons/collections/list/SetUniqueList.java (original)
+++ commons/proper/collections/trunk/src/main/java/org/apache/commons/collections/list/SetUniqueList.java Mon Feb 25 21:47:48 2013
@@ -232,11 +232,12 @@ public class SetUniqueList<E> extends Ab
// 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.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.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/java/org/apache/commons/collections/list/SetUniqueListTest.java
URL: http://svn.apache.org/viewvc/commons/proper/collections/trunk/src/test/java/org/apache/commons/collections/list/SetUniqueListTest.java?rev=1449914&r1=1449913&r2=1449914&view=diff
==============================================================================
--- commons/proper/collections/trunk/src/test/java/org/apache/commons/collections/list/SetUniqueListTest.java (original)
+++ commons/proper/collections/trunk/src/test/java/org/apache/commons/collections/list/SetUniqueListTest.java Mon Feb 25 21:47:48 2013
@@ -596,6 +596,24 @@ public class SetUniqueListTest<E> extend
assertTrue(stop - start < 5000);
}
+ public void testSetCollections444() {
+ final SetUniqueList<Integer> lset = new SetUniqueList<Integer>(new ArrayList<Integer>(), new HashSet<Integer>());
+
+ // 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));
+ }
+
@SuppressWarnings("serial")
class SetUniqueList307 extends SetUniqueList<E> {
public SetUniqueList307(final List<E> list, final Set<E> set) {