[libgee] Change the Iterator.get method signature and fix implementations



commit 602eb9a4b51c9c5361f81f677d3969a5337369db
Author: Julien Peeters <contact julienpeeters fr>
Date:   Fri Sep 11 16:04:08 2009 +0200

    Change the Iterator.get method signature and fix implementations
    
    Fixes part of bug 594868.
    
    Change the return type of the Iterator.get method from G? to G and
    apply those changes to implementations: ArrayList, HashMap,
    HashMultiSet, HashSet, LinkedList, TreeMap, TreeSet.

 gee/arraylist.vala    |    9 +++------
 gee/hashmap.vala      |    4 ++--
 gee/hashmultiset.vala |    2 +-
 gee/hashset.vala      |    2 +-
 gee/iterator.vala     |    2 +-
 gee/linkedlist.vala   |    9 +++------
 gee/treemap.vala      |    4 ++--
 gee/treeset.vala      |    2 +-
 8 files changed, 14 insertions(+), 20 deletions(-)
---
diff --git a/gee/arraylist.vala b/gee/arraylist.vala
index 5c7be27..ccc59e9 100644
--- a/gee/arraylist.vala
+++ b/gee/arraylist.vala
@@ -263,13 +263,10 @@ public class Gee.ArrayList<G> : AbstractList<G> {
 			return (_index < _list._size);
 		}
 
-		public new G? get () {
+		public new G get () {
 			assert (_stamp == _list._stamp);
-
-			if (_index < 0 || _index >= _list._size) {
-				return null;
-			}
-
+			assert (_index >= 0);
+			assert (_index < _list._size);
 			return _list.get (_index);
 		}
 	}
diff --git a/gee/hashmap.vala b/gee/hashmap.vala
index 40e6964..f34f923 100644
--- a/gee/hashmap.vala
+++ b/gee/hashmap.vala
@@ -311,7 +311,7 @@ public class Gee.HashMap<K,V> : Gee.AbstractMap<K,V> {
 			return (_node != null);
 		}
 
-		public new K? get () {
+		public new K get () {
 			assert (_stamp == _map._stamp);
 			assert (_node != null);
 			return _node.key;
@@ -398,7 +398,7 @@ public class Gee.HashMap<K,V> : Gee.AbstractMap<K,V> {
 			return (_node != null);
 		}
 
-		public new V? get () {
+		public new V get () {
 			assert (_stamp == _map._stamp);
 			assert (_node != null);
 			return _node.value;
diff --git a/gee/hashmultiset.vala b/gee/hashmultiset.vala
index 123ea32..c977426 100644
--- a/gee/hashmultiset.vala
+++ b/gee/hashmultiset.vala
@@ -120,7 +120,7 @@ public class Gee.HashMultiSet<G> : AbstractCollection<G>, MultiSet<G> {
 			return false;
 		}
 
-		public new G? get () {
+		public new G get () {
 			return _iter.get ();
 		}
 	}
diff --git a/gee/hashset.vala b/gee/hashset.vala
index 8956791..0763350 100644
--- a/gee/hashset.vala
+++ b/gee/hashset.vala
@@ -230,7 +230,7 @@ public class Gee.HashSet<G> : AbstractSet<G> {
 			return (_node != null);
 		}
 
-		public new G? get () {
+		public new G get () {
 			assert (_stamp == _set._stamp);
 			assert (_node != null);
 			return _node.key;
diff --git a/gee/iterator.vala b/gee/iterator.vala
index 4f05b5c..41de156 100644
--- a/gee/iterator.vala
+++ b/gee/iterator.vala
@@ -36,6 +36,6 @@ public interface Gee.Iterator<G> : GLib.Object {
 	 *
 	 * @return the current element in the iteration
 	 */
-	public abstract G? get ();
+	public abstract G get ();
 }
 
diff --git a/gee/linkedlist.vala b/gee/linkedlist.vala
index d83869f..7b4775f 100644
--- a/gee/linkedlist.vala
+++ b/gee/linkedlist.vala
@@ -414,14 +414,11 @@ public class Gee.LinkedList<G> : AbstractList<G>, Queue<G>, Deque<G> {
 			}
 		}
 
-		public new G? get () {
+		public new G get () {
 			assert (this._stamp == this._list._stamp);
+			assert (this.position != null);
 
-			if (this.position == null) {
-				return null;
-			} else {
-				return this.position.data;
-			}
+			return this.position.data;
 		}
 	}
 
diff --git a/gee/treemap.vala b/gee/treemap.vala
index 6f91a3a..69d374a 100644
--- a/gee/treemap.vala
+++ b/gee/treemap.vala
@@ -480,7 +480,7 @@ public class Gee.TreeMap<K,V> : Gee.AbstractMap<K,V> {
 			}
 		}
 
-		public new K? get () {
+		public new K get () {
 			assert (stamp == map.stamp);
 			assert (current != null);
 			return current.key;
@@ -523,7 +523,7 @@ public class Gee.TreeMap<K,V> : Gee.AbstractMap<K,V> {
 			}
 		}
 
-		public new V? get () {
+		public new V get () {
 			assert (stamp == map.stamp);
 			assert (current != null);
 			return current.value;
diff --git a/gee/treeset.vala b/gee/treeset.vala
index a325705..443c468 100644
--- a/gee/treeset.vala
+++ b/gee/treeset.vala
@@ -336,7 +336,7 @@ public class Gee.TreeSet<G> : AbstractSet<G> {
 			}
 		}
 
-		public new G? get () {
+		public new G get () {
 			assert (stamp == set.stamp);
 			assert (current != null);
 			return current.key;



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]