KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > struts > util > IteratorAdapter


1 /*
2  * $Id: IteratorAdapter.java 164530 2005-04-25 03:11:07Z niallp $
3  *
4  * Copyright 2002-2005 The Apache Software Foundation.
5  *
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  */

18
19 package org.apache.struts.util;
20
21 import java.util.Enumeration JavaDoc;
22 import java.util.Iterator JavaDoc;
23 import java.util.NoSuchElementException JavaDoc;
24
25
26 /**
27  * Utility method for converting Enumeration to an Iterator
28  * class. If you attempt to remove() an Object from the iterator, it will
29  * throw an UnsupportedOperationException. Added for use by TagLib so
30  * Enumeration can be supported
31  *
32  * @version $Rev: 164530 $ $Date: 2005-04-25 04:11:07 +0100 (Mon, 25 Apr 2005) $
33  */

34
35 public class IteratorAdapter implements Iterator JavaDoc {
36     private Enumeration JavaDoc e;
37
38     public IteratorAdapter(Enumeration JavaDoc e) {
39         this.e = e;
40     }
41
42     public boolean hasNext() {
43         return e.hasMoreElements();
44    }
45
46     public Object JavaDoc next() {
47         if (!e.hasMoreElements()) {
48             throw new NoSuchElementException JavaDoc("IteratorAdaptor.next() has no more elements");
49         }
50         return e.nextElement();
51     }
52     public void remove() {
53         throw new UnsupportedOperationException JavaDoc("Method IteratorAdaptor.remove() not implemented");
54     }
55 }
56
Popular Tags