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 2015/11/08 22:35:54 UTC
svn commit: r1713299 - in
/commons/proper/collections/branches/COLLECTIONS_3_2_X/src:
changes/changes.xml
java/org/apache/commons/collections/list/SetUniqueList.java
test/org/apache/commons/collections/list/TestSetUniqueList.java
Author: tn
Date: Sun Nov 8 21:35:53 2015
New Revision: 1713299
URL: http://svn.apache.org/viewvc?rev=1713299&view=rev
Log:
Backport COLLECTIONS-444 to 3.2.2.
Modified:
commons/proper/collections/branches/COLLECTIONS_3_2_X/src/changes/changes.xml
commons/proper/collections/branches/COLLECTIONS_3_2_X/src/java/org/apache/commons/collections/list/SetUniqueList.java
commons/proper/collections/branches/COLLECTIONS_3_2_X/src/test/org/apache/commons/collections/list/TestSetUniqueList.java
Modified: commons/proper/collections/branches/COLLECTIONS_3_2_X/src/changes/changes.xml
URL: http://svn.apache.org/viewvc/commons/proper/collections/branches/COLLECTIONS_3_2_X/src/changes/changes.xml?rev=1713299&r1=1713298&r2=1713299&view=diff
==============================================================================
--- commons/proper/collections/branches/COLLECTIONS_3_2_X/src/changes/changes.xml (original)
+++ commons/proper/collections/branches/COLLECTIONS_3_2_X/src/changes/changes.xml Sun Nov 8 21:35:53 2015
@@ -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.
Modified: commons/proper/collections/branches/COLLECTIONS_3_2_X/src/java/org/apache/commons/collections/list/SetUniqueList.java
URL: http://svn.apache.org/viewvc/commons/proper/collections/branches/COLLECTIONS_3_2_X/src/java/org/apache/commons/collections/list/SetUniqueList.java?rev=1713299&r1=1713298&r2=1713299&view=diff
==============================================================================
--- commons/proper/collections/branches/COLLECTIONS_3_2_X/src/java/org/apache/commons/collections/list/SetUniqueList.java (original)
+++ commons/proper/collections/branches/COLLECTIONS_3_2_X/src/java/org/apache/commons/collections/list/SetUniqueList.java Sun Nov 8 21:35:53 2015
@@ -216,17 +216,17 @@ public class SetUniqueList extends Abstr
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) {
Modified: commons/proper/collections/branches/COLLECTIONS_3_2_X/src/test/org/apache/commons/collections/list/TestSetUniqueList.java
URL: http://svn.apache.org/viewvc/commons/proper/collections/branches/COLLECTIONS_3_2_X/src/test/org/apache/commons/collections/list/TestSetUniqueList.java?rev=1713299&r1=1713298&r2=1713299&view=diff
==============================================================================
--- commons/proper/collections/branches/COLLECTIONS_3_2_X/src/test/org/apache/commons/collections/list/TestSetUniqueList.java (original)
+++ commons/proper/collections/branches/COLLECTIONS_3_2_X/src/test/org/apache/commons/collections/list/TestSetUniqueList.java Sun Nov 8 21:35:53 2015
@@ -486,7 +486,22 @@ public class TestSetUniqueList extends A
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";