1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.ldap.server.db;
18
19
20 import javax.naming.NamingEnumeration;
21 import java.util.Iterator;
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: 159259 $
35 */
36 public class TupleEnumeration
37 implements NamingEnumeration
38 {
39 /*** TODO */
40 private final Object key;
41 /*** TODO */
42 private final Iterator 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 key, Iterator 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 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 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 }