1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 package org.apache.directory.server.core.partition.impl.btree.mavibot;
22
23
24 import java.io.IOException;
25
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.exception.LdapException;
29 import org.apache.directory.mavibot.btree.ValueCursor;
30 import org.apache.directory.server.i18n.I18n;
31
32
33
34
35
36
37
38 public class ValueTreeCursor<V> extends AbstractCursor<V>
39 {
40
41 private ValueCursor<V> wrapped;
42
43 private V available;
44
45
46 private V notAvailable = ( V ) new Object();
47
48
49 public ValueTreeCursor( ValueCursor<V> cursor )
50 {
51 this.wrapped = cursor;
52 }
53
54
55 @Override
56 public boolean available()
57 {
58 return ( available != notAvailable );
59 }
60
61
62 @Override
63 public void before( V element ) throws LdapException, CursorException
64 {
65 throw new UnsupportedOperationException( I18n.err( I18n.ERR_446 ) );
66 }
67
68
69 @Override
70 public void after( V element ) throws LdapException, CursorException
71 {
72 throw new UnsupportedOperationException( I18n.err( I18n.ERR_446 ) );
73 }
74
75
76 @Override
77 public void beforeFirst() throws LdapException, CursorException
78 {
79 }
80
81
82 @Override
83 public void afterLast() throws LdapException, CursorException
84 {
85 throw new UnsupportedOperationException( I18n.err( I18n.ERR_446 ) );
86 }
87
88
89 @Override
90 public boolean first() throws LdapException, CursorException
91 {
92 throw new UnsupportedOperationException( I18n.err( I18n.ERR_446 ) );
93 }
94
95
96 @Override
97 public boolean last() throws LdapException, CursorException
98 {
99 throw new UnsupportedOperationException( I18n.err( I18n.ERR_446 ) );
100 }
101
102
103 @Override
104 public boolean previous() throws LdapException, CursorException
105 {
106 try
107 {
108 if ( wrapped.hasPrev() )
109 {
110 available = wrapped.prev();
111 return true;
112 }
113 else
114 {
115 available = notAvailable;
116 return false;
117 }
118 }
119 catch ( IOException e )
120 {
121 throw new CursorException( e );
122 }
123 }
124
125
126 @Override
127 public boolean next() throws LdapException, CursorException
128 {
129 try
130 {
131 if ( wrapped.hasNext() )
132 {
133 available = wrapped.next();
134 return true;
135 }
136 else
137 {
138 available = notAvailable;
139 return false;
140 }
141 }
142 catch ( IOException e )
143 {
144 throw new CursorException( e );
145 }
146 }
147
148
149 @Override
150 public V get() throws CursorException
151 {
152 return available;
153 }
154
155 }