1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.commons.collections.bidimap;
18
19 import java.util.Collection;
20 import java.util.Map;
21 import java.util.Set;
22 import java.util.SortedMap;
23
24 import org.apache.commons.collections.OrderedMapIterator;
25 import org.apache.commons.collections.SortedBidiMap;
26 import org.apache.commons.collections.Unmodifiable;
27 import org.apache.commons.collections.collection.UnmodifiableCollection;
28 import org.apache.commons.collections.iterators.UnmodifiableOrderedMapIterator;
29 import org.apache.commons.collections.map.UnmodifiableEntrySet;
30 import org.apache.commons.collections.map.UnmodifiableSortedMap;
31 import org.apache.commons.collections.set.UnmodifiableSet;
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 private UnmodifiableSortedBidiMap<V, K> inverse;
46
47
48
49
50
51
52
53
54
55
56
57
58 public static <K, V> SortedBidiMap<K, V> unmodifiableSortedBidiMap(final SortedBidiMap<K, V> map) {
59 if (map instanceof Unmodifiable) {
60 return map;
61 }
62 return new UnmodifiableSortedBidiMap<K, V>(map);
63 }
64
65
66
67
68
69
70
71
72 private UnmodifiableSortedBidiMap(final SortedBidiMap<K, V> map) {
73 super(map);
74 }
75
76
77 @Override
78 public void clear() {
79 throw new UnsupportedOperationException();
80 }
81
82 @Override
83 public V put(final K key, final V value) {
84 throw new UnsupportedOperationException();
85 }
86
87 @Override
88 public void putAll(final Map<? extends K, ? extends V> mapToCopy) {
89 throw new UnsupportedOperationException();
90 }
91
92 @Override
93 public V remove(final Object key) {
94 throw new UnsupportedOperationException();
95 }
96
97 @Override
98 public Set<Map.Entry<K, V>> entrySet() {
99 final Set<Map.Entry<K, V>> set = super.entrySet();
100 return UnmodifiableEntrySet.unmodifiableEntrySet(set);
101 }
102
103 @Override
104 public Set<K> keySet() {
105 final Set<K> set = super.keySet();
106 return UnmodifiableSet.unmodifiableSet(set);
107 }
108
109 @Override
110 public Collection<V> values() {
111 final Collection<V> coll = super.values();
112 return UnmodifiableCollection.unmodifiableCollection(coll);
113 }
114
115
116 @Override
117 public K removeValue(final Object value) {
118 throw new UnsupportedOperationException();
119 }
120
121
122 @Override
123 public OrderedMapIterator<K, V> mapIterator() {
124 final OrderedMapIterator<K, V> it = decorated().mapIterator();
125 return UnmodifiableOrderedMapIterator.unmodifiableOrderedMapIterator(it);
126 }
127
128
129 @Override
130 public SortedBidiMap<V, K> inverseBidiMap() {
131 if (inverse == null) {
132 inverse = new UnmodifiableSortedBidiMap<V, K>(decorated().inverseBidiMap());
133 inverse.inverse = this;
134 }
135 return inverse;
136 }
137
138 @Override
139 public SortedMap<K, V> subMap(final K fromKey, final K toKey) {
140 final SortedMap<K, V> sm = decorated().subMap(fromKey, toKey);
141 return UnmodifiableSortedMap.unmodifiableSortedMap(sm);
142 }
143
144 @Override
145 public SortedMap<K, V> headMap(final K toKey) {
146 final SortedMap<K, V> sm = decorated().headMap(toKey);
147 return UnmodifiableSortedMap.unmodifiableSortedMap(sm);
148 }
149
150 @Override
151 public SortedMap<K, V> tailMap(final K fromKey) {
152 final SortedMap<K, V> sm = decorated().tailMap(fromKey);
153 return UnmodifiableSortedMap.unmodifiableSortedMap(sm);
154 }
155
156 }