1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.commons.collections4.map;
18
19 import java.util.Iterator;
20 import java.util.Map;
21 import java.util.Set;
22
23 import org.apache.commons.collections4.MapIterator;
24 import org.apache.commons.collections4.ResettableIterator;
25
26
27
28
29
30
31
32
33
34 public class EntrySetToMapIteratorAdapter<K, V> implements MapIterator<K, V>, ResettableIterator<K> {
35
36
37 final Set<Map.Entry<K, V>> entrySet;
38
39
40 transient Iterator<Map.Entry<K, V>> iterator;
41
42
43 transient Map.Entry<K, V> entry;
44
45
46
47
48
49 public EntrySetToMapIteratorAdapter(final Set<Map.Entry<K, V>> entrySet) {
50 this.entrySet = entrySet;
51 reset();
52 }
53
54
55
56
57
58 protected synchronized Map.Entry<K, V> current() {
59 if (entry == null) {
60 throw new IllegalStateException();
61 }
62 return entry;
63 }
64
65
66
67
68 @Override
69 public K getKey() {
70 return current().getKey();
71 }
72
73
74
75
76 @Override
77 public V getValue() {
78 return current().getValue();
79 }
80
81
82
83
84 @Override
85 public boolean hasNext() {
86 return iterator.hasNext();
87 }
88
89
90
91
92 @Override
93 public K next() {
94 entry = iterator.next();
95 return getKey();
96 }
97
98
99
100
101 @Override
102 public void remove() {
103 iterator.remove();
104 entry = null;
105 }
106
107
108
109
110 @Override
111 public synchronized void reset() {
112 iterator = entrySet.iterator();
113 }
114
115
116
117
118 @Override
119 public V setValue(final V value) {
120 return current().setValue(value);
121 }
122 }