1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.commons.collections4.bidimap;
18
19 import java.util.Map;
20 import java.util.Set;
21
22 import org.apache.commons.collections4.BidiMap;
23 import org.apache.commons.collections4.MapIterator;
24 import org.apache.commons.collections4.Unmodifiable;
25 import org.apache.commons.collections4.iterators.UnmodifiableMapIterator;
26 import org.apache.commons.collections4.map.UnmodifiableEntrySet;
27 import org.apache.commons.collections4.set.UnmodifiableSet;
28
29
30
31
32
33
34
35
36
37
38
39 public final class UnmodifiableBidiMap<K, V>
40 extends AbstractBidiMapDecorator<K, V> implements Unmodifiable {
41
42
43
44
45
46
47
48
49
50
51
52
53
54 public static <K, V> BidiMap<K, V> unmodifiableBidiMap(final BidiMap<? extends K, ? extends V> map) {
55 if (map instanceof Unmodifiable) {
56 @SuppressWarnings("unchecked")
57 final BidiMap<K, V> tmpMap = (BidiMap<K, V>) map;
58 return tmpMap;
59 }
60 return new UnmodifiableBidiMap<>(map);
61 }
62
63
64 private UnmodifiableBidiMap<V, K> inverse;
65
66
67
68
69
70
71
72 @SuppressWarnings("unchecked")
73 private UnmodifiableBidiMap(final BidiMap<? extends K, ? extends V> map) {
74 super((BidiMap<K, V>) map);
75 }
76
77 @Override
78 public void clear() {
79 throw new UnsupportedOperationException();
80 }
81
82 @Override
83 public Set<Map.Entry<K, V>> entrySet() {
84 final Set<Map.Entry<K, V>> set = super.entrySet();
85 return UnmodifiableEntrySet.unmodifiableEntrySet(set);
86 }
87
88 @Override
89 public synchronized BidiMap<V, K> inverseBidiMap() {
90 if (inverse == null) {
91 inverse = new UnmodifiableBidiMap<>(decorated().inverseBidiMap());
92 inverse.inverse = this;
93 }
94 return inverse;
95 }
96
97 @Override
98 public Set<K> keySet() {
99 final Set<K> set = super.keySet();
100 return UnmodifiableSet.unmodifiableSet(set);
101 }
102
103 @Override
104 public MapIterator<K, V> mapIterator() {
105 final MapIterator<K, V> it = decorated().mapIterator();
106 return UnmodifiableMapIterator.unmodifiableMapIterator(it);
107 }
108
109 @Override
110 public V put(final K key, final V value) {
111 throw new UnsupportedOperationException();
112 }
113
114 @Override
115 public void putAll(final Map<? extends K, ? extends V> mapToCopy) {
116 throw new UnsupportedOperationException();
117 }
118
119 @Override
120 public V remove(final Object key) {
121 throw new UnsupportedOperationException();
122 }
123
124 @Override
125 public K removeValue(final Object value) {
126 throw new UnsupportedOperationException();
127 }
128
129 @Override
130 public Set<V> values() {
131 final Set<V> set = super.values();
132 return UnmodifiableSet.unmodifiableSet(set);
133 }
134
135 }