diff options
Diffstat (limited to 'gee/map.vala')
-rw-r--r-- | gee/map.vala | 73 |
1 files changed, 51 insertions, 22 deletions
diff --git a/gee/map.vala b/gee/map.vala index a2b9a3b..e8e3138 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,13 @@ 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}, + * {@link remove} etc. are legal operations. + */ + public abstract bool read_only { get; } /** * The read-only view of the keys of this map. @@ -62,6 +69,11 @@ public interface Gee.Map<K,V> : Object, Iterable<Map.Entry<K,V>> { * The value of this entry. */ public abstract V value { get; set; } + + /** + * ``true`` if the setting value is permitted. + */ + public abstract bool read_only { get; } } /** @@ -79,11 +91,11 @@ public interface Gee.Map<K,V> : Object, Iterable<Map.Entry<K,V>> { * @param key the key to locate in the map * * @return ``true`` if key is found, ``false`` otherwise - * - * @deprecated Use {@link has_key} method instead. */ - [Deprecated] - public abstract bool contains (K key); + [Deprecated (replacement = "Map.has_key")] + public bool contains (K key) { + return has_key(key); + } /** * Determines whether this map has the specified key/value entry. @@ -130,11 +142,11 @@ public interface Gee.Map<K,V> : Object, Iterable<Map.Entry<K,V>> { * @param value the receiver variable for the removed value * * @return ``true`` if the map has been changed, ``false`` otherwise - * - * @deprecated Use {@link unset} method instead. */ - [Deprecated] - public abstract bool remove (K key, out V? value = null); + [Deprecated (replacement = "Map.unset")] + 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 @@ -154,7 +166,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 @@ -162,35 +178,48 @@ 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 * and this map. * * @param map the map which common items are deleted from this map - * - * @deprecated Use {@link unset_all} method instead. */ - [Deprecated] - public abstract bool remove_all (Map<K,V> map); + [Deprecated (replacement = "Map.unset_all")] + 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. * * @param map the map which items will be compared with this map - * - * @deprecated Use {@link has_all} method instead. */ - [Deprecated] - public abstract bool contains_all (Map<K,V> map); + [Deprecated (replacement = "Map.has_all")] + public bool contains_all (Map<K,V> map) { + return has_all (map); + } /** * The read-only view this map. @@ -200,12 +229,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. |