1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.commons.collections4.multimap;
18
19 import java.util.Collection;
20 import java.util.Map;
21 import java.util.Map.Entry;
22 import java.util.Set;
23
24 import org.apache.commons.collections4.MapIterator;
25 import org.apache.commons.collections4.MultiSet;
26 import org.apache.commons.collections4.MultiValuedMap;
27 import org.apache.commons.collections4.Unmodifiable;
28 import org.apache.commons.collections4.collection.UnmodifiableCollection;
29 import org.apache.commons.collections4.iterators.UnmodifiableMapIterator;
30 import org.apache.commons.collections4.map.UnmodifiableMap;
31 import org.apache.commons.collections4.multiset.UnmodifiableMultiSet;
32 import org.apache.commons.collections4.set.UnmodifiableSet;
33
34
35
36
37
38
39
40
41
42
43
44 public final class UnmodifiableMultiValuedMap<K, V>
45 extends AbstractMultiValuedMapDecorator<K, V> implements Unmodifiable {
46
47
48 private static final long serialVersionUID = 20150612L;
49
50
51
52
53
54
55
56
57
58
59
60
61
62 @SuppressWarnings("unchecked")
63 public static <K, V> UnmodifiableMultiValuedMap<K, V> unmodifiableMultiValuedMap(
64 final MultiValuedMap<? extends K, ? extends V> map) {
65 if (map instanceof Unmodifiable) {
66 return (UnmodifiableMultiValuedMap<K, V>) map;
67 }
68 return new UnmodifiableMultiValuedMap<>(map);
69 }
70
71
72
73
74
75
76
77 @SuppressWarnings("unchecked")
78 private UnmodifiableMultiValuedMap(final MultiValuedMap<? extends K, ? extends V> map) {
79 super((MultiValuedMap<K, V>) map);
80 }
81
82 @Override
83 public Map<K, Collection<V>> asMap() {
84 return UnmodifiableMap.unmodifiableMap(decorated().asMap());
85 }
86
87 @Override
88 public void clear() {
89 throw new UnsupportedOperationException();
90 }
91
92 @Override
93 public Collection<Entry<K, V>> entries() {
94 return UnmodifiableCollection.unmodifiableCollection(decorated().entries());
95 }
96
97 @Override
98 public Collection<V> get(final K key) {
99 return UnmodifiableCollection.unmodifiableCollection(decorated().get(key));
100 }
101
102 @Override
103 public MultiSet<K> keys() {
104 return UnmodifiableMultiSet.unmodifiableMultiSet(decorated().keys());
105 }
106
107 @Override
108 public Set<K> keySet() {
109 return UnmodifiableSet.unmodifiableSet(decorated().keySet());
110 }
111
112 @Override
113 public MapIterator<K, V> mapIterator() {
114 return UnmodifiableMapIterator.unmodifiableMapIterator(decorated().mapIterator());
115 }
116
117 @Override
118 public boolean put(final K key, final V value) {
119 throw new UnsupportedOperationException();
120 }
121
122 @Override
123 public boolean putAll(final K key, final Iterable<? extends V> values) {
124 throw new UnsupportedOperationException();
125 }
126
127 @Override
128 public boolean putAll(final Map<? extends K, ? extends V> map) {
129 throw new UnsupportedOperationException();
130 }
131
132 @Override
133 public boolean putAll(final MultiValuedMap<? extends K, ? extends V> map) {
134 throw new UnsupportedOperationException();
135 }
136
137 @Override
138 public Collection<V> remove(final Object key) {
139 throw new UnsupportedOperationException();
140 }
141
142 @Override
143 public boolean removeMapping(final Object key, final Object item) {
144 throw new UnsupportedOperationException();
145 }
146
147 @Override
148 public Collection<V> values() {
149 return UnmodifiableCollection.unmodifiableCollection(decorated().values());
150 }
151
152 }