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.OrderedBidiMap;
23 import org.apache.commons.collections4.OrderedMapIterator;
24 import org.apache.commons.collections4.Unmodifiable;
25 import org.apache.commons.collections4.iterators.UnmodifiableOrderedMapIterator;
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 UnmodifiableOrderedBidiMap<K, V>
40 extends AbstractOrderedBidiMapDecorator<K, V> implements Unmodifiable {
41
42
43
44
45
46
47
48
49
50
51
52
53
54 public static <K, V> OrderedBidiMap<K, V> unmodifiableOrderedBidiMap(
55 final OrderedBidiMap<? extends K, ? extends V> map) {
56 if (map instanceof Unmodifiable) {
57 @SuppressWarnings("unchecked")
58 final OrderedBidiMap<K, V> tmpMap = (OrderedBidiMap<K, V>) map;
59 return tmpMap;
60 }
61 return new UnmodifiableOrderedBidiMap<>(map);
62 }
63
64
65 private UnmodifiableOrderedBidiMap<V, K> inverse;
66
67
68
69
70
71
72
73 @SuppressWarnings("unchecked")
74 private UnmodifiableOrderedBidiMap(final OrderedBidiMap<? extends K, ? extends V> map) {
75 super((OrderedBidiMap<K, V>) map);
76 }
77
78 @Override
79 public void clear() {
80 throw new UnsupportedOperationException();
81 }
82
83 @Override
84 public Set<Map.Entry<K, V>> entrySet() {
85 final Set<Map.Entry<K, V>> set = super.entrySet();
86 return UnmodifiableEntrySet.unmodifiableEntrySet(set);
87 }
88
89 @Override
90 public OrderedBidiMap<V, K> inverseBidiMap() {
91 return inverseOrderedBidiMap();
92 }
93
94
95
96
97
98
99 public OrderedBidiMap<V, K> inverseOrderedBidiMap() {
100 if (inverse == null) {
101 inverse = new UnmodifiableOrderedBidiMap<>(decorated().inverseBidiMap());
102 inverse.inverse = this;
103 }
104 return inverse;
105 }
106
107 @Override
108 public Set<K> keySet() {
109 final Set<K> set = super.keySet();
110 return UnmodifiableSet.unmodifiableSet(set);
111 }
112
113 @Override
114 public OrderedMapIterator<K, V> mapIterator() {
115 final OrderedMapIterator<K, V> it = decorated().mapIterator();
116 return UnmodifiableOrderedMapIterator.unmodifiableOrderedMapIterator(it);
117 }
118
119 @Override
120 public V put(final K key, final V value) {
121 throw new UnsupportedOperationException();
122 }
123
124 @Override
125 public void putAll(final Map<? extends K, ? extends V> mapToCopy) {
126 throw new UnsupportedOperationException();
127 }
128
129 @Override
130 public V remove(final Object key) {
131 throw new UnsupportedOperationException();
132 }
133
134 @Override
135 public K removeValue(final Object value) {
136 throw new UnsupportedOperationException();
137 }
138
139 @Override
140 public Set<V> values() {
141 final Set<V> set = super.values();
142 return UnmodifiableSet.unmodifiableSet(set);
143 }
144
145 }