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
This commit is contained in:
Thomas Neidhart 2015-11-08 21:35:53 +00:00
parent 7f947f938d
commit be67139289
3 changed files with 25 additions and 10 deletions

View File

@ -29,6 +29,10 @@
permission to read system properties, the "File#separator" field will permission to read system properties, the "File#separator" field will
be used instead. be used instead.
</action> </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"> <action issue="COLLECTIONS-350" dev="bayard" type="fix" due-to="Michael Akerman">
Removed debug output in "MapUtils#getNumber(Map)". Removed debug output in "MapUtils#getNumber(Map)".
</action> </action>
@ -78,10 +82,6 @@
Tree traversal with a TreeListIterator will not be affected anymore by Tree traversal with a TreeListIterator will not be affected anymore by
the removal of an element directly after a call to previous(). the removal of an element directly after a call to previous().
</action> </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"> <action issue="COLLECTIONS-359" dev="bayard" type="fix" due-to="Mark Shead">
"ListUtils#intersection(List, List)" will now also work correctly if there "ListUtils#intersection(List, List)" will now also work correctly if there
are duplicate elements in the provided lists. are duplicate elements in the provided lists.

View File

@ -223,8 +223,8 @@ public class SetUniqueList extends AbstractSerializableListDecorator {
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
} }

View File

@ -487,6 +487,21 @@ public class TestSetUniqueList extends AbstractTestList {
assertEquals(4, decoratedList.size()); 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() { public String getCompatibilityVersion() {
return "3.1"; return "3.1";