From e300c2a1ebd59362aefffa70a640a377aeadefc8 Mon Sep 17 00:00:00 2001 From: Maciej Piechotka Date: Sat, 18 Aug 2012 18:36:00 -0700 Subject: [PATCH] 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 : Object, Traversable> * {@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 : Object, Traversable> /** * {@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 : Object, Traversable> /** * {@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 map) { - foreach (Map.Entry entry in map.entries) { - set (entry.key, entry.value); - } - } - - /** - * {@inheritDoc} - */ - public virtual bool unset_all (Map map) { - bool changed = false; - foreach (K key in map.keys) { - changed = changed | unset (key); - } - return changed; - } - - /** - * {@inheritDoc} - */ - public bool remove_all (Map map) { - return unset_all (map); - } - - /** - * {@inheritDoc} - */ - public virtual bool has_all (Map map) { - foreach (Map.Entry entry in map.entries) { - if (!has (entry.key, entry.value)) { - return false; - } - } - return true; - } - - /** - * {@inheritDoc} - */ - public bool contains_all (Map map) { - return has_all (map); - } - private weak Map _read_only_view; /** @@ -178,20 +111,6 @@ public abstract class Gee.AbstractMap : Object, Traversable> /** * {@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); } } 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 : Object, Iterable> { /** * The number of items in this map. @@ -32,7 +33,7 @@ public interface Gee.Map : Object, Iterable> { /** * 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 : Object, Iterable> { * @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 : Object, Iterable> { * @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 : Object, Iterable> { * * @param map the map which items are inserted to this map */ - public abstract void set_all (Map map); + public virtual void set_all (Map map) { + foreach (Map.Entry 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 : Object, Iterable> { * * @param map the map which common items are deleted from this map */ - public abstract bool unset_all (Map map); + public virtual bool unset_all (Map 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 : Object, Iterable> { * @deprecated Use {@link unset_all} method instead. */ [Deprecated] - public abstract bool remove_all (Map map); + public bool remove_all (Map 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 map); + public virtual bool has_all (Map map) { + foreach (Map.Entry 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 : Object, Iterable> { * @deprecated Use {@link has_all} method instead. */ [Deprecated] - public abstract bool contains_all (Map map); + public bool contains_all (Map map) { + return has_all (map); + } /** * The read-only view this map. @@ -206,12 +232,12 @@ public interface Gee.Map : Object, Iterable> { /** * 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 : Gee.AbstractBidirSortedMap { private class SubMap : AbstractBidirSortedMap { 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 map, Range 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); -- 2.7.4