1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 package org.apache.tiles.util;
23
24 import java.util.Enumeration;
25 import java.util.Iterator;
26
27 /***
28 * Copied and modified from Apache Commons Collections 3.2.1.<br>
29 *
30 * Adapter to make an {@link Iterator Iterator} instance appear to be an
31 * {@link Enumeration Enumeration} instance.
32 *
33 * @param <E> The type of the enumerated elements.
34 * @since Commons Collections 1.0
35 * @version $Revision: 797916 $ $Date: 2008-04-10 13:33:15 +0100 (Thu, 10 Apr
36 * 2008) $
37 *
38 * @author <a href="mailto:jstrachan@apache.org">James Strachan</a>
39 */
40 public class IteratorEnumeration<E> implements Enumeration<E> {
41
42 /*** The iterator being decorated. */
43 private Iterator<E> iterator;
44
45 /***
46 * Constructs a new <code>IteratorEnumeration</code> that will use the given
47 * iterator.
48 *
49 * @param iterator the iterator to use
50 */
51 public IteratorEnumeration(Iterator<E> iterator) {
52 this.iterator = iterator;
53 }
54
55
56
57
58 /***
59 * Returns true if the underlying iterator has more elements.
60 *
61 * @return true if the underlying iterator has more elements
62 */
63 public boolean hasMoreElements() {
64 return iterator.hasNext();
65 }
66
67 /***
68 * Returns the next element from the underlying iterator.
69 *
70 * @return the next element from the underlying iterator.
71 * @throws java.util.NoSuchElementException if the underlying iterator has
72 * no more elements
73 */
74 public E nextElement() {
75 return iterator.next();
76 }
77
78
79
80 }