Fix misunderstanding about ArrayList.{retain,remove}_all semantics
authorJulien Peeters <contact@julienpeeters.fr>
Sun, 6 Sep 2009 18:38:25 +0000 (20:38 +0200)
committerDidier 'Ptitjes <ptitjes@free.fr>
Sun, 6 Sep 2009 19:58:17 +0000 (21:58 +0200)
These methods did not match the semantic of the Collection interface ones.
Then they are deleted in order to use the implementation in
AbstractCollection.

By the way, few optimization could probably be found for these methods in
the case of ArrayList.

gee/arraylist.vala
gee/collection.vala
tests/testcollection.vala

index 54c777d..f99430e 100644 (file)
@@ -209,36 +209,6 @@ public class Gee.ArrayList<G> : AbstractList<G> {
                return true;
        }
 
-       /**
-        * @inheritDoc
-        */
-       public override bool remove_all (Collection<G> collection) {
-               bool changed = false;
-               for (int index = 0; index < _size; index++) {
-                       if (collection.contains (_items[index])) {
-                               remove_at (index);
-                               index--;
-                               changed = true;
-                       }
-               }
-               return changed;
-       }
-
-       /**
-        * @inheritDoc
-        */
-       public override bool retain_all (Collection<G> collection) {
-               bool changed = false;
-               for (int index = 0; index < _size; index++) {
-                       if (!collection.contains (_items[index])) {
-                               remove_at (index);
-                               index--;
-                               changed = true;
-                       }
-               }
-               return changed;
-       }
-
        private void shift (int start, int delta) {
                assert (start >= 0);
                assert (start <= _size);
index 7827a86..769ee93 100644 (file)
@@ -91,9 +91,10 @@ public interface Gee.Collection<G> : Iterable<G> {
        public abstract bool contains_all (Collection<G> collection);
 
        /**
-        * Removes all items in this collection that are contained in the input 
-        * collection. In other words all common items of both collections are 
-        * removed from this collection.
+        * Removes the subset of items in this collection corresponding to the
+        * elments in the input collection. If there is several occurrences of
+        * the same value in this collection they are decremented of the number
+        * of occurrences in the input collection.
         * 
         * @param collection the collection which items will be compared with
         *                   this collection.
index 88a1b67..ce18275 100644 (file)
@@ -125,14 +125,14 @@ public abstract class CollectionTests : Gee.TestCase {
                assert (! test_collection.contains("three"));
                assert (test_collection.size == 1);
                assert (! test_collection.is_empty);
-               
+
                assert (test_collection.add ("two"));
                assert (test_collection.contains("one"));
                assert (test_collection.contains("two"));
                assert (! test_collection.contains("three"));
                assert (test_collection.size == 2);
                assert (! test_collection.is_empty);
-               
+
                assert (test_collection.add ("three"));
                assert (test_collection.contains("one"));
                assert (test_collection.contains("two"));
@@ -355,7 +355,7 @@ public abstract class CollectionTests : Gee.TestCase {
 
                assert (test_collection.remove_all (dummy));
 
-               assert (test_collection.is_empty);
+               assert (test_collection.size == 2);
                assert (dummy.size == 2);
        }