|
26 | 26 | import java.net.URISyntaxException; |
27 | 27 | import java.net.URL; |
28 | 28 | import java.text.DecimalFormatSymbols; |
29 | | -import java.util.Collection; |
30 | | -import java.util.HashMap; |
31 | | -import java.util.Iterator; |
32 | | -import java.util.Map; |
| 29 | +import java.util.*; |
33 | 30 | import java.util.regex.Pattern; |
34 | 31 |
|
35 | 32 | /** |
@@ -217,6 +214,46 @@ public static Map<String, String> parseSimpleArrayAsMap(Configuration configurat |
217 | 214 | return result; |
218 | 215 | } |
219 | 216 |
|
| 217 | + /** |
| 218 | + * parse a simple array and return it as a Set. |
| 219 | + * @param configPrefix the prefix that is the basis of the array. E.g. |
| 220 | + * |
| 221 | + * given: |
| 222 | + * |
| 223 | + * smartcardAdaptor.cardFeatures.23.sbmMSB.0=0x00 |
| 224 | + * smartcardAdaptor.cardFeatures.23.sbmMSB.1=0x01 |
| 225 | + * |
| 226 | + * the config prefix will be: |
| 227 | + * smartcardAdaptor.cardFeatures.23.sbmMSB |
| 228 | + * |
| 229 | + * @return the Set where a distinct list of values. |
| 230 | + */ |
| 231 | + public static Set<String> parseSimpleArrayAsSet(String configPrefix) { |
| 232 | + |
| 233 | + Configuration configuration = ConfigurationFactory.getConfiguration(); |
| 234 | + |
| 235 | + return parseSimpleArrayAsSet(configuration, configPrefix); |
| 236 | + } |
| 237 | + |
| 238 | + public static Set<String> parseSimpleArrayAsSet(Configuration configuration, String configPrefix) { |
| 239 | + |
| 240 | + Set<String> result = new HashSet<String>(); |
| 241 | + |
| 242 | + // get a subset of the configuration based on the config prefix. |
| 243 | + final Configuration subset = configuration.subset(configPrefix); |
| 244 | + |
| 245 | + @SuppressWarnings("unchecked") |
| 246 | + final Iterator<String> keys = subset.getKeys(); |
| 247 | + |
| 248 | + while (keys.hasNext()) { |
| 249 | + |
| 250 | + final String key = keys.next(); |
| 251 | + result.add(subset.getString(key)); |
| 252 | + } |
| 253 | + |
| 254 | + return result; |
| 255 | + } |
| 256 | + |
220 | 257 | /** |
221 | 258 | * create inner key map by taking what ever is after the first dot. |
222 | 259 | * |
|
0 commit comments