/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. * This library is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12. * Lesser General Public License for more details.
  13. * You should have received a copy of the GNU Lesser General Public
  14. * License along with this library; if not, write to the Free Software
  15. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  16. *
  17. * Author:
  18. * J?rg Billeter <j@bitron.ch>
  19. */
  20. using GLib;
  21. /**
  22. * Represents a read-only collection of key/value pairs.
  23. */
  24. public class Gee.ReadOnlyMap<K,V> : Object, Map<K,V> {
  25. public int size {
  26. get { return _map.size; }
  27. }
  28. public Map<K,V> map {
  29. set { _map = value; }
  30. }
  31. private Map<K,V> _map;
  32. public ReadOnlyMap (Map<K,V>? map = null) {
  33. this.map = map;
  34. }
  35. public Set<K> get_keys () {
  36. if (_map == null) {
  37. return new ReadOnlySet<K> ();
  38. }
  39. return _map.get_keys ();
  40. }
  41. public Collection<V> get_values () {
  42. if (_map == null) {
  43. return new ReadOnlyCollection<V> ();
  44. }
  45. return _map.get_values ();
  46. }
  47. public bool contains (K key) {
  48. if (_map == null) {
  49. return false;
  50. }
  51. return _map.contains (key);
  52. }
  53. public weak V? get (K key) {
  54. if (_map == null) {
  55. return null;
  56. }
  57. return _map.get (key);
  58. }
  59. public void set (K key, V value) {
  60. assert_not_reached ();
  61. }
  62. public bool remove (K key) {
  63. assert_not_reached ();
  64. }
  65. public void clear () {
  66. assert_not_reached ();
  67. }
  68. }