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:
parent
7f947f938d
commit
be67139289
|
@ -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.
|
||||
|
|
|
@ -216,17 +216,17 @@ public class SetUniqueList extends AbstractSerializableListDecorator {
|
|||
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) {
|
||||
|
|
|
@ -486,7 +486,22 @@ public class TestSetUniqueList extends AbstractTestList {
|
|||
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";
|
||||
|
|
Loading…
Reference in New Issue