[libgee] Move virtual methods to Map interface



commit e300c2a1ebd59362aefffa70a640a377aeadefc8
Author: Maciej Piechotka <uzytkownik2 gmail com>
Date:   Sat Aug 18 18:36:00 2012 -0700

    Move virtual methods to Map interface

 gee/abstractmap.vala |   81 --------------------------------------------------
 gee/map.vala         |   46 ++++++++++++++++++++++------
 gee/treemap.vala     |    2 +-
 tests/testmap.vala   |    5 ---
 4 files changed, 37 insertions(+), 97 deletions(-)
---
diff --git a/gee/abstractmap.vala b/gee/abstractmap.vala
index e281f49..5d96ffb 100644
--- a/gee/abstractmap.vala
+++ b/gee/abstractmap.vala
@@ -35,13 +35,6 @@ public abstract class Gee.AbstractMap<K,V> : Object, Traversable<Map.Entry<K,V>>
 	 * { inheritDoc}
 	 */
 	public abstract int size { get; }
-
-	/**
-	 * { inheritDoc}
-	 */
-	public virtual bool is_empty {
-		get { return size == 0; }
-	}
 	
 	/**
 	 * { inheritDoc}
@@ -71,13 +64,6 @@ public abstract class Gee.AbstractMap<K,V> : Object, Traversable<Map.Entry<K,V>>
 	/**
 	 * { inheritDoc}
 	 */
-	public bool contains (K key) {
-		return has_key (key);
-	}
-
-	/**
-	 * { inheritDoc}
-	 */
 	public abstract bool has (K key, V value);
 
 	/**
@@ -103,61 +89,8 @@ public abstract class Gee.AbstractMap<K,V> : Object, Traversable<Map.Entry<K,V>>
 	/**
 	 * { inheritDoc}
 	 */
-	public bool remove (K key, out V? value = null) {
-		return unset (key, out value);
-	}
-
-	/**
-	 * { inheritDoc}
-	 */
 	public abstract void clear ();
 
-	/**
-	 * { inheritDoc}
-	 */
-	public virtual void set_all (Map<K,V> map) {
-		foreach (Map.Entry<K,V> entry in map.entries) {
-			set (entry.key, entry.value);
-		}
-	}
-
-	/**
-	 * { inheritDoc}
-	 */
-	public virtual bool unset_all (Map<K,V> map) {
-		bool changed = false;
-		foreach (K key in map.keys) {
-			changed = changed | unset (key);
-		}
-		return changed;
-	}
-
-	/**
-	 * { inheritDoc}
-	 */
-	public bool remove_all (Map<K,V> map) {
-		return unset_all (map);
-	}
-
-	/**
-	 * { inheritDoc}
-	 */
-	public virtual bool has_all (Map<K,V> map) {
-		foreach (Map.Entry<K,V> entry in map.entries) {
-			if (!has (entry.key, entry.value)) {
-				return false;
-			}
-		}
-		return true;
-	}
-
-	/**
-	 * { inheritDoc}
-	 */
-	public bool contains_all (Map<K,V> map) {
-		return has_all (map);
-	}
-
 	private weak Map<K,V> _read_only_view;
 
 	/**
@@ -178,20 +111,6 @@ public abstract class Gee.AbstractMap<K,V> : Object, Traversable<Map.Entry<K,V>>
 	/**
 	 * { inheritDoc}
 	 */
-	public Type key_type {
-		get { return typeof (K); }
-	}
-
-	/**
-	 * { inheritDoc}
-	 */
-	public Type value_type {
-		get { return typeof (V); }
-	}
-
-	/**
-	 * { inheritDoc}
-	 */
 	public Type element_type {
 		get { return typeof (Map.Entry<K,V>); }
 	}
diff --git a/gee/map.vala b/gee/map.vala
index 3c85622..3770e9e 100644
--- a/gee/map.vala
+++ b/gee/map.vala
@@ -23,6 +23,7 @@
 /**
  * An object that maps keys to values.
  */
