]> git.argeo.org Git - lgpl/argeo-commons.git/blob - src/org/argeo/util/DictionaryKeys.java
Prepare next development cycle
[lgpl/argeo-commons.git] / src / org / argeo / util / DictionaryKeys.java
1 package org.argeo.util;
2
3 import java.util.Dictionary;
4 import java.util.Enumeration;
5 import java.util.Iterator;
6
7 /**
8 * Access the keys of a {@link String}-keyed {@link Dictionary} (common throughout
9 * the OSGi APIs) as an {@link Iterable} so that they are easily usable in
10 * for-each loops.
11 */
12 class DictionaryKeys implements Iterable<String> {
13 private final Dictionary<String, ?> dictionary;
14
15 public DictionaryKeys(Dictionary<String, ?> dictionary) {
16 this.dictionary = dictionary;
17 }
18
19 @Override
20 public Iterator<String> iterator() {
21 return new KeyIterator(dictionary.keys());
22 }
23
24 private static class KeyIterator implements Iterator<String> {
25 private final Enumeration<String> keys;
26
27 KeyIterator(Enumeration<String> keys) {
28 this.keys = keys;
29 }
30
31 @Override
32 public boolean hasNext() {
33 return keys.hasMoreElements();
34 }
35
36 @Override
37 public String next() {
38 return keys.nextElement();
39 }
40
41 }
42 }