1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.commons.collections4.iterators;
18
19 import java.util.Objects;
20
21 import org.apache.commons.collections4.MapIterator;
22 import org.apache.commons.collections4.Unmodifiable;
23
24
25
26
27
28
29
30
31
32
33
34 public final class UnmodifiableMapIterator<K, V> implements MapIterator<K, V>, Unmodifiable {
35
36
37
38
39
40
41
42
43
44
45 public static <K, V> MapIterator<K, V> unmodifiableMapIterator(
46 final MapIterator<? extends K, ? extends V> iterator) {
47 Objects.requireNonNull(iterator, "iterator");
48 if (iterator instanceof Unmodifiable) {
49 @SuppressWarnings("unchecked")
50 final MapIterator<K, V> tmpIterator = (MapIterator<K, V>) iterator;
51 return tmpIterator;
52 }
53 return new UnmodifiableMapIterator<>(iterator);
54 }
55
56
57 private final MapIterator<? extends K, ? extends V> iterator;
58
59
60
61
62
63
64 private UnmodifiableMapIterator(final MapIterator<? extends K, ? extends V> iterator) {
65 this.iterator = iterator;
66 }
67
68 @Override
69 public K getKey() {
70 return iterator.getKey();
71 }
72
73 @Override
74 public V getValue() {
75 return iterator.getValue();
76 }
77
78 @Override
79 public boolean hasNext() {
80 return iterator.hasNext();
81 }
82
83 @Override
84 public K next() {
85 return iterator.next();
86 }
87
88 @Override
89 public void remove() {
90 throw new UnsupportedOperationException("remove() is not supported");
91 }
92
93 @Override
94 public V setValue(final V value) {
95 throw new UnsupportedOperationException("setValue() is not supported");
96 }
97
98 }