KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > pluto > util > Enumerator


1 /*
2  * Copyright 2003,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 /*
17
18  */

19
20 package org.apache.pluto.util;
21
22 import java.util.Collection JavaDoc;
23 import java.util.Enumeration JavaDoc;
24 import java.util.Iterator JavaDoc;
25 import java.util.Map JavaDoc;
26 import java.util.NoSuchElementException JavaDoc;
27
28
29 /**
30  * Uitlity class to wraps an <code>Enumeration</code> around a
31  * Collection, i.e. <code>Iterator</code> classes.
32  */

33
34 public final class Enumerator implements Enumeration JavaDoc
35 {
36
37
38     // Iterator over which the Enumeration takes place
39
private Iterator JavaDoc iterator = null;
40
41
42     /**
43      * Returns an Enumeration over the specified Collection.
44      *
45      * @param collection Collection with values that should be enumerated
46      */

47     public Enumerator(Collection JavaDoc collection)
48     {
49         this(collection.iterator());
50     }
51
52
53     /**
54      * Returns an Enumeration over the values of the
55      * specified Iterator.
56      *
57      * @param iterator Iterator to be wrapped
58      */

59     public Enumerator(Iterator JavaDoc iterator)
60     {
61         super();
62         this.iterator = iterator;
63     }
64
65
66     /**
67      * Returns an Enumeration over the values of the specified Map.
68      *
69      * @param map Map with values that should be enumerated
70      */

71     public Enumerator(Map JavaDoc map)
72     {
73         this(map.values().iterator());
74     }
75
76
77
78     /**
79      * Tests if this enumeration contains more elements.
80      *
81      * @return <code>true</code> if this enumeration contains at
82      * least one more element to provide,
83      * <code>false</code> otherwise.
84      */

85     public boolean hasMoreElements()
86     {
87         return(iterator.hasNext());
88     }
89
90
91     /**
92      * Returns the next element of this enumeration.
93      *
94      * @return the next element of this enumeration
95      *
96      * @exception NoSuchElementException if no more elements exist
97      */

98     public Object JavaDoc nextElement() throws NoSuchElementException JavaDoc {
99         return(iterator.next());
100     }
101
102
103 }
104
Popular Tags