This project has retired. For details please refer to its Attic page.
IteratorEnumeration xref
View Javadoc

1   /*
2    * $Id: IteratorEnumeration.java 797916 2009-07-26 11:54:13Z 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.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      // Iterator interface
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      // Properties
79      // -------------------------------------------------------------------------
80  }