KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > ldap > server > db > TupleEnumeration


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  */

17 package org.apache.ldap.server.db;
18
19
20 import javax.naming.NamingEnumeration JavaDoc;
21 import java.util.Iterator JavaDoc;
22
23
24 /**
25  * A NamingEnumeration that returns underlying Iterator values for a single key
26  * as Tuples.
27  *
28  * <p>
29  * WARNING: The tuple returned is reused every time for efficiency and populated
30  * a over and over again with the new value. The key never changes.
31  * </p>
32  *
33  * @author <a HREF="mailto:dev@directory.apache.org">Apache Directory Project</a>
34  * @version $Rev: 169198 $
35  */

36 public class TupleEnumeration
37     implements NamingEnumeration JavaDoc
38 {
39     /** TODO */
40     private final Object JavaDoc key;
41     /** TODO */
42     private final Iterator JavaDoc iterator;
43     /** TODO */
44     private final Tuple tuple = new Tuple();
45
46
47     /**
48      * Creates a cursor over an Iterator of single key's values
49      *
50      * @param key the keys whose duplicate values are to be returned
51      * @param iterator the underlying iterator this cursor uses
52      */

53     public TupleEnumeration( Object JavaDoc key, Iterator JavaDoc iterator )
54     {
55         this.key = key;
56         tuple.setKey( key );
57         this.iterator = iterator;
58     }
59
60     
61     /**
62      * Gets the next value as a Tuple.
63      *
64      * @see javax.naming.NamingEnumeration#next()
65      */

66     public Object JavaDoc next()
67     {
68         tuple.setKey( key );
69         tuple.setValue( iterator.next() );
70         return tuple;
71     }
72
73
74     /**
75      * Gets the next value as a Tuple.
76      *
77      * @see javax.naming.NamingEnumeration#nextElement()
78      */

79     public Object JavaDoc nextElement()
80     {
81         tuple.setKey( key );
82         tuple.setValue( iterator.next() );
83         return tuple;
84     }
85
86
87     /**
88      * Checks if another value is available.
89      *
90      * @see javax.naming.NamingEnumeration#hasMore()
91      */

92     public boolean hasMore()
93     {
94         return iterator.hasNext();
95     }
96
97
98     /**
99      * Checks if another value is available.
100      *
101      * @see javax.naming.NamingEnumeration#hasMoreElements()
102      */

103     public boolean hasMoreElements()
104     {
105         return iterator.hasNext();
106     }
107
108
109     /**
110      * @see javax.naming.NamingEnumeration#close()
111      */

112     public void close()
113     {
114     }
115 }
116
Popular Tags