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 import java.util.SortedMap;
22
23 import org.apache.commons.collections4.OrderedMapIterator;
24 import org.apache.commons.collections4.SortedBidiMap;
25 import org.apache.commons.collections4.Unmodifiable;
26 import org.apache.commons.collections4.iterators.UnmodifiableOrderedMapIterator;
27 import org.apache.commons.collections4.map.UnmodifiableEntrySet;
28 import org.apache.commons.collections4.map.UnmodifiableSortedMap;
29 import org.apache.commons.collections4.set.UnmodifiableSet;
30
31
32
33
34
35
36
37
38
39
40
41 public final class UnmodifiableSortedBidiMap<K, V>
42 extends AbstractSortedBidiMapDecorator<K, V> implements Unmodifiable {
43
44
45
46
47
48
49
50
51
52
53
54
55
56 public static <K, V> SortedBidiMap<K, V> unmodifiableSortedBidiMap(final SortedBidiMap<K, ? extends V> map) {
57 if (map instanceof Unmodifiable) {
58 @SuppressWarnings("unchecked")
59 final SortedBidiMap<K, V> tmpMap = (SortedBidiMap<K, V>) map;
60 return tmpMap;
61 }
62 return new UnmodifiableSortedBidiMap<>(map);
63 }
64
65
66 private UnmodifiableSortedBidiMap<V, K> inverse;
67
68
69
70
71
72
73
74 @SuppressWarnings("unchecked")
75 private UnmodifiableSortedBidiMap(final SortedBidiMap<K, ? extends V> map) {
76 super((SortedBidiMap<K, V>) map);
77 }
78
79
80
81
82
83
84 @Override
85 public void clear() {
86 throw new UnsupportedOperationException();
87 }
88
89 @Override
90 public Set<Map.Entry<K, V>> entrySet() {
91 final Set<Map.Entry<K, V>> set = super.entrySet();
92 return UnmodifiableEntrySet.unmodifiableEntrySet(set);
93 }
94
95 @Override
96 public SortedMap<K, V> headMap(final K toKey) {
97 final SortedMap<K, V> sm = decorated().headMap(toKey);
98 return UnmodifiableSortedMap.unmodifiableSortedMap(sm);
99 }
100
101 @Override
102 public SortedBidiMap<V, K> inverseBidiMap() {
103 if (inverse == null) {
104 inverse = new UnmodifiableSortedBidiMap<>(decorated().inverseBidiMap());
105 inverse.inverse = this;
106 }
107 return inverse;
108 }
109
110 @Override
111 public Set<K> keySet() {
112 final Set<K> set = super.keySet();
113 return UnmodifiableSet.unmodifiableSet(set);
114 }
115
116 @Override
117 public OrderedMapIterator<K, V> mapIterator() {
118 final OrderedMapIterator<K, V> it = decorated().mapIterator();
119 return UnmodifiableOrderedMapIterator.unmodifiableOrderedMapIterator(it);
120 }
121
122
123
124
125
126
127
128
129 @Override
130 public V put(final K key, final V value) {
131 throw new UnsupportedOperationException();
132 }
133
134
135
136
137
138
139
140 @Override
141 public void putAll(final Map<? extends K, ? extends V> mapToCopy) {
142 throw new UnsupportedOperationException();
143 }
144
145
146
147
148
149
150
151 @Override
152 public V remove(final Object key) {
153 throw new UnsupportedOperationException();
154 }
155
156
157
158
159
160
161
162 @Override
163 public K removeValue(final Object value) {
164 throw new UnsupportedOperationException();
165 }
166
167 @Override
168 public SortedMap<K, V> subMap(final K fromKey, final K toKey) {
169 final SortedMap<K, V> sm = decorated().subMap(fromKey, toKey);
170 return UnmodifiableSortedMap.unmodifiableSortedMap(sm);
171 }
172
173 @Override
174 public SortedMap<K, V> tailMap(final K fromKey) {
175 final SortedMap<K, V> sm = decorated().tailMap(fromKey);
176 return UnmodifiableSortedMap.unmodifiableSortedMap(sm);
177 }
178
179 @Override
180 public Set<V> values() {
181 final Set<V> set = super.values();
182 return UnmodifiableSet.unmodifiableSet(set);
183 }
184
185 }