Update Changelog
[profile/ivi/libgee.git] / gee / readonlymultimap.vala
1 /* readonlymultimap.vala
2  *
3  * Copyright (C) 2013  Maciej Piechotka
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 of the License, or (at your option) any later version.
9
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  * Lesser General Public License for more details.
14
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this library; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301  USA
18  *
19  * Author:
20  *      Maciej Piechotka <uzytkownik2@gmail.com>
21  */
22
23 using GLib;
24
25 /**
26  * Read-only view for {@link MultiMap} collections.
27  *
28  * This class decorates any class which implements the {@link MultiMap}
29  * interface by making it read only. Any method which normally modify data will
30  * throw an error.
31  *
32  * @see MultiMap
33  */
34 internal class Gee.ReadOnlyMultiMap<K, V> : Object, MultiMap<K, V> {
35         /**
36          * Constructs a read-only multi-set that mirrors the content of the specified
37          * list.
38          *
39          * @param multiset the multi-set to decorate.
40          */
41         public ReadOnlyMultiMap (MultiMap<K, V> multimap) {
42                 this._multimap = multimap;
43         }
44
45         /**
46          * {@inheritDoc}
47          */
48         public int size { get { return _multimap.size; } }
49
50         /**
51          * {@inheritDoc}
52          */
53         public bool read_only { get { return true; } }
54
55         /**
56          * {@inheritDoc}
57          */
58         public Set<K> get_keys () {
59                 return _multimap.get_keys ();
60         }
61
62         /**
63          * {@inheritDoc}
64          */
65         public MultiSet<K> get_all_keys () {
66                 return _multimap.get_all_keys ();
67         }
68
69         /**
70          * {@inheritDoc}
71          */
72         public Collection<V> get_values () {
73                 return _multimap.get_values ();
74         }
75
76         /**
77          * {@inheritDoc}
78          */
79         public bool contains (K key) {
80                 return _multimap.contains (key);
81         }
82
83         /**
84          * {@inheritDoc}
85          */
86         public new Collection<V> get (K key) {
87                 return _multimap.get (key);
88         }
89
90         /**
91          * {@inheritDoc}
92          */
93         public new void set (K key, V value) {
94                 assert_not_reached ();
95         }
96
97         /**
98          * {@inheritDoc}
99          */
100         public bool remove (K key, V value) {
101                 assert_not_reached ();
102         }
103
104         /**
105          * {@inheritDoc}
106          */
107         public bool remove_all (K key) {
108                 assert_not_reached ();
109         }
110
111         /**
112          * {@inheritDoc}
113          */
114         public void clear () {
115                 assert_not_reached ();
116         }
117
118         /**
119          * {@inheritDoc}
120          */
121         public MapIterator<K, V> map_iterator () {
122                 return new ReadOnlyMap.MapIterator<K, V> (_multimap.map_iterator ());
123         }
124
125         /**
126          * {@inheritDoc}
127          */
128         public virtual new MultiMap<K, V> read_only_view { owned get { return this; } }
129
130         private MultiMap<K, V> _multimap;
131 }