1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package uk.org.bryanray.testtoys.generator;
17
18 import java.util.ArrayList;
19 import java.util.Collection;
20 import java.util.HashSet;
21 import java.util.Iterator;
22 import java.util.Map;
23 import java.util.Set;
24
25 import uk.org.bryanray.testtoys.generator.sequencegenerators.SequenceGenerator;
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44 public class SequenceMapAdapter implements Map<String, String> {
45
46
47
48
49 private Map<String, SequenceGenerator> map;
50
51
52
53
54 public SequenceMapAdapter(Map<String, SequenceGenerator> sequenceMap) {
55 map = sequenceMap;
56 }
57
58
59
60
61 public void clear() {
62 map.clear();
63 }
64
65
66
67
68 public boolean containsKey(Object key) {
69 return map.containsKey(key);
70 }
71
72
73
74
75 public boolean containsValue(Object value) {
76 if (null != value) {
77 for (Iterator<SequenceGenerator> i = map.values().iterator(); i
78 .hasNext();) {
79 SequenceGenerator sequenceGenerator = i.next();
80 if (sequenceGenerator.value().equals(value)) {
81 return true;
82 }
83 }
84 }
85 return false;
86 }
87
88
89
90
91 public Set<Entry<String, String>> entrySet() {
92 Set<Entry<String, String>> set = new HashSet<Entry<String, String>>();
93 for (Iterator<Entry<String, SequenceGenerator>> i = map.entrySet()
94 .iterator(); i.hasNext();) {
95 Entry<String, SequenceGenerator> e = i.next();
96 set.add(new AdapterEntry(e.getKey(), e.getValue().value()));
97 }
98 return set;
99
100 }
101
102
103
104
105 public String get(Object key) {
106 return map.get(key).value();
107 }
108
109
110
111
112 public boolean isEmpty() {
113 return map.isEmpty();
114 }
115
116
117
118
119 public Set<String> keySet() {
120 return map.keySet();
121 }
122
123
124
125
126
127
128 public String put(String key, String value) {
129 throw new UnsupportedOperationException();
130 }
131
132
133
134
135
136
137 public void putAll(Map<? extends String, ? extends String> t) {
138 throw new UnsupportedOperationException();
139 }
140
141
142
143
144 public String remove(Object key) {
145 return map.remove(key).value();
146 }
147
148
149
150
151 public int size() {
152 return map.size();
153 }
154
155
156
157
158 public Collection<String> values() {
159 Collection<String> result = new ArrayList<String>();
160 for (Iterator<SequenceGenerator> i = map.values().iterator(); i
161 .hasNext();) {
162 SequenceGenerator sequenceGenerator = i.next();
163 result.add(sequenceGenerator.value());
164 }
165 return result;
166 }
167
168
169
170
171 private class AdapterEntry implements Entry<String, String> {
172
173 private String key;
174 private String value;
175
176 public AdapterEntry(String key, String value) {
177 this.key = key;
178 this.value = value;
179 }
180
181
182
183
184 public String getKey() {
185 return key;
186 }
187
188
189
190
191 public String getValue() {
192 return value;
193 }
194
195
196
197
198 public String setValue(String value) {
199 String oldValue = this.value;
200 this.value = value;
201 return oldValue;
202 }
203 }
204 }