KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > commons > collections > iterators > IteratorEnumeration


1 /*
2  * Copyright 1999-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 package org.apache.commons.collections.iterators;
17
18 import java.util.Enumeration JavaDoc;
19 import java.util.Iterator JavaDoc;
20
21 /**
22  * Adapter to make an {@link Iterator Iterator} instance appear to be
23  * an {@link Enumeration Enumeration} instance.
24  *
25  * @since Commons Collections 1.0
26  * @version $Revision: 1.9 $ $Date: 2004/05/03 10:23:38 $
27  *
28  * @author <a HREF="mailto:jstrachan@apache.org">James Strachan</a>
29  */

30 public class IteratorEnumeration implements Enumeration JavaDoc {
31     
32     /** The iterator being decorated. */
33     private Iterator JavaDoc iterator;
34     
35     /**
36      * Constructs a new <code>IteratorEnumeration</code> that will not
37      * function until {@link #setIterator(Iterator) setIterator} is
38      * invoked.
39      */

40     public IteratorEnumeration() {
41         super();
42     }
43
44     /**
45      * Constructs a new <code>IteratorEnumeration</code> that will use
46      * the given iterator.
47      *
48      * @param iterator the iterator to use
49      */

50     public IteratorEnumeration( Iterator JavaDoc iterator ) {
51         super();
52         this.iterator = iterator;
53     }
54
55     // Iterator interface
56
//-------------------------------------------------------------------------
57

58     /**
59      * Returns true if the underlying iterator has more elements.
60      *
61      * @return true if the underlying iterator has more elements
62      */

63     public boolean hasMoreElements() {
64         return iterator.hasNext();
65     }
66
67     /**
68      * Returns the next element from the underlying iterator.
69      *
70      * @return the next element from the underlying iterator.
71      * @throws java.util.NoSuchElementException if the underlying iterator has no
72      * more elements
73      */

74     public Object JavaDoc nextElement() {
75         return iterator.next();
76     }
77
78     // Properties
79
//-------------------------------------------------------------------------
80

81     /**
82      * Returns the underlying iterator.
83      *
84      * @return the underlying iterator
85      */

86     public Iterator JavaDoc getIterator() {
87         return iterator;
88     }
89
90     /**
91      * Sets the underlying iterator.
92      *
93      * @param iterator the new underlying iterator
94      */

95     public void setIterator( Iterator JavaDoc iterator ) {
96         this.iterator = iterator;
97     }
98     
99 }
100
Popular Tags