View Javadoc

1   /*
2    * $Id: RollingVectorEnumeration.java 527536 2007-04-11 15:44:51Z apetrelli $
3    *
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   * http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.
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  }