[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:
parent
9036c09662
commit
f7a557a38a
|
@ -65,7 +65,7 @@
|
||||||
<action issue="COLLECTIONS-396" dev="tn" type="add" due-to="Jeff Rodriguez">
|
<action issue="COLLECTIONS-396" dev="tn" type="add" due-to="Jeff Rodriguez">
|
||||||
Added "LazyIteratorChain" iterator.
|
Added "LazyIteratorChain" iterator.
|
||||||
</action>
|
</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
|
SetUniqueList.set(int, E) now works correctly if the object to be inserted
|
||||||
is already placed at the given position.
|
is already placed at the given position.
|
||||||
</action>
|
</action>
|
||||||
|
|
|
@ -214,7 +214,7 @@ public class SetUniqueList<E> extends AbstractSerializableListDecorator<E> {
|
||||||
* Sets the value at the specified index avoiding duplicates.
|
* Sets the value at the specified index avoiding duplicates.
|
||||||
* <p>
|
* <p>
|
||||||
* The object is set into the specified index. Afterwards, any previous
|
* 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.
|
* normal set occurs. If it is present, then the old version is removed.
|
||||||
*
|
*
|
||||||
* @param index
|
* @param index
|
||||||
|
@ -229,15 +229,14 @@ public class SetUniqueList<E> extends AbstractSerializableListDecorator<E> {
|
||||||
final E removed = super.set(index, object);
|
final E removed = super.set(index, object);
|
||||||
|
|
||||||
if (pos != -1 && pos != index) {
|
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)
|
// (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.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
|
return removed; // return the item deleted by the set
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -613,7 +613,6 @@ public class SetUniqueListTest<E> extends AbstractListTest<E> {
|
||||||
assertTrue(lset.contains(obj2));
|
assertTrue(lset.contains(obj2));
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("serial")
|
|
||||||
class SetUniqueList307 extends SetUniqueList<E> {
|
class SetUniqueList307 extends SetUniqueList<E> {
|
||||||
/**
|
/**
|
||||||
* Generated serial version ID.
|
* Generated serial version ID.
|
||||||
|
|
Loading…
Reference in New Issue