You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by ba...@apache.org on 2007/04/21 15:44:47 UTC
svn commit: r531027 - in /jakarta/commons/proper/collections/trunk:
RELEASE-NOTES.html
src/java/org/apache/commons/collections/list/SetUniqueList.java
src/test/org/apache/commons/collections/list/TestSetUniqueList.java
Author: bayard
Date: Sat Apr 21 06:44:46 2007
New Revision: 531027
URL: http://svn.apache.org/viewvc?view=rev&rev=531027
Log:
Applying Joe Kelly's fix for COLLECTIONS-249 - SetUniqueList.addAll(int, Collection
) was always inserting at the end of the list
Modified:
jakarta/commons/proper/collections/trunk/RELEASE-NOTES.html
jakarta/commons/proper/collections/trunk/src/java/org/apache/commons/collections/list/SetUniqueList.java
jakarta/commons/proper/collections/trunk/src/test/org/apache/commons/collections/list/TestSetUniqueList.java
Modified: jakarta/commons/proper/collections/trunk/RELEASE-NOTES.html
URL: http://svn.apache.org/viewvc/jakarta/commons/proper/collections/trunk/RELEASE-NOTES.html?view=diff&rev=531027&r1=531026&r2=531027
==============================================================================
--- jakarta/commons/proper/collections/trunk/RELEASE-NOTES.html (original)
+++ jakarta/commons/proper/collections/trunk/RELEASE-NOTES.html Sat Apr 21 06:44:46 2007
@@ -59,6 +59,7 @@
<li>ExtendedProperties - Include property name had confused static/instance semantics [COLLECTIONS-214]</li>
<li>CollectionUtils - Fix removeAll() method which was completely broken [COLLECTIONS-219]</li>
<li>MultiValueMap - Fix put() and putAll() to return correct results [COLLECTIONS-228]</li>
+<li>SetUniqueList - addAll(int, Collection) fixed to properly insert at the specified index [COLLECTIONS-249]</li>
</ul>
<center><h3>JAVADOC</h3></center>
Modified: jakarta/commons/proper/collections/trunk/src/java/org/apache/commons/collections/list/SetUniqueList.java
URL: http://svn.apache.org/viewvc/jakarta/commons/proper/collections/trunk/src/java/org/apache/commons/collections/list/SetUniqueList.java?view=diff&rev=531027&r1=531026&r2=531027
==============================================================================
--- jakarta/commons/proper/collections/trunk/src/java/org/apache/commons/collections/list/SetUniqueList.java (original)
+++ jakarta/commons/proper/collections/trunk/src/java/org/apache/commons/collections/list/SetUniqueList.java Sat Apr 21 06:44:46 2007
@@ -155,20 +155,25 @@
}
/**
- * Adds an element to the end of the list if it is not already present.
+ * Adds a collection of objects to the end of 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.
* <p>
* <i>(Violation)</i>
- * The <code>List</code> interface makes the assumption that the element is
- * always inserted. This may not happen with this implementation.
+ * The <code>List</code> interface makes the assumption that the elements
+ * are always inserted. This may not happen with this implementation.
*
- * @param coll the collection to add
+ * @param coll the collection to add in iterator order
+ * @return true if this collection changed
*/
public boolean addAll(Collection coll) {
return addAll(size(), coll);
}
/**
- * 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 +192,12 @@
// 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
Modified: jakarta/commons/proper/collections/trunk/src/test/org/apache/commons/collections/list/TestSetUniqueList.java
URL: http://svn.apache.org/viewvc/jakarta/commons/proper/collections/trunk/src/test/org/apache/commons/collections/list/TestSetUniqueList.java?view=diff&rev=531027&r1=531026&r2=531027
==============================================================================
--- jakarta/commons/proper/collections/trunk/src/test/org/apache/commons/collections/list/TestSetUniqueList.java (original)
+++ jakarta/commons/proper/collections/trunk/src/test/org/apache/commons/collections/list/TestSetUniqueList.java Sat Apr 21 06:44:46 2007
@@ -144,6 +144,31 @@
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
---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org