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.xdbm;
21
22
23 import org.apache.directory.api.ldap.model.cursor.Tuple;
24 import org.apache.directory.api.ldap.model.entry.Entry;
25
26
27
28
29
30
31
32
33
34
35 public class IndexEntry<K, I>
36 {
37
38 private Entry entry;
39
40
41 private final Tuple<K, I> tuple = new Tuple<>();
42
43
44
45
46
47 public IndexEntry()
48 {
49 super();
50 }
51
52
53
54
55
56
57
58
59 public void setTuple( Tuple<K, I> tuple )
60 {
61
62 entry = null;
63
64
65 this.tuple.setKey( tuple.getKey() );
66 this.tuple.setValue( tuple.getValue() );
67 }
68
69
70
71
72
73 public I getId()
74 {
75 return tuple.getValue();
76 }
77
78
79
80
81
82 public K getKey()
83 {
84 return tuple.getKey();
85 }
86
87
88
89
90
91 public void setId( I id )
92 {
93 tuple.setValue( id );
94 }
95
96
97
98
99
100 public void setKey( K value )
101 {
102 tuple.setKey( value );
103 }
104
105
106
107
108
109 public Entry getEntry()
110 {
111 return entry;
112 }
113
114
115
116
117
118 public void setEntry( Entry entry )
119 {
120 this.entry = entry;
121 }
122
123
124
125
126
127 public Tuple<K, I> getTuple()
128 {
129 return tuple;
130 }
131
132
133
134
135
136 public void clear()
137 {
138 entry = null;
139 tuple.setKey( null );
140 tuple.setValue( null );
141 }
142
143
144
145
146
147 public void copy( IndexEntry<K, I> entry )
148 {
149 this.entry = entry.getEntry();
150 tuple.setKey( entry.getKey() );
151 tuple.setValue( entry.getId() );
152 }
153
154
155 public int hashCode()
156 {
157 if ( getId() == null )
158 {
159 return 0;
160 }
161
162 return getId().hashCode();
163 }
164
165
166 public boolean equals( Object that )
167 {
168 if ( that == this )
169 {
170 return true;
171 }
172
173 if ( !( that instanceof IndexEntry ) )
174 {
175 return false;
176 }
177
178 @SuppressWarnings("unchecked")
179 IndexEntry<K, I> thatIndexEntry = ( IndexEntry<K, I> ) that;
180
181 if ( thatIndexEntry.getId() == null )
182 {
183 return getId() == null;
184 }
185
186 return thatIndexEntry.getId().equals( getId() );
187 }
188
189
190
191
192
193 public String toString()
194 {
195 StringBuilder buf = new StringBuilder();
196 buf.append( "IndexEntry[ " );
197 buf.append( tuple.getKey() );
198 buf.append( ", " );
199 buf.append( tuple.getValue() );
200 buf.append( " ]" );
201
202 return buf.toString();
203 }
204 }