Backport COLLECTIONS-249 to 3.2.2.
git-svn-id: https://svn.apache.org/repos/asf/commons/proper/collections/branches/COLLECTIONS_3_2_X@1713172 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
a2ddc7cdd3
commit
16b1e26bd1
|
@ -23,6 +23,10 @@
|
|||
|
||||
<release version="3.2.2" date="20XX-XX-XX" description="This is a bugfix release.">
|
||||
|
||||
<action issue="COLLECTIONS-249" dev="bayard" type="fix" due-to="Joe Kelly">
|
||||
"SetUniqueList.addAll(int, Collection)" now correctly add the collection at the
|
||||
provided index.
|
||||
</action>
|
||||
<action issue="COLLECTIONS-219" dev="scolebourne" type="fix" due-to="Tom Leccese">
|
||||
"CollectionUtils#removeAll" wrongly called "ListUtils#retainAll".
|
||||
</action>
|
||||
|
@ -74,10 +78,6 @@
|
|||
"Flat3Map#remove(Object)" will now return the correct value mapped to the removed key
|
||||
if the size of the map is less or equal 3.
|
||||
</action>
|
||||
<action issue="COLLECTIONS-249" dev="bayard" type="fix" due-to="Joe Kelly">
|
||||
"SetUniqueList.addAll(int, Collection)" now correctly add the collection at the
|
||||
provided index.
|
||||
</action>
|
||||
<action issue="COLLECTIONS-228" dev="scolebourne" type="fix">
|
||||
"MultiValueMap#put(Object, Object)" and "MultiValueMap#putAll(Object, Collection)"
|
||||
now correctly return if the map has changed by this operation.
|
||||
|
|
|
@ -168,7 +168,8 @@ public class SetUniqueList extends AbstractSerializableListDecorator {
|
|||
}
|
||||
|
||||
/**
|
||||
* Adds a collection of objects to the end of the list avoiding duplicates.
|
||||
* Adds a collection of objects a specific index in the list avoiding
|
||||
* duplicates.
|
||||
* <p>
|
||||
* Only elements that are not already in this list will be added, and
|
||||
* duplicates from the specified collection will be ignored.
|
||||
|
@ -187,7 +188,12 @@ public class SetUniqueList extends AbstractSerializableListDecorator {
|
|||
|
||||
// adds all elements
|
||||
for (final Iterator it = coll.iterator(); it.hasNext();) {
|
||||
add(it.next());
|
||||
int sizeBeforeAddNext = size();
|
||||
add(index, it.next());
|
||||
// if it was inserted, then increase the target index
|
||||
if (sizeBeforeAddNext != size()) {
|
||||
index++;
|
||||
}
|
||||
}
|
||||
|
||||
// compares sizes to detect if collection changed
|
||||
|
|
|
@ -144,7 +144,31 @@ public class TestSetUniqueList extends AbstractTestList {
|
|||
assertEquals("Size should increase after addAll",
|
||||
size + elements.length, collection.size());
|
||||
}
|
||||
|
||||
|
||||
public void testIntCollectionAddAll() {
|
||||
// make a SetUniqueList with one element
|
||||
List list = new SetUniqueList(new ArrayList(), new HashSet());
|
||||
final Integer existingElement = new Integer(1);
|
||||
list.add(existingElement);
|
||||
|
||||
// add two new unique elements at index 0
|
||||
final Integer firstNewElement = new Integer(2);
|
||||
final Integer secondNewElement = new Integer(3);
|
||||
collection = Arrays.asList(new Integer[] { firstNewElement, secondNewElement });
|
||||
list.addAll(0, collection);
|
||||
assertEquals("Unique elements should be added.", 3, list.size());
|
||||
assertEquals("First new element should be at index 0", firstNewElement, list.get(0));
|
||||
assertEquals("Second new element should be at index 1", secondNewElement, list.get(1));
|
||||
assertEquals("Existing element should shift to index 2", existingElement, list.get(2));
|
||||
|
||||
// add a duplicate element and a unique element at index 0
|
||||
final Integer thirdNewElement = new Integer(4);
|
||||
collection = Arrays.asList(new Integer[] { existingElement, thirdNewElement });
|
||||
list.addAll(0, collection);
|
||||
assertEquals("Duplicate element should not be added, unique element should be added.", 4, list.size());
|
||||
assertEquals("Third new element should be at index 0", thirdNewElement, list.get(0));
|
||||
}
|
||||
|
||||
public void testListSetByIndex() {
|
||||
// override for set behaviour
|
||||
resetFull();
|
||||
|
|
Loading…
Reference in New Issue