PageRenderTime 25ms CodeModel.GetById 17ms app.highlight 3ms RepoModel.GetById 1ms app.codeStats 0ms

/gee/gee/readonlymap.vala

http://libgdom3.googlecode.com/
Vala | 87 lines | 46 code | 17 blank | 24 comment | 8 complexity | 8cd548afdb6e3615db45477ad0aecfa6 MD5 | raw file
 1/* readonlymap.vala
 2 *
 3 * Copyright (C) 2007-2008  J?rg Billeter
 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 * 	J?rg Billeter <j@bitron.ch>
21 */
22
23using GLib;
24
25/**
26 * Represents a read-only collection of key/value pairs.
27 */
28public class Gee.ReadOnlyMap<K,V> : Object, Map<K,V> {
29	public int size {
30		get { return _map.size; }
31	}
32
33	public Map<K,V> map {
34		set { _map = value; }
35	}
36
37	private Map<K,V> _map;
38
39	public ReadOnlyMap (Map<K,V>? map = null) {
40		this.map = map;
41	}
42
43	public Set<K> get_keys () {
44		if (_map == null) {
45			return new ReadOnlySet<K> ();
46		}
47
48		return _map.get_keys ();
49	}
50
51	public Collection<V> get_values () {
52		if (_map == null) {
53			return new ReadOnlyCollection<V> ();
54		}
55
56		return _map.get_values ();
57	}
58
59	public bool contains (K key) {
60		if (_map == null) {
61			return false;
62		}
63
64		return _map.contains (key);
65	}
66
67	public weak V? get (K key) {
68		if (_map == null) {
69			return null;
70		}
71
72		return _map.get (key);
73	}
74
75	public void set (K key, V value) {
76		assert_not_reached ();
77	}
78
79	public bool remove (K key) {
80		assert_not_reached ();
81	}
82
83	public void clear () {
84		assert_not_reached ();
85	}
86}
87