[COLLECTIONS-444] SetUniqueList.set now works correctly when the object to be inserted is already at the same place. Thanks to Thomas Vahrst.

git-svn-id: https://svn.apache.org/repos/asf/commons/proper/collections/trunk@1449914 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Thomas Neidhart 2013-02-25 21:47:48 +00:00
parent 89d8791f05
commit bb9952dbed
3 changed files with 27 additions and 4 deletions

View File

@ -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>

View File

@ -232,10 +232,11 @@ public class SetUniqueList<E> extends AbstractSerializableListDecorator<E> {
// 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
}
return removed; // return the item deleted by the set
}

View File

@ -596,6 +596,24 @@ public class SetUniqueListTest<E> extends AbstractListTest<E> {
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) {