1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package org.apache.pluto.util;
21
22 import java.util.Collection;
23 import java.util.Enumeration;
24 import java.util.Iterator;
25 import java.util.Map;
26 import java.util.NoSuchElementException;
27
28
29 /***
30 * Uitlity class to wraps an <code>Enumeration</code> around a
31 * Collection, i.e. <code>Iterator</code> classes.
32 */
33
34 public final class Enumerator implements Enumeration
35 {
36
37
38
39 private Iterator iterator = null;
40
41
42 /***
43 * Returns an Enumeration over the specified Collection.
44 *
45 * @param collection Collection with values that should be enumerated
46 */
47 public Enumerator(Collection collection)
48 {
49 this(collection.iterator());
50 }
51
52
53 /***
54 * Returns an Enumeration over the values of the
55 * specified Iterator.
56 *
57 * @param iterator Iterator to be wrapped
58 */
59 public Enumerator(Iterator iterator)
60 {
61 super();
62 this.iterator = iterator;
63 }
64
65
66 /***
67 * Returns an Enumeration over the values of the specified Map.
68 *
69 * @param map Map with values that should be enumerated
70 */
71 public Enumerator(Map map)
72 {
73 this(map.values().iterator());
74 }
75
76
77
78 /***
79 * Tests if this enumeration contains more elements.
80 *
81 * @return <code>true</code> if this enumeration contains at
82 * least one more element to provide,
83 * <code>false</code> otherwise.
84 */
85 public boolean hasMoreElements()
86 {
87 return(iterator.hasNext());
88 }
89
90
91 /***
92 * Returns the next element of this enumeration.
93 *
94 * @return the next element of this enumeration
95 *
96 * @exception NoSuchElementException if no more elements exist
97 */
98 public Object nextElement() throws NoSuchElementException {
99 return(iterator.next());
100 }
101
102
103 }