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 @Override
80 public void clear() {
81 throw new UnsupportedOperationException();
82 }
83
84 @Override
85 public Set<Map.Entry<K, V>> entrySet() {
86 final Set<Map.Entry<K, V>> set = super.entrySet();
87 return UnmodifiableEntrySet.unmodifiableEntrySet(set);
88 }
89
90 @Override
91 public SortedMap<K, V> headMap(final K toKey) {
92 final SortedMap<K, V> sm = decorated().headMap(toKey);
93 return UnmodifiableSortedMap.unmodifiableSortedMap(sm);
94 }
95
96 @Override
97 public SortedBidiMap<V, K> inverseBidiMap() {
98 if (inverse == null) {
99 inverse = new UnmodifiableSortedBidiMap<>(decorated().inverseBidiMap());
100 inverse.inverse = this;
101 }
102 return inverse;
103 }
104
105 @Override
106 public Set<K> keySet() {
107 final Set<K> set = super.keySet();
108 return UnmodifiableSet.unmodifiableSet(set);
109 }
110
111 @Override
112 public OrderedMapIterator<K, V> mapIterator() {
113 final OrderedMapIterator<K, V> it = decorated().mapIterator();
114 return UnmodifiableOrderedMapIterator.unmodifiableOrderedMapIterator(it);
115 }
116
117 @Override
118 public V put(final K key, final V value) {
119 throw new UnsupportedOperationException();
120 }
121
122 @Override
123 public void putAll(final Map<? extends K, ? extends V> mapToCopy) {
124 throw new UnsupportedOperationException();
125 }
126
127 @Override
128 public V remove(final Object key) {
129 throw new UnsupportedOperationException();
130 }
131
132 @Override
133 public K removeValue(final Object value) {
134 throw new UnsupportedOperationException();
135 }
136
137 @Override
138 public SortedMap<K, V> subMap(final K fromKey, final K toKey) {
139 final SortedMap<K, V> sm = decorated().subMap(fromKey, toKey);
140 return UnmodifiableSortedMap.unmodifiableSortedMap(sm);
141 }
142
143 @Override
144 public SortedMap<K, V> tailMap(final K fromKey) {
145 final SortedMap<K, V> sm = decorated().tailMap(fromKey);
146 return UnmodifiableSortedMap.unmodifiableSortedMap(sm);
147 }
148
149 @Override
150 public Set<V> values() {
151 final Set<V> set = super.values();
152 return UnmodifiableSet.unmodifiableSet(set);
153 }
154
155 }