1   /**
2    * Distribution License:
3    * JSword is free software; you can redistribute it and/or modify it under
4    * the terms of the GNU Lesser General Public License, version 2.1 or later
5    * as published by the Free Software Foundation. This program is distributed
6    * in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
7    * the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
8    * See the GNU Lesser General Public License for more details.
9    *
10   * The License is available on the internet at:
11   *      http://www.gnu.org/copyleft/lgpl.html
12   * or by writing to:
13   *      Free Software Foundation, Inc.
14   *      59 Temple Place - Suite 330
15   *      Boston, MA 02111-1307, USA
16   *
17   * © CrossWire Bible Society, 2005 - 2016
18   *
19   */
20  package org.crosswire.common.util;
21  
22  import java.util.Enumeration;
23  import java.util.Iterator;
24  import java.util.NoSuchElementException;
25  
26  /**
27   * Convert an Iterator into a Enumeration.
28   * <p>
29   * The only real difference between the 2 is the naming and that Enumeration
30   * does not have the delete method.
31   * </p>
32   * 
33   * @param <E> The type of the elements returned by this iterator
34   * @see gnu.lgpl.License The GNU Lesser General Public License for details.
35   * @author Joe Walker
36   */
37  public final class IteratorEnumeration<E> implements Enumeration<E> {
38      /**
39       * Create an Enumeration that proxies to an Iterator.
40       * 
41       * @param it the iterator to wrap.
42       */
43      public IteratorEnumeration(Iterator<E> it) {
44          this.it = it;
45      }
46  
47      /* (non-Javadoc)
48       * @see java.util.Enumeration#hasMoreElements()
49       */
50      public boolean hasMoreElements() {
51          return it.hasNext();
52      }
53  
54      /* (non-Javadoc)
55       * @see java.util.Enumeration#nextElement()
56       */
57      public E nextElement() throws NoSuchElementException {
58          return it.next();
59      }
60  
61      /**
62       * The Iterator that we are proxying to
63       */
64      private Iterator<E> it;
65  }
66