[libgee] Fix misunderstanding about ArrayList.{retain, remove}_all semantics
- From: Didier 'Ptitjes' Villevalois <dvillevalois src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [libgee] Fix misunderstanding about ArrayList.{retain, remove}_all semantics
- Date: Sun, 6 Sep 2009 20:00:40 +0000 (UTC)
commit da29acdbac97708473b0c1ad288993296ac7cc6b
Author: Julien Peeters <contact julienpeeters fr>
Date: Sun Sep 6 20:38:25 2009 +0200
Fix misunderstanding about ArrayList.{retain,remove}_all semantics
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 | 30 ------------------------------
gee/collection.vala | 7 ++++---
tests/testcollection.vala | 6 +++---
3 files changed, 7 insertions(+), 36 deletions(-)
---
diff --git a/gee/arraylist.vala b/gee/arraylist.vala
index 54c777d..f99430e 100644
--- a/gee/arraylist.vala
+++ b/gee/arraylist.vala
@@ -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);
diff --git a/gee/collection.vala b/gee/collection.vala
index 7827a86..769ee93 100644
--- a/gee/collection.vala
+++ b/gee/collection.vala
@@ -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.
diff --git a/tests/testcollection.vala b/tests/testcollection.vala
index 88a1b67..ce18275 100644
--- a/tests/testcollection.vala
+++ b/tests/testcollection.vala
@@ -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);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]