[libgee/0.4.x: 8/11] Remove possibility of passing null to constructors of ReadOnly* classes



commit 2c73d39f267024a9c3e384ca162377b62b46a3bc
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 |   23 ++++++++---------------
 gee/readonlylist.vala       |   20 ++------------------
 gee/readonlymap.vala        |   27 ++++++---------------------
 gee/readonlyset.vala        |    7 ++++++-
 4 files changed, 22 insertions(+), 55 deletions(-)
---
diff --git a/gee/readonlycollection.vala b/gee/readonlycollection.vala
index 2893ef1..3953ce6 100644
--- a/gee/readonlycollection.vala
+++ b/gee/readonlycollection.vala
@@ -36,7 +36,13 @@ public class Gee.ReadOnlyCollection<G> : Object, Iterable<G>, Collection<G> {
 
 	protected Collection<G> _collection;
 
-	public ReadOnlyCollection (Collection<G>? collection = null) {
+	/**
+	 * Constructs a read-only collection that mirrors the content of the
+	 * specified collection.
+	 *
+	 * @param collection the collection to decorate.
+	 */
+	public ReadOnlyCollection (Collection<G> collection) {
 		this._collection = collection;
 	}
 
@@ -45,18 +51,10 @@ public class Gee.ReadOnlyCollection<G> : Object, Iterable<G>, Collection<G> {
 	}
 
 	public Gee.Iterator<G> iterator () {
-		if (_collection == null) {
-			return new Iterator<G> ();
-		}
-
 		return _collection.iterator ();
 	}
 
 	public bool contains (G item) {
-		if (_collection == null) {
-			return false;
-		}
-
 		return _collection.contains (item);
 	}
 
@@ -77,12 +75,7 @@ public class Gee.ReadOnlyCollection<G> : Object, Iterable<G>, Collection<G> {
 	}
 
 	public bool contains_all (Collection<G> collection) {
-		foreach (G element in collection) {
-			if (!contains (element)) {
-				return false;
-			}
-		}
-		return true;
+		return _collection.contains_all (collection);
 	}
 
 	public bool remove_all (Collection<G> collection) {
diff --git a/gee/readonlylist.vala b/gee/readonlylist.vala
index 01a15e7..08f6c0a 100644
--- a/gee/readonlylist.vala
+++ b/gee/readonlylist.vala
@@ -31,17 +31,13 @@ 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);
 	}
 
 	public int index_of (G item) {
-		if (_collection == null) {
-			return -1;
-		}
-
 		return ((Gee.List<G>) _collection).index_of (item);
 	}
 
@@ -54,10 +50,6 @@ public class Gee.ReadOnlyList<G> : Gee.ReadOnlyCollection<G>, List<G> {
 	}
 
 	public new G? get (int index) {
-		if (_collection == null) {
-			return null;
-		}
-
 		return ((Gee.List<G>) _collection).get (index);
 	}
 
@@ -76,18 +68,10 @@ 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 ();
 	}
 
 	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 9e53db3..0231d48 100644
--- a/gee/readonlymap.vala
+++ b/gee/readonlymap.vala
@@ -36,39 +36,28 @@ public class Gee.ReadOnlyMap<K,V> : Object, Map<K,V> {
 
 	private Map<K,V> _map;
 
-	public ReadOnlyMap (Map<K,V>? map = null) {
+	/**
+	 * Constructs a read-only map that mirrors the content of the specified map.
+	 *
+	 * @param map the map to decorate.
+	 */
+	public ReadOnlyMap (Map<K,V> map) {
 		this._map = map;
 	}
 
 	public Set<K> get_keys () {
-		if (_map == null) {
-			return new ReadOnlySet<K> ();
-		}
-
 		return _map.get_keys ();
 	}
 
 	public Collection<V> get_values () {
-		if (_map == null) {
-			return new ReadOnlyCollection<V> ();
-		}
-
 		return _map.get_values ();
 	}
 
 	public bool contains (K key) {
-		if (_map == null) {
-			return false;
-		}
-
 		return _map.contains (key);
 	}
 
 	public new V? get (K key) {
-		if (_map == null) {
-			return null;
-		}
-
 		return _map.get (key);
 	}
 
@@ -93,10 +82,6 @@ public class Gee.ReadOnlyMap<K,V> : Object, Map<K,V> {
 	}
 
 	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 a9feb1f..5bca179 100644
--- a/gee/readonlyset.vala
+++ b/gee/readonlyset.vala
@@ -27,7 +27,12 @@ using GLib;
  */
 public class Gee.ReadOnlySet<G> : Gee.ReadOnlyCollection<G>, Set<G> {
 
-	public ReadOnlySet (Set<G>? set = null) {
+	/**
+	 * Constructs a read-only set that mirrors the content of the specified set.
+	 *
+	 * @param set the set to decorate.
+	 */
+	public ReadOnlySet (Set<G> set) {
 		base(set);
 	}
 }



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