+[GenericAccessors]
 public interface Gee.Map<K,V> : Object, Iterable<Map.Entry<K,V>> {
 	/**
 	 * The number of items in this map.
@@ -32,7 +33,7 @@ public interface Gee.Map<K,V> : Object, Iterable<Map.Entry<K,V>> {
 	/**
 	 * Specifies whether this map is empty.
 	 */
-	public abstract bool is_empty { get; }
+	public virtual bool is_empty { get { return size == 0; } }
 	
 	/**
 	 * Specifies whether this collection can change - i.e. wheather { link set},
@@ -89,7 +90,9 @@ public interface Gee.Map<K,V> : Object, Iterable<Map.Entry<K,V>> {
 	 * @deprecated Use { link has_key} method instead.
 	 */
 	[Deprecated]
-	public abstract bool contains (K key);
+	public bool contains (K key) {
+		return has_key(key);
+	}
 
 	/**
 	 * Determines whether this map has the specified key/value entry.
@@ -140,7 +143,9 @@ public interface Gee.Map<K,V> : Object, Iterable<Map.Entry<K,V>> {
 	 * @deprecated Use { link unset} method instead.
 	 */
 	[Deprecated]
-	public abstract bool remove (K key, out V? value = null);
+	public bool remove (K key, out V? value = null) {
+		return unset (key, out value);
+	}
 
 	/**
 	 * Removes all items from this collection. Must not be called on
@@ -160,7 +165,11 @@ public interface Gee.Map<K,V> : Object, Iterable<Map.Entry<K,V>> {
 	 *
 	 * @param map the map which items are inserted to this map
 	 */
-	public abstract void set_all (Map<K,V> map);
+	public virtual void set_all (Map<K,V> map) {
+		foreach (Map.Entry<K,V> entry in map.entries) {
+			set (entry.key, entry.value);
+		}
+	}
 
 	/**
 	 * Removes all items from this map that are common to the input map
@@ -168,7 +177,13 @@ public interface Gee.Map<K,V> : Object, Iterable<Map.Entry<K,V>> {
 	 *
 	 * @param map the map which common items are deleted from this map
 	 */
-	public abstract bool unset_all (Map<K,V> map);
+	public virtual bool unset_all (Map<K,V> map) {
+		bool changed = false;
+		foreach (K key in map.keys) {
+			changed = changed | unset (key);
+		}
+		return changed;	
+	}
 
 	/**
 	 * Removes all items from this map that are common to the input map
@@ -179,14 +194,23 @@ public interface Gee.Map<K,V> : Object, Iterable<Map.Entry<K,V>> {
 	 * @deprecated Use { link unset_all} method instead.
 	 */
 	[Deprecated]
-	public abstract bool remove_all (Map<K,V> map);
+	public bool remove_all (Map<K,V> map) {
+		return unset_all (map);
+	}
 
 	/**
 	 * Returns ``true`` it this map contains all items as the input map.
 	 *
 	 * @param map the map which items will be compared with this map
 	 */
-	public abstract bool has_all (Map<K,V> map);
+	public virtual bool has_all (Map<K,V> map) {
+		foreach (Map.Entry<K,V> entry in map.entries) {
+			if (!has (entry.key, entry.value)) {
+				return false;
+			}
+		}
+		return true;
+	}
 
 	/**
 	 * Returns ``true`` it this map contains all items as the input map.
@@ -196,7 +220,9 @@ public interface Gee.Map<K,V> : Object, Iterable<Map.Entry<K,V>> {
 	 * @deprecated Use { link has_all} method instead.
 	 */
 	[Deprecated]
-	public abstract bool contains_all (Map<K,V> map);
+	public bool contains_all (Map<K,V> map) {
+		return has_all (map);
+	}
 
 	/**
 	 * The read-only view this map.
@@ -206,12 +232,12 @@ public interface Gee.Map<K,V> : Object, Iterable<Map.Entry<K,V>> {
 	/**
 	 * The type of the keys in this map.
 	 */
-	public abstract Type key_type { get; }
+	public Type key_type { get { return typeof(K); } }
 
 	/**
 	 * The type of the values in this map.
 	 */
-	public abstract Type value_type { get; }
+	public Type value_type { get { return typeof(V); } }
 
 	/**
 	 * Returns an immutable empty map.
diff --git a/gee/treemap.vala b/gee/treemap.vala
index 7e718cf..a5bda43 100644
--- a/gee/treemap.vala
+++ b/gee/treemap.vala
@@ -747,7 +747,7 @@ public class Gee.TreeMap<K,V> : Gee.AbstractBidirSortedMap<K,V> {
 
 	private class SubMap<K,V> : AbstractBidirSortedMap<K,V> {
 		public override int size { get { return keys.size; } }
-		public override bool is_empty { get { return keys.is_empty; } }
+		public bool is_empty { get { return keys.is_empty; } }
 
 		public SubMap (TreeMap<K,V> map, Range<K,V> range) {
 			this.map = map;
diff --git a/tests/testmap.vala b/tests/testmap.vala
index 009f091..4507763 100644
--- a/tests/testmap.vala
+++ b/tests/testmap.vala
@@ -519,11 +519,6 @@ public abstract class MapTests : Gee.TestCase {
 		assert (test_map != null);
 		Value value;
 
-		value = Value (typeof (bool));
-		test_map.get_property ("is-empty", ref value);
-		assert (value.get_boolean () == test_map.is_empty);
-		value.unset ();
-
 		value = Value (typeof (int));
 		test_map.get_property ("size", ref value);
 		assert (value.get_int () == test_map.size);



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