01: package net.sourceforge.squirrel_sql.fw.util;
02:
03: /*
04: * Copyright (C) 2001-2002 Colin Bell
05: * colbell@users.sourceforge.net
06: *
07: * This library is free software; you can redistribute it and/or
08: * modify it under the terms of the GNU Lesser General Public
09: * License as published by the Free Software Foundation; either
10: * version 2.1 of the License, or (at your option) any later version.
11: *
12: * This library is distributed in the hope that it will be useful,
13: * but WITHOUT ANY WARRANTY; without even the implied warranty of
14: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15: * Lesser General Public License for more details.
16: *
17: * You should have received a copy of the GNU Lesser General Public
18: * License along with this library; if not, write to the Free Software
19: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20: */
21: import java.util.Enumeration;
22: import java.util.Iterator;
23:
24: /**
25: * An <TT>EnumerationIterator</TT> object will allow you to treat
26: * an <TT>Enumeration</TT> as an <TT>Iterator</TT>.
27: *
28: * @author <A HREF="mailto:colbell@users.sourceforge.net">Colin Bell</A>
29: */
30: public class EnumerationIterator<E> implements Iterator<E> {
31: /** <TT>Enumeration</TT> that this <TT>Iterator</TT> is built over. */
32: private Enumeration<E> _en;
33:
34: /**
35: * Ctor.
36: *
37: * @param en <TT>Enumeration</TT> that <TT>Iterator</TT> will be built
38: * over. If <TT>null</TT> pretends it was an empty
39: * <TT>Enumeration</TT> passed.
40: */
41: public EnumerationIterator(Enumeration<E> en) {
42: super ();
43: _en = en != null ? en : new EmptyEnumeration<E>();
44: }
45:
46: /**
47: * Returns <TT>true</TT> if the iteration has more elements.
48: *
49: * @return <TT>true</TT> if the <TT>Iterator</TT> has more elements.
50: */
51: public boolean hasNext() {
52: return _en.hasMoreElements();
53: }
54:
55: /**
56: * Returns the next element in the interation.
57: *
58: * @return the next element in the iteration.
59: *
60: * @throws <TT>NoSuchElementException</TT>
61: * iteration has no more elements.
62: */
63: public E next() {
64: return _en.nextElement();
65: }
66:
67: /**
68: * Unsupported operation. <TT>Enumeration</TT> objects don't
69: * support <TT>remove</TT>.
70: *
71: * @throws <TT>UnsupportedOperationException</TT>
72: * This is an unsupported operation.
73: */
74: public void remove() {
75: throw new UnsupportedOperationException("remove()");
76: }
77: }
|