KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > beehive > netui > util > iterator > EnumerationIterator


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

18 package org.apache.beehive.netui.util.iterator;
19
20 import java.util.Enumeration JavaDoc;
21 import java.util.Iterator JavaDoc;
22 import java.util.NoSuchElementException JavaDoc;
23
24 import org.apache.beehive.netui.util.Bundle;
25
26 /**
27  * This class implements the {@link java.util.Iterator} interface for an {@link java.util.Enumeration}.
28  */

29 public class EnumerationIterator
30     implements Iterator JavaDoc {
31
32     private Enumeration JavaDoc _enum = null;
33
34     public EnumerationIterator(Enumeration JavaDoc e) {
35         _enum = e;
36     }
37
38     public boolean hasNext() {
39         if(_enum == null)
40             return false;
41         else return _enum.hasMoreElements();
42     }
43
44     public Object JavaDoc next() {
45         if(_enum == null || hasNext() == false)
46             throw new NoSuchElementException JavaDoc(Bundle.getErrorString("IteratorFactory_Iterator_noSuchElement"));
47         else return _enum.nextElement();
48     }
49
50     public void remove() {
51         throw new UnsupportedOperationException JavaDoc(Bundle.getErrorString("IteratorFactory_Iterator_removeUnsupported",
52             new Object JavaDoc[]{this.getClass().getName()}));
53     }
54 }
55
Popular Tags