[COLLECTIONS-444] Apply fix as suggested by John Vasileff.

git-svn-id: https://svn.apache.org/repos/asf/commons/proper/collections/trunk@1469016 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Thomas Neidhart 2013-04-17 18:12:48 +00:00
parent 9036c09662
commit f7a557a38a
3 changed files with 7 additions and 9 deletions

View File

@ -65,7 +65,7 @@
<action issue="COLLECTIONS-396" dev="tn" type="add" due-to="Jeff Rodriguez">
Added "LazyIteratorChain" iterator.
</action>
<action issue="COLLECTIONS-444" dev="tn" type="fix" due-to="Thomas Vahrst">
<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>

View File

@ -214,7 +214,7 @@ public class SetUniqueList<E> extends AbstractSerializableListDecorator<E> {
* Sets the value at the specified index avoiding duplicates.
* <p>
* The object is set into the specified index. Afterwards, any previous
* duplicate is removed If the object is not already in the list then a
* duplicate is removed. If the object is not already in the list then a
* normal set occurs. If it is present, then the old version is removed.
*
* @param index
@ -229,15 +229,14 @@ public class SetUniqueList<E> extends AbstractSerializableListDecorator<E> {
final E removed = super.set(index, object);
if (pos != -1 && pos != index) {
// the object is already in the uniq list
// the object is already in the unique 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.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
}

View File

@ -613,7 +613,6 @@ public class SetUniqueListTest<E> extends AbstractListTest<E> {
assertTrue(lset.contains(obj2));
}
@SuppressWarnings("serial")
class SetUniqueList307 extends SetUniqueList<E> {
/**
* Generated serial version ID.