1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.ldap.server.partition.impl.btree;
18
19
20 import java.util.Iterator;
21
22 import javax.naming.NamingEnumeration;
23
24
25 /***
26 * A NamingEnumeration that returns underlying Iterator values for a single key
27 * as Tuples.
28 *
29 * <p>
30 * WARNING: The tuple returned is reused every time for efficiency and populated
31 * a over and over again with the new value. The key never changes.
32 * </p>
33 *
34 * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
35 * @version $Rev: 264732 $
36 */
37 public class TupleEnumeration
38 implements NamingEnumeration
39 {
40 private final Object key;
41 private final Iterator iterator;
42 private final Tuple tuple = new Tuple();
43
44
45 /***
46 * Creates a cursor over an Iterator of single key's values
47 *
48 * @param key the keys whose duplicate values are to be returned
49 * @param iterator the underlying iterator this cursor uses
50 */
51 public TupleEnumeration( Object key, Iterator iterator )
52 {
53 this.key = key;
54 tuple.setKey( key );
55 this.iterator = iterator;
56 }
57
58
59 /***
60 * Gets the next value as a Tuple.
61 *
62 * @see javax.naming.NamingEnumeration#next()
63 */
64 public Object next()
65 {
66 tuple.setKey( key );
67 tuple.setValue( iterator.next() );
68 return tuple;
69 }
70
71
72 /***
73 * Gets the next value as a Tuple.
74 *
75 * @see javax.naming.NamingEnumeration#nextElement()
76 */
77 public Object nextElement()
78 {
79 tuple.setKey( key );
80 tuple.setValue( iterator.next() );
81 return tuple;
82 }
83
84
85 /***
86 * Checks if another value is available.
87 *
88 * @see javax.naming.NamingEnumeration#hasMore()
89 */
90 public boolean hasMore()
91 {
92 return iterator.hasNext();
93 }
94
95
96 /***
97 * Checks if another value is available.
98 *
99 * @see javax.naming.NamingEnumeration#hasMoreElements()
100 */
101 public boolean hasMoreElements()
102 {
103 return iterator.hasNext();
104 }
105
106
107 /***
108 * @see javax.naming.NamingEnumeration#close()
109 */
110 public void close()
111 {
112 }
113 }