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.OrderedMapIterator;
22 import org.apache.commons.collections4.Unmodifiable;
23
24
25
26
27
28
29
30
31
32
33
34 public final class UnmodifiableOrderedMapIterator<K, V> implements OrderedMapIterator<K, V>,
35 Unmodifiable {
36
37
38
39
40
41
42
43
44
45
46 public static <K, V> OrderedMapIterator<K, V> unmodifiableOrderedMapIterator(
47 final OrderedMapIterator<K, ? extends V> iterator) {
48 Objects.requireNonNull(iterator, "iterator");
49 if (iterator instanceof Unmodifiable) {
50 @SuppressWarnings("unchecked")
51 final OrderedMapIterator<K, V> tmpIterator = (OrderedMapIterator<K, V>) iterator;
52 return tmpIterator;
53 }
54 return new UnmodifiableOrderedMapIterator<>(iterator);
55 }
56
57
58 private final OrderedMapIterator<? extends K, ? extends V> iterator;
59
60
61
62
63
64
65 private UnmodifiableOrderedMapIterator(final OrderedMapIterator<K, ? extends V> iterator) {
66 this.iterator = iterator;
67 }
68
69 @Override
70 public K getKey() {
71 return iterator.getKey();
72 }
73
74 @Override
75 public V getValue() {
76 return iterator.getValue();
77 }
78
79 @Override
80 public boolean hasNext() {
81 return iterator.hasNext();
82 }
83
84 @Override
85 public boolean hasPrevious() {
86 return iterator.hasPrevious();
87 }
88
89 @Override
90 public K next() {
91 return iterator.next();
92 }
93
94 @Override
95 public K previous() {
96 return iterator.previous();
97 }
98
99 @Override
100 public void remove() {
101 throw new UnsupportedOperationException("remove() is not supported");
102 }
103
104 @Override
105 public V setValue(final V value) {
106 throw new UnsupportedOperationException("setValue() is not supported");
107 }
108
109 }