1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 package net.sf.webmancer.util.immutable;
22
23 import java.util.Collection;
24 import java.util.HashSet;
25 import java.util.Map;
26 import java.util.Set;
27
28
29
30
31
32
33 public final class ImmutableMap<K, V> implements Map<K, V> {
34
35
36
37 private Map<? extends K, ? extends V> map;
38
39
40
41
42 public ImmutableMap(final Map<? extends K, ? extends V> map) {
43 super();
44 this.map = map;
45 }
46
47
48
49
50 public boolean containsKey(final Object key) {
51 return this.map.containsKey(key);
52 }
53
54
55
56
57 public boolean containsValue(final Object value) {
58 return this.map.containsValue(value);
59 }
60
61
62
63
64 @SuppressWarnings("unchecked")
65 public Set<Map.Entry<K, V>> entrySet() {
66 Set set = this.map.entrySet();
67 Set<Map.Entry<K, V>> result = new HashSet<Map.Entry<K, V>>(set.size());
68 for (Object object : set) {
69 Map.Entry<K, V> entry = new ImmutableMapEntry((Map.Entry<K, V>) object);
70 result.add(entry);
71 }
72 return result;
73 }
74
75
76
77
78 @Override
79 public boolean equals(final Object o) {
80 return this.map.equals(o);
81 }
82
83
84
85
86 public V get(final Object key) {
87 return this.map.get(key);
88 }
89
90
91
92
93 @Override
94 public int hashCode() {
95 return this.map.hashCode();
96 }
97
98
99
100
101 public boolean isEmpty() {
102 return this.map.isEmpty();
103 }
104
105
106
107
108 public Set<K> keySet() {
109 return new ImmutableSet<K>(this.map.keySet());
110 }
111
112
113
114
115 public int size() {
116 return this.map.size();
117 }
118
119
120
121
122 public Collection<V> values() {
123 return new ImmutableCollection<V>(this.map.values());
124 }
125
126
127
128
129 public V put(final K key, final V value) {
130 throw new UnsupportedOperationException("ImmutableMap.put");
131 }
132
133
134
135
136 public V remove(final Object key) {
137 throw new UnsupportedOperationException("ImmutableMap.remove");
138 }
139
140
141
142
143 public void putAll(final Map<? extends K, ? extends V> t) {
144 throw new UnsupportedOperationException("ImmutableMap.putAll");
145 }
146
147
148
149
150 public void clear() {
151 throw new UnsupportedOperationException("ImmutableMap.clear");
152 }
153
154 }