[libgee] Make List.remove_at return the removed element
- From: Didier 'Ptitjes' Villevalois <dvillevalois src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [libgee] Make List.remove_at return the removed element
- Date: Fri, 11 Sep 2009 17:21:44 +0000 (UTC)
commit 20d38b133776c44c44856dfc64c941e4e5a7c0ed
Author: Didier 'Ptitjes <ptitjes free fr>
Date: Fri Sep 11 09:49:54 2009 +0200
Make List.remove_at return the removed element
gee/abstractlist.vala | 2 +-
gee/arraylist.vala | 4 +++-
gee/linkedlist.vala | 4 +++-
gee/list.vala | 4 +++-
gee/readonlylist.vala | 2 +-
tests/testlist.vala | 6 +++---
6 files changed, 14 insertions(+), 8 deletions(-)
---
diff --git a/gee/abstractlist.vala b/gee/abstractlist.vala
index 82d57b3..dc57958 100644
--- a/gee/abstractlist.vala
+++ b/gee/abstractlist.vala
@@ -54,7 +54,7 @@ public abstract class Gee.AbstractList<G> : Gee.AbstractCollection<G>, List<G> {
/**
* @inheritDoc
*/
- public abstract void remove_at (int index);
+ public abstract G remove_at (int index);
/**
* @inheritDoc
diff --git a/gee/arraylist.vala b/gee/arraylist.vala
index f752ea9..5c7be27 100644
--- a/gee/arraylist.vala
+++ b/gee/arraylist.vala
@@ -155,15 +155,17 @@ public class Gee.ArrayList<G> : AbstractList<G> {
/**
* @inheritDoc
*/
- public override void remove_at (int index) {
+ public override G remove_at (int index) {
assert (index >= 0);
assert (index < _size);
+ G item = _items[index];
_items[index] = null;
shift (index + 1, -1);
_stamp++;
+ return item;
}
/**
diff --git a/gee/linkedlist.vala b/gee/linkedlist.vala
index 6ca470b..a35f97d 100644
--- a/gee/linkedlist.vala
+++ b/gee/linkedlist.vala
@@ -198,13 +198,15 @@ public class Gee.LinkedList<G> : AbstractList<G> {
/**
* @inheritDoc
*/
- public override void remove_at (int index) {
+ public override G remove_at (int index) {
assert (index >= 0);
assert (index < this._size);
unowned Node<G>? n = this._get_node_at (index);
return_if_fail (n != null);
+ G element = n.data;
this._remove_node (n);
+ return element;
}
/**
diff --git a/gee/list.vala b/gee/list.vala
index d7a22e7..4c00223 100644
--- a/gee/list.vala
+++ b/gee/list.vala
@@ -61,8 +61,10 @@ public interface Gee.List<G> : Collection<G> {
* Removes the item at the specified index of this list.
*
* @param index zero-based index of the item to be removed
+ *
+ * @return the removed element
*/
- public abstract void remove_at (int index);
+ public abstract G remove_at (int index);
/**
* Returns a slice of this list.
diff --git a/gee/readonlylist.vala b/gee/readonlylist.vala
index 354afa7..46ac354 100644
--- a/gee/readonlylist.vala
+++ b/gee/readonlylist.vala
@@ -60,7 +60,7 @@ internal class Gee.ReadOnlyList<G> : Gee.ReadOnlyCollection<G>, List<G> {
/**
* Unimplemented method (read only list).
*/
- public void remove_at (int index) {
+ public G remove_at (int index) {
assert_not_reached ();
}
diff --git a/tests/testlist.vala b/tests/testlist.vala
index 25cd83b..7cabdb1 100644
--- a/tests/testlist.vala
+++ b/tests/testlist.vala
@@ -276,7 +276,7 @@ public abstract class ListTests : CollectionTests {
assert (test_list.size == 5);
// Check remove_at first
- test_list.remove_at (0);
+ assert (test_list.remove_at (0) == "one");
assert (test_list.size == 4);
assert (test_list.get (0) == "two");
assert (test_list.get (1) == "three");
@@ -284,14 +284,14 @@ public abstract class ListTests : CollectionTests {
assert (test_list.get (3) == "five");
// Check remove_at last
- test_list.remove_at (3);
+ assert (test_list.remove_at (3) == "five");
assert (test_list.size == 3);
assert (test_list.get (0) == "two");
assert (test_list.get (1) == "three");
assert (test_list.get (2) == "four");
// Check remove_at in between
- test_list.remove_at (1);
+ assert (test_list.remove_at (1) == "three");
assert (test_list.size == 2);
assert (test_list.get (0) == "two");
assert (test_list.get (1) == "four");
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]