[libgee] Remove possibility of passing null to constructors of ReadOnly* classes



commit 19e50b46cbc02b5ae6d93f3049c611b02f5adc30
Author: Maciej Piechotka <uzytkownik2 gmail com>
Date:   Mon Sep 7 00:47:57 2009 +0200

    Remove possibility of passing null to constructors of ReadOnly* classes
    
    Fixes bug 590305.

 gee/readonlycollection.vala |   19 +++----------------
 gee/readonlylist.vala       |   20 ++------------------
 gee/readonlymap.vala        |   24 ++----------------------
 gee/readonlyset.vala        |    2 +-
 4 files changed, 8 insertions(+), 57 deletions(-)
---
diff --git a/gee/readonlycollection.vala b/gee/readonlycollection.vala
index fb99885..c4ad4d8 100644
--- a/gee/readonlycollection.vala
+++ b/gee/readonlycollection.vala
@@ -53,9 +53,9 @@ public class Gee.ReadOnlyCollection<G> : Object, Iterable<G>, Collection<G> {
 	 * Constructs a read-only collection that mirrors the content of the
 	 * specified collection.
 	 *
-	 * @param collection the collection to decorate (may be null).
+	 * @param collection the collection to decorate.
 	 */
-	public ReadOnlyCollection (Collection<G>? collection = null) {
+	public ReadOnlyCollection (Collection<G> collection) {
 		this._collection = collection;
 	}
 
@@ -70,10 +70,6 @@ public class Gee.ReadOnlyCollection<G> : Object, Iterable<G>, Collection<G> {
 	 * @inheritDoc
 	 */
 	public Gee.Iterator<G> iterator () {
-		if (_collection == null) {
-			return new Iterator<G> ();
-		}
-
 		return _collection.iterator ();
 	}
 
@@ -81,10 +77,6 @@ public class Gee.ReadOnlyCollection<G> : Object, Iterable<G>, Collection<G> {
 	 * @inheritDoc
 	 */
 	public bool contains (G item) {
-		if (_collection == null) {
-			return false;
-		}
-
 		return _collection.contains (item);
 	}
 
@@ -120,12 +112,7 @@ public class Gee.ReadOnlyCollection<G> : Object, Iterable<G>, Collection<G> {
 	 * @inheritDoc
 	 */
 	public bool contains_all (Collection<G> collection) {
-		foreach (G element in collection) {
-			if (!contains (element)) {
-				return false;
-			}
-		}
-		return true;
+		return _collection.contains_all (collection);
 	}
 
 	/**
diff --git a/gee/readonlylist.vala b/gee/readonlylist.vala
index 7412bf8..fd712d3 100644
--- a/gee/readonlylist.vala
+++ b/gee/readonlylist.vala
@@ -37,9 +37,9 @@ public class Gee.ReadOnlyList<G> : Gee.ReadOnlyCollection<G>, List<G> {
 	 * Constructs a read-only list that mirrors the content of the specified
 	 * list.
 	 *
-	 * @param list the list to decorate (may be null).
+	 * @param list the list to decorate.
 	 */
-	public ReadOnlyList (List<G>? list = null) {
+	public ReadOnlyList (List<G> list) {
 		base (list);
 	}
 
@@ -47,10 +47,6 @@ public class Gee.ReadOnlyList<G> : Gee.ReadOnlyCollection<G>, List<G> {
 	 * @inheritDoc
 	 */
 	public int index_of (G item) {
-		if (_collection == null) {
-			return -1;
-		}
-
 		return ((Gee.List<G>) _collection).index_of (item);
 	}
 
@@ -72,10 +68,6 @@ public class Gee.ReadOnlyList<G> : Gee.ReadOnlyCollection<G>, List<G> {
 	 * @inheritDoc
 	 */
 	public new G? get (int index) {
-		if (_collection == null) {
-			return null;
-		}
-
 		return ((Gee.List<G>) _collection).get (index);
 	}
 
@@ -97,10 +89,6 @@ public class Gee.ReadOnlyList<G> : Gee.ReadOnlyCollection<G>, List<G> {
 	 * @inheritDoc
 	 */
 	public G? first () {
-		if (_collection == null) {
-			return null;
-		}
-
 		return ((Gee.List<G>) _collection).first ();
 	}
 
@@ -108,10 +96,6 @@ public class Gee.ReadOnlyList<G> : Gee.ReadOnlyCollection<G>, List<G> {
 	 * @inheritDoc
 	 */
 	public G? last () {
-		if (_collection == null) {
-			return null;
-		}
-
 		return ((Gee.List<G>) _collection).last ();
 	}
 
diff --git a/gee/readonlymap.vala b/gee/readonlymap.vala
index 9b91365..3166104 100644
--- a/gee/readonlymap.vala
+++ b/gee/readonlymap.vala
@@ -52,9 +52,9 @@ public class Gee.ReadOnlyMap<K,V> : Object, Map<K,V> {
 	/**
 	 * Constructs a read-only map that mirrors the content of the specified map.
 	 *
-	 * @param map the map to decorate (may be null).
+	 * @param map the map to decorate.
 	 */
-	public ReadOnlyMap (Map<K,V>? map = null) {
+	public ReadOnlyMap (Map<K,V> map) {
 		this._map = map;
 	}
 
@@ -62,10 +62,6 @@ public class Gee.ReadOnlyMap<K,V> : Object, Map<K,V> {
 	 * @inheritDoc
 	 */
 	public Set<K> get_keys () {
-		if (_map == null) {
-			return new ReadOnlySet<K> ();
-		}
-
 		return _map.get_keys ();
 	}
 
@@ -73,10 +69,6 @@ public class Gee.ReadOnlyMap<K,V> : Object, Map<K,V> {
 	 * @inheritDoc
 	 */
 	public Collection<V> get_values () {
-		if (_map == null) {
-			return new ReadOnlyCollection<V> ();
-		}
-
 		return _map.get_values ();
 	}
 
@@ -84,10 +76,6 @@ public class Gee.ReadOnlyMap<K,V> : Object, Map<K,V> {
 	 * @inheritDoc
 	 */
 	public bool contains (K key) {
-		if (_map == null) {
-			return false;
-		}
-
 		return _map.contains (key);
 	}
 
@@ -95,10 +83,6 @@ public class Gee.ReadOnlyMap<K,V> : Object, Map<K,V> {
 	 * @inheritDoc
 	 */
 	public new V? get (K key) {
-		if (_map == null) {
-			return null;
-		}
-
 		return _map.get (key);
 	}
 
@@ -141,10 +125,6 @@ public class Gee.ReadOnlyMap<K,V> : Object, Map<K,V> {
 	 * @inheritDoc
 	 */
 	public bool contains_all (Map<K,V> map) {
-		if (_map == null) {
-			return false;
-		}
-
 		return _map.contains_all (map);
 	}
 }
diff --git a/gee/readonlyset.vala b/gee/readonlyset.vala
index 6bd5f72..3997409 100644
--- a/gee/readonlyset.vala
+++ b/gee/readonlyset.vala
@@ -38,7 +38,7 @@ public class Gee.ReadOnlySet<G> : Gee.ReadOnlyCollection<G>, Set<G> {
 	 *
 	 * @param set the set to decorate.
 	 */
-	public ReadOnlySet (Set<G>? set = null) {
+	public ReadOnlySet (Set<G> set) {
 		base(set);
 	}
 }



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