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.Vector;
26
27 /***
28 * It represents an vector-based enumeration when, when it has finished
29 * enumerating items, it starts from the beginning.
30 *
31 * @param <E> The type of the element of this enumeration.
32 * @version $Rev: 527536 $ $Date: 2007-04-11 17:44:51 +0200 (Wed, 11 Apr 2007) $
33 */
34 public class RollingVectorEnumeration<E> implements Enumeration<E> {
35
36 /***
37 * The vector.
38 */
39 private Vector<E> vector;
40
41 /***
42 * The elements.
43 */
44 private Enumeration<E> elements;
45
46 /***
47 * Constructor.
48 *
49 * @param vector The vector.
50 */
51 public RollingVectorEnumeration(Vector<E> vector) {
52 this.vector = vector;
53 }
54
55 /*** {@inheritDoc} */
56 public boolean hasMoreElements() {
57 if (elements == null) {
58 elements = vector.elements();
59 return false;
60 }
61 return elements.hasMoreElements();
62 }
63
64 /*** {@inheritDoc} */
65 public E nextElement() {
66 E retValue = elements.nextElement();
67
68 if (!elements.hasMoreElements()) {
69 elements = null;
70 }
71
72 return retValue;
73 }
74
75 }