1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package org.apache.directory.server.core.avltree;
21
22
23 import java.io.IOException;
24
25 import org.apache.directory.api.ldap.model.constants.Loggers;
26 import org.apache.directory.api.ldap.model.cursor.AbstractCursor;
27 import org.apache.directory.api.ldap.model.cursor.CursorException;
28 import org.apache.directory.api.ldap.model.cursor.InvalidCursorPositionException;
29 import org.apache.directory.api.ldap.model.cursor.Tuple;
30 import org.apache.directory.api.ldap.model.exception.LdapException;
31 import org.slf4j.Logger;
32 import org.slf4j.LoggerFactory;
33
34
35
36
37
38
39
40
41
42 public class AvlTreeMapNoDupsWrapperCursor<K, V> extends AbstractCursor<Tuple<K, V>>
43 {
44
45 private static final Logger LOG_CURSOR = LoggerFactory.getLogger( Loggers.CURSOR_LOG.getName() );
46
47
48 private static final boolean IS_DEBUG = LOG_CURSOR.isDebugEnabled();
49
50 private final AvlSingletonOrOrderedSetCursor<K, V> wrapped;
51 private final Tuple<K, V> returnedTuple = new Tuple<K, V>();
52
53
54 public AvlTreeMapNoDupsWrapperCursor( AvlSingletonOrOrderedSetCursor<K, V> wrapped )
55 {
56 if ( IS_DEBUG )
57 {
58 LOG_CURSOR.debug( "Creating AvlTreeMapNoDupsWrapperCursor {}", this );
59 }
60
61 this.wrapped = wrapped;
62 }
63
64
65 public void afterKey( K key ) throws Exception
66 {
67 wrapped.afterKey( key );
68 }
69
70
71 public void afterValue( K key, V value ) throws Exception
72 {
73 throw new UnsupportedOperationException( "This Cursor does not support duplicate keys." );
74 }
75
76
77 public void beforeKey( K key ) throws Exception
78 {
79 wrapped.beforeKey( key );
80 }
81
82
83 public void beforeValue( K key, V value ) throws Exception
84 {
85 throw new UnsupportedOperationException( "This Cursor does not support duplicate keys." );
86 }
87
88
89
90
91
92 public void after( Tuple<K, V> element ) throws LdapException, CursorException, IOException
93 {
94 wrapped.afterKey( element.getKey() );
95 }
96
97
98
99
100
101 public void afterLast() throws LdapException, CursorException, IOException
102 {
103 wrapped.afterLast();
104 }
105
106
107
108
109
110 public boolean available()
111 {
112 return wrapped.available();
113 }
114
115
116
117
118
119 public void before( Tuple<K, V> element ) throws LdapException, CursorException, IOException
120 {
121 wrapped.beforeKey( element.getKey() );
122 }
123
124
125
126
127
128 public void beforeFirst() throws LdapException, CursorException, IOException
129 {
130 wrapped.beforeFirst();
131 }
132
133
134
135
136
137 public boolean first() throws LdapException, CursorException, IOException
138 {
139 return wrapped.first();
140 }
141
142
143
144
145
146 public Tuple<K, V> get() throws CursorException, IOException
147 {
148 if ( wrapped.available() )
149 {
150 Tuple<K, SingletonOrOrderedSet<V>> tuple = wrapped.get();
151
152 if ( tuple.getValue().isOrderedSet() )
153 {
154 tuple.getValue().getOrderedSet().printTree();
155 }
156
157 returnedTuple.setBoth( tuple.getKey(), tuple.getValue().getSingleton() );
158 return returnedTuple;
159 }
160
161 throw new InvalidCursorPositionException();
162 }
163
164
165
166
167
168 public boolean last() throws LdapException, CursorException, IOException
169 {
170 return wrapped.last();
171 }
172
173
174
175
176
177 public boolean next() throws LdapException, CursorException, IOException
178 {
179 return wrapped.next();
180 }
181
182
183
184
185
186 public boolean previous() throws LdapException, CursorException, IOException
187 {
188 return wrapped.previous();
189 }
190
191
192 public void close()
193 {
194 if ( IS_DEBUG )
195 {
196 LOG_CURSOR.debug( "Closing AvlTreeMapNoDupsWrapperCursor {}", this );
197 }
198
199 wrapped.close();
200 }
201
202
203 public void close( Exception reason )
204 {
205 if ( IS_DEBUG )
206 {
207 LOG_CURSOR.debug( "Closing AvlTreeMapNoDupsWrapperCursor {}", this );
208 }
209
210 wrapped.close( reason );
211 }
212 }