|
1 |
| |
|
2 |
| |
|
3 |
| |
|
4 |
| |
|
5 |
| |
|
6 |
| |
|
7 |
| |
|
8 |
| |
|
9 |
| |
|
10 |
| |
|
11 |
| |
|
12 |
| |
|
13 |
| |
|
14 |
| |
|
15 |
| |
|
16 |
| |
|
17 |
| |
|
18 |
| |
|
19 |
| |
|
20 |
| package org.apache.xindice.core.indexer; |
|
21 |
| |
|
22 |
| import org.apache.commons.logging.Log; |
|
23 |
| import org.apache.commons.logging.LogFactory; |
|
24 |
| import org.apache.xindice.core.DBException; |
|
25 |
| import org.apache.xindice.core.FaultCodes; |
|
26 |
| import org.apache.xindice.core.data.Key; |
|
27 |
| import org.apache.xindice.core.data.Value; |
|
28 |
| import org.apache.xindice.core.query.QueryEngine; |
|
29 |
| import org.apache.xindice.util.Configuration; |
|
30 |
| |
|
31 |
| import java.util.Arrays; |
|
32 |
| import java.util.Collection; |
|
33 |
| import java.util.Comparator; |
|
34 |
| import java.util.Iterator; |
|
35 |
| import java.util.LinkedList; |
|
36 |
| import java.util.Map; |
|
37 |
| import java.util.SortedMap; |
|
38 |
| import java.util.TreeMap; |
|
39 |
| import java.util.TreeSet; |
|
40 |
| |
|
41 |
| |
|
42 |
| |
|
43 |
| |
|
44 |
| |
|
45 |
| |
|
46 |
| |
|
47 |
| |
|
48 |
| |
|
49 |
| |
|
50 |
| |
|
51 |
| public class MemValueIndexer implements Indexer { |
|
52 |
| |
|
53 |
| |
|
54 |
| |
|
55 |
| |
|
56 |
| private static final Log log = LogFactory.getLog(MemValueIndexer.class); |
|
57 |
| |
|
58 |
| |
|
59 |
| |
|
60 |
| |
|
61 |
| |
|
62 |
| private static final int STRING = 0; |
|
63 |
| private static final int TRIMMED = 1; |
|
64 |
| private static final int SHORT = 2; |
|
65 |
| private static final int INTEGER = 3; |
|
66 |
| private static final int LONG = 4; |
|
67 |
| private static final int FLOAT = 5; |
|
68 |
| private static final int DOUBLE = 6; |
|
69 |
| private static final int BYTE = 7; |
|
70 |
| private static final int CHAR = 8; |
|
71 |
| private static final int BOOLEAN = 9; |
|
72 |
| |
|
73 |
| private static final String NAME = "name"; |
|
74 |
| private static final String PATTERN = "pattern"; |
|
75 |
| private static final String TYPE = "type"; |
|
76 |
| |
|
77 |
| private static final String STRING_VAL = "string"; |
|
78 |
| private static final String TRIMMED_VAL = "trimmed"; |
|
79 |
| private static final String SHORT_VAL = "short"; |
|
80 |
| private static final String INT_VAL = "int"; |
|
81 |
| private static final String LONG_VAL = "long"; |
|
82 |
| private static final String FLOAT_VAL = "float"; |
|
83 |
| private static final String DOUBLE_VAL = "double"; |
|
84 |
| private static final String BYTE_VAL = "byte"; |
|
85 |
| private static final String CHAR_VAL = "char"; |
|
86 |
| private static final String BOOLEAN_VAL = "boolean"; |
|
87 |
| |
|
88 |
| private final static IndexMatch[] EMPTY_INDEX_MATCH_ARRAY = new IndexMatch[0]; |
|
89 |
| |
|
90 |
| |
|
91 |
| |
|
92 |
| |
|
93 |
| |
|
94 |
| |
|
95 |
| |
|
96 |
| |
|
97 |
| private org.apache.xindice.core.Collection itsCollection; |
|
98 |
| |
|
99 |
| |
|
100 |
| |
|
101 |
| |
|
102 |
| private Configuration itsConfig; |
|
103 |
| |
|
104 |
| |
|
105 |
| |
|
106 |
| |
|
107 |
| private String itsName; |
|
108 |
| |
|
109 |
| |
|
110 |
| |
|
111 |
| |
|
112 |
| private IndexPattern itsPattern; |
|
113 |
| |
|
114 |
| |
|
115 |
| |
|
116 |
| |
|
117 |
| private boolean itsWildcard = false; |
|
118 |
| |
|
119 |
| |
|
120 |
| |
|
121 |
| |
|
122 |
| private int itsValueType = STRING; |
|
123 |
| |
|
124 |
| |
|
125 |
| |
|
126 |
| |
|
127 |
| private String itsValueTypeName = STRING_VAL; |
|
128 |
| |
|
129 |
| |
|
130 |
| |
|
131 |
| |
|
132 |
| private TreeMap itsValues = null; |
|
133 |
| |
|
134 |
| |
|
135 |
| |
|
136 |
| |
|
137 |
| private int itsValueLocatorCount = 0; |
|
138 |
| |
|
139 |
| |
|
140 |
| |
|
141 |
| |
|
142 |
| private boolean itsOpen = false; |
|
143 |
| private IndexerEventHandler handler; |
|
144 |
| |
|
145 |
| |
|
146 |
| |
|
147 |
| |
|
148 |
| |
|
149 |
| |
|
150 |
| |
|
151 |
24
| public void setCollection(org.apache.xindice.core.Collection theCollection) {
|
|
152 |
24
| itsCollection = theCollection;
|
|
153 |
| } |
|
154 |
| |
|
155 |
| |
|
156 |
| |
|
157 |
| |
|
158 |
| |
|
159 |
| |
|
160 |
| |
|
161 |
| |
|
162 |
48
| public String getIndexStyle() {
|
|
163 |
48
| return STYLE_NODEVALUE;
|
|
164 |
| } |
|
165 |
| |
|
166 |
| |
|
167 |
| |
|
168 |
| |
|
169 |
| |
|
170 |
| |
|
171 |
| |
|
172 |
| |
|
173 |
| |
|
174 |
| |
|
175 |
| |
|
176 |
| |
|
177 |
| |
|
178 |
| |
|
179 |
| |
|
180 |
| |
|
181 |
| |
|
182 |
| |
|
183 |
| |
|
184 |
216
| public IndexPattern[] getPatterns() {
|
|
185 |
216
| return new IndexPattern[] { itsPattern };
|
|
186 |
| } |
|
187 |
| |
|
188 |
| |
|
189 |
| |
|
190 |
| |
|
191 |
| |
|
192 |
| |
|
193 |
| |
|
194 |
| |
|
195 |
| |
|
196 |
| |
|
197 |
| |
|
198 |
| |
|
199 |
35
| public synchronized IndexMatch[] queryMatches(IndexQuery theQuery) throws DBException {
|
|
200 |
35
| LinkedList aResult = new LinkedList();
|
|
201 |
| |
|
202 |
| |
|
203 |
| |
|
204 |
| |
|
205 |
| |
|
206 |
35
| Value[] aQueryValueList = theQuery.getValues();
|
|
207 |
35
| Object[] aMatchValueArray = new Object[aQueryValueList.length];
|
|
208 |
| |
|
209 |
| |
|
210 |
| |
|
211 |
35
| if (itsValueType != STRING) {
|
|
212 |
25
| for (int anIndex = 0; anIndex < aQueryValueList.length; ++anIndex) {
|
|
213 |
32
| aMatchValueArray[anIndex] = getTypedValue(aQueryValueList[anIndex].toString());
|
|
214 |
| } |
|
215 |
| } else { |
|
216 |
10
| for (int anIndex = 0; anIndex < aQueryValueList.length; ++anIndex) {
|
|
217 |
14
| aMatchValueArray[anIndex] = aQueryValueList[anIndex].toString();
|
|
218 |
| } |
|
219 |
| } |
|
220 |
| |
|
221 |
35
| TreeSet aLocatorSet;
|
|
222 |
| |
|
223 |
35
| Object aLowEndpoint = aMatchValueArray[0];
|
|
224 |
35
| Object aHighEndpoint = aMatchValueArray[aMatchValueArray.length - 1];
|
|
225 |
35
| Iterator aValueIterator;
|
|
226 |
35
| int anOperator = theQuery.getOperator();
|
|
227 |
35
| IndexPattern queryPattern = theQuery.getPattern();
|
|
228 |
| |
|
229 |
| |
|
230 |
35
| switch (anOperator) {
|
|
231 |
0
| default:
|
|
232 |
0
| throw new DBException(FaultCodes.IDX_NOT_SUPPORTED,
|
|
233 |
| "Unimplemented index query operation code (code = " + anOperator + ")"); |
|
234 |
| |
|
235 |
10
| case IndexQuery.EQ:
|
|
236 |
10
| aLocatorSet = (TreeSet) itsValues.get(aLowEndpoint);
|
|
237 |
10
| if (aLocatorSet != null) {
|
|
238 |
8
| addMatches(aResult, aLocatorSet, queryPattern);
|
|
239 |
| } |
|
240 |
10
| break;
|
|
241 |
| |
|
242 |
2
| case IndexQuery.NEQ:
|
|
243 |
| |
|
244 |
2
| TreeSet anExcludedLocatorSet = (TreeSet) itsValues.get(aLowEndpoint);
|
|
245 |
| |
|
246 |
2
| aValueIterator = itsValues.entrySet().iterator();
|
|
247 |
2
| if (anExcludedLocatorSet == null) {
|
|
248 |
| |
|
249 |
| |
|
250 |
0
| while (aValueIterator.hasNext()) {
|
|
251 |
| |
|
252 |
0
| addMatches(aResult, (TreeSet) ((Map.Entry) aValueIterator.next()).getValue(), queryPattern);
|
|
253 |
| } |
|
254 |
| } else { |
|
255 |
| |
|
256 |
| |
|
257 |
2
| while (aValueIterator.hasNext()) {
|
|
258 |
8
| aLocatorSet = (TreeSet) ((Map.Entry) aValueIterator.next()).getValue();
|
|
259 |
| |
|
260 |
| |
|
261 |
8
| if (aLocatorSet != anExcludedLocatorSet) {
|
|
262 |
| |
|
263 |
6
| addMatches(aResult, aLocatorSet, queryPattern);
|
|
264 |
| } |
|
265 |
| } |
|
266 |
| } |
|
267 |
2
| break;
|
|
268 |
| |
|
269 |
1
| case IndexQuery.BWX:
|
|
270 |
| |
|
271 |
| |
|
272 |
| |
|
273 |
| |
|
274 |
| |
|
275 |
| |
|
276 |
| |
|
277 |
| |
|
278 |
| |
|
279 |
| |
|
280 |
| |
|
281 |
| |
|
282 |
| |
|
283 |
| |
|
284 |
| |
|
285 |
| |
|
286 |
| |
|
287 |
| |
|
288 |
| |
|
289 |
| |
|
290 |
| |
|
291 |
| |
|
292 |
| |
|
293 |
| |
|
294 |
| |
|
295 |
1
| aLowEndpoint = getNextValueOf(aLowEndpoint);
|
|
296 |
1
| if (aLowEndpoint != null && ((Comparable) aLowEndpoint).compareTo(aHighEndpoint) < 0) {
|
|
297 |
| |
|
298 |
1
| addMatches(aResult, itsValues.subMap(aLowEndpoint, aHighEndpoint), queryPattern);
|
|
299 |
| } |
|
300 |
1
| break;
|
|
301 |
| |
|
302 |
2
| case IndexQuery.BW:
|
|
303 |
2
| addMatches(aResult, getBWSubmap(aLowEndpoint, aHighEndpoint), queryPattern);
|
|
304 |
2
| break;
|
|
305 |
| |
|
306 |
4
| case IndexQuery.SW:
|
|
307 |
| |
|
308 |
| |
|
309 |
| |
|
310 |
| |
|
311 |
4
| if (! (aLowEndpoint instanceof String) ) {
|
|
312 |
0
| aLowEndpoint = aLowEndpoint.toString();
|
|
313 |
| } |
|
314 |
| |
|
315 |
| |
|
316 |
4
| addMatches(aResult, getSWSubmap((String)aLowEndpoint), queryPattern);
|
|
317 |
4
| break;
|
|
318 |
| |
|
319 |
1
| case IndexQuery.IN:
|
|
320 |
| |
|
321 |
| |
|
322 |
| |
|
323 |
| |
|
324 |
| |
|
325 |
| |
|
326 |
1
| addMatches(aResult, getBWSubmap(aLowEndpoint, aHighEndpoint), aMatchValueArray, false, queryPattern);
|
|
327 |
1
| break;
|
|
328 |
| |
|
329 |
1
| case IndexQuery.NBWX:
|
|
330 |
| |
|
331 |
1
| addMatches(aResult, getLTSubmap(aLowEndpoint), queryPattern);
|
|
332 |
1
| addMatches(aResult, getGTSubmap(aHighEndpoint), queryPattern);
|
|
333 |
1
| break;
|
|
334 |
| |
|
335 |
1
| case IndexQuery.NBW:
|
|
336 |
| |
|
337 |
1
| addMatches(aResult, getLEQSubmap(aLowEndpoint), queryPattern);
|
|
338 |
1
| addMatches(aResult, getGEQSubmap(aHighEndpoint), queryPattern);
|
|
339 |
1
| break;
|
|
340 |
| |
|
341 |
0
| case IndexQuery.NSW:
|
|
342 |
| |
|
343 |
| |
|
344 |
| |
|
345 |
0
| if(! (aLowEndpoint instanceof String) )
|
|
346 |
| { |
|
347 |
0
| aLowEndpoint = aLowEndpoint.toString();
|
|
348 |
| } |
|
349 |
| |
|
350 |
| |
|
351 |
| |
|
352 |
0
| addMatches(aResult, getLTSubmap(aLowEndpoint), queryPattern);
|
|
353 |
0
| addMatches(aResult, getGTSubmap(aLowEndpoint), queryPattern);
|
|
354 |
0
| break;
|
|
355 |
| |
|
356 |
4
| case IndexQuery.LT:
|
|
357 |
4
| addMatches(aResult, getLTSubmap(aLowEndpoint), queryPattern);
|
|
358 |
4
| break;
|
|
359 |
| |
|
360 |
2
| case IndexQuery.LEQ:
|
|
361 |
2
| addMatches(aResult, getLEQSubmap(aLowEndpoint), queryPattern);
|
|
362 |
2
| break;
|
|
363 |
| |
|
364 |
4
| case IndexQuery.GT:
|
|
365 |
4
| addMatches(aResult, getGTSubmap(aLowEndpoint), queryPattern);
|
|
366 |
4
| break;
|
|
367 |
| |
|
368 |
2
| case IndexQuery.GEQ:
|
|
369 |
2
| addMatches(aResult, getGEQSubmap(aLowEndpoint), queryPattern);
|
|
370 |
2
| break;
|
|
371 |
| |
|
372 |
1
| case IndexQuery.NIN:
|
|
373 |
| |
|
374 |
| |
|
375 |
| |
|
376 |
1
| addMatches(aResult, getLTSubmap(aLowEndpoint), queryPattern);
|
|
377 |
1
| addMatches(aResult, getGTSubmap(aHighEndpoint), queryPattern);
|
|
378 |
| |
|
379 |
| |
|
380 |
1
| addMatches(aResult, getBWSubmap(aLowEndpoint, aHighEndpoint), aMatchValueArray, true, queryPattern);
|
|
381 |
1
| break;
|
|
382 |
| |
|
383 |
0
| case IndexQuery.ANY:
|
|
384 |
0
| addMatches(aResult, itsValues, queryPattern);
|
|
385 |
0
| break;
|
|
386 |
| } |
|
387 |
| |
|
388 |
35
| return (IndexMatch[]) aResult.toArray(EMPTY_INDEX_MATCH_ARRAY);
|
|
389 |
| } |
|
390 |
| |
|
391 |
| |
|
392 |
| |
|
393 |
| |
|
394 |
| |
|
395 |
| |
|
396 |
| |
|
397 |
| |
|
398 |
4
| private SortedMap getSWSubmap(String theLowEndpoint) {
|
|
399 |
4
| SortedMap aSubmap;
|
|
400 |
| |
|
401 |
| |
|
402 |
| |
|
403 |
4
| String aHighEndpoint = (String) getNextValueOf(theLowEndpoint, STRING);
|
|
404 |
| |
|
405 |
4
| if (aHighEndpoint == null) {
|
|
406 |
| |
|
407 |
0
| aSubmap = itsValues.tailMap(theLowEndpoint);
|
|
408 |
| } else { |
|
409 |
| |
|
410 |
4
| aSubmap = itsValues.subMap(theLowEndpoint, aHighEndpoint);
|
|
411 |
| } |
|
412 |
| |
|
413 |
4
| return aSubmap == null || aSubmap.size() == 0 ? null : aSubmap;
|
|
414 |
| } |
|
415 |
| |
|
416 |
| |
|
417 |
| |
|
418 |
| |
|
419 |
| |
|
420 |
| |
|
421 |
| |
|
422 |
| |
|
423 |
| |
|
424 |
4
| private SortedMap getBWSubmap(Object theLowEndpoint, Object theHighEndpoint) {
|
|
425 |
4
| SortedMap aSubmap = null;
|
|
426 |
| |
|
427 |
| |
|
428 |
4
| int aComparison = ((Comparable) theLowEndpoint).compareTo(theHighEndpoint);
|
|
429 |
| |
|
430 |
4
| if (aComparison == 0) {
|
|
431 |
| |
|
432 |
| |
|
433 |
0
| TreeSet aLocatorSet = (TreeSet) itsValues.get(theLowEndpoint);
|
|
434 |
0
| if (aLocatorSet != null) {
|
|
435 |
0
| aSubmap = new TreeMap(MemValueIndexer.ValueComparator.INSTANCE);
|
|
436 |
0
| aSubmap.put(theLowEndpoint, aLocatorSet);
|
|
437 |
| } |
|
438 |
| } else { |
|
439 |
4
| if (aComparison < 0) {
|
|
440 |
| |
|
441 |
| |
|
442 |
4
| theHighEndpoint = theHighEndpoint instanceof String ? getNextValueOf(theHighEndpoint, STRING) : getNextValueOf(theHighEndpoint);
|
|
443 |
| |
|
444 |
4
| if (theHighEndpoint == null) {
|
|
445 |
| |
|
446 |
0
| aSubmap = itsValues.tailMap(theLowEndpoint);
|
|
447 |
| } else { |
|
448 |
| |
|
449 |
4
| aSubmap = itsValues.subMap(theLowEndpoint, theHighEndpoint);
|
|
450 |
| } |
|
451 |
| } |
|
452 |
| |
|
453 |
| } |
|
454 |
4
| return aSubmap == null || aSubmap.size() == 0 ? null : aSubmap;
|
|
455 |
| } |
|
456 |
| |
|
457 |
| |
|
458 |
| |
|
459 |
| |
|
460 |
| |
|
461 |
| |
|
462 |
| |
|
463 |
9
| private SortedMap getLTSubmap(Object theHighEndpoint) {
|
|
464 |
9
| SortedMap aSubmap = itsValues.headMap(theHighEndpoint);
|
|
465 |
9
| return aSubmap == null || aSubmap.size() == 0 ? null : aSubmap;
|
|
466 |
| } |
|
467 |
| |
|
468 |
| |
|
469 |
| |
|
470 |
| |
|
471 |
| |
|
472 |
| |
|
473 |
| |
|
474 |
3
| private SortedMap getLEQSubmap(Object theHighEndpoint) {
|
|
475 |
| |
|
476 |
| |
|
477 |
3
| theHighEndpoint = theHighEndpoint instanceof String ? getNextValueOf(theHighEndpoint, STRING) : getNextValueOf(theHighEndpoint);
|
|
478 |
| |
|
479 |
3
| if (theHighEndpoint == null) {
|
|
480 |
| |
|
481 |
0
| return itsValues;
|
|
482 |
| } |
|
483 |
| |
|
484 |
| |
|
485 |
3
| return getLTSubmap(theHighEndpoint);
|
|
486 |
| } |
|
487 |
| |
|
488 |
| |
|
489 |
| |
|
490 |
| |
|
491 |
| |
|
492 |
| |
|
493 |
| |
|
494 |
6
| private SortedMap getGTSubmap(Object theLowEndpoint) {
|
|
495 |
| |
|
496 |
| |
|
497 |
6
| theLowEndpoint = theLowEndpoint instanceof String ? getNextValueOf(theLowEndpoint, STRING) : getNextValueOf(theLowEndpoint);
|
|
498 |
| |
|
499 |
6
| if (theLowEndpoint == null) {
|
|
500 |
| |
|
501 |
0
| return null;
|
|
502 |
| } |
|
503 |
| |
|
504 |
| |
|
505 |
6
| return getGEQSubmap(theLowEndpoint);
|
|
506 |
| } |
|
507 |
| |
|
508 |
| |
|
509 |
| |
|
510 |
| |
|
511 |
| |
|
512 |
| |
|
513 |
| |
|
514 |
9
| private SortedMap getGEQSubmap(Object theLowEndpoint) {
|
|
515 |
9
| SortedMap aSubmap = itsValues.tailMap(theLowEndpoint);
|
|
516 |
9
| return aSubmap == null || aSubmap.size() == 0 ? null : aSubmap;
|
|
517 |
| } |
|
518 |
| |
|
519 |
| |
|
520 |
| |
|
521 |
| |
|
522 |
| |
|
523 |
| |
|
524 |
| |
|
525 |
| |
|
526 |
| |
|
527 |
| |
|
528 |
| |
|
529 |
| |
|
530 |
| |
|
531 |
2
| private void addMatches(LinkedList aResult, Map theMap, Object[] theFilterList, boolean theExcludeFlag, IndexPattern queryPattern) {
|
|
532 |
| |
|
533 |
2
| if (theMap == null) {
|
|
534 |
0
| return;
|
|
535 |
| } |
|
536 |
| |
|
537 |
2
| LinkedList aResultList = new LinkedList();
|
|
538 |
| |
|
539 |
2
| Iterator aValueIterator = theMap.entrySet().iterator();
|
|
540 |
| |
|
541 |
| |
|
542 |
2
| while (aValueIterator.hasNext()) {
|
|
543 |
6
| Map.Entry anEntry = (Map.Entry) aValueIterator.next();
|
|
544 |
6
| Object aKey = anEntry.getKey();
|
|
545 |
| |
|
546 |
6
| boolean aValueInFilterList = Arrays.binarySearch(theFilterList, aKey, MemValueIndexer.ValueComparator.INSTANCE) >= 0;
|
|
547 |
| |
|
548 |
6
| if (theExcludeFlag ^ aValueInFilterList) {
|
|
549 |
| |
|
550 |
3
| TreeSet aSet = (TreeSet) anEntry.getValue();
|
|
551 |
3
| aResultList.add(aSet);
|
|
552 |
| } |
|
553 |
| } |
|
554 |
| |
|
555 |
| |
|
556 |
2
| aValueIterator = aResultList.iterator();
|
|
557 |
2
| while (aValueIterator.hasNext()) {
|
|
558 |
3
| addMatches(aResult, (Collection) aValueIterator.next(), queryPattern);
|
|
559 |
| } |
|
560 |
| } |
|
561 |
| |
|
562 |
| |
|
563 |
| |
|
564 |
| |
|
565 |
128
| public void flush() throws DBException {
|
|
566 |
| |
|
567 |
| } |
|
568 |
| |
|
569 |
104
| public IndexerEventHandler getIndexerEventHandler() {
|
|
570 |
104
| return handler;
|
|
571 |
| } |
|
572 |
| |
|
573 |
| |
|
574 |
| |
|
575 |
| |
|
576 |
| |
|
577 |
| |
|
578 |
| |
|
579 |
| |
|
580 |
| |
|
581 |
24
| public void setConfig(Configuration theConfig) {
|
|
582 |
24
| itsConfig = theConfig;
|
|
583 |
24
| try {
|
|
584 |
24
| itsName = theConfig.getAttribute(NAME);
|
|
585 |
24
| String itsPattern = theConfig.getAttribute(PATTERN);
|
|
586 |
24
| itsWildcard = itsPattern.indexOf('*') != -1;
|
|
587 |
| |
|
588 |
| |
|
589 |
24
| String type = theConfig.getAttribute(TYPE, STRING_VAL).toLowerCase();
|
|
590 |
24
| if (type.equals(STRING_VAL)) {
|
|
591 |
7
| itsValueType = STRING;
|
|
592 |
17
| } else if (type.equals(TRIMMED_VAL)) {
|
|
593 |
0
| itsValueType = TRIMMED;
|
|
594 |
17
| } else if (type.equals(SHORT_VAL)) {
|
|
595 |
0
| itsValueType = SHORT;
|
|
596 |
17
| } else if (type.equals(INT_VAL)) {
|
|
597 |
0
| itsValueType = INTEGER;
|
|
598 |
17
| } else if (type.equals(LONG_VAL)) {
|
|
599 |
13
| itsValueType = LONG;
|
|
600 |
4
| } else if (type.equals(FLOAT_VAL)) {
|
|
601 |
1
| itsValueType = FLOAT;
|
|
602 |
3
| } else if (type.equals(DOUBLE_VAL)) {
|
|
603 |
0
| itsValueType = DOUBLE;
|
|
604 |
3
| } else if (type.equals(BYTE_VAL)) {
|
|
605 |
1
| itsValueType = BYTE;
|
|
606 |
2
| } else if (type.equals(CHAR_VAL)) {
|
|
607 |
1
| itsValueType = CHAR;
|
|
608 |
1
| } else if (type.equals(BOOLEAN_VAL)) {
|
|
609 |
1
| itsValueType = BOOLEAN;
|
|
610 |
| } else { |
|
611 |
0
| if (itsPattern.indexOf('@') != -1) {
|
|
612 |
0
| log.warn("Unrecognized value type, defaulting to '" + STRING_VAL + "'");
|
|
613 |
0
| itsValueType = STRING;
|
|
614 |
| } else { |
|
615 |
0
| log.warn("Unrecognized value type, defaulting to '" + TRIMMED_VAL + "'");
|
|
616 |
0
| itsValueType = TRIMMED;
|
|
617 |
| } |
|
618 |
| } |
|
619 |
| |
|
620 |
24
| this.itsPattern = new IndexPattern(itsCollection.getSymbols(), itsPattern, null);
|
|
621 |
24
| setupHandler();
|
|
622 |
| } catch (Exception e) { |
|
623 |
0
| log.warn("Exception while setting configuration", e);
|
|
624 |
| } |
|
625 |
| } |
|
626 |
| |
|
627 |
24
| private void setupHandler() {
|
|
628 |
24
| handler = new BasicIndexerEventHandler() {
|
|
629 |
103
| public synchronized void onValueAdded(IndexPattern pattern, String value, Key key, int pos, int len,
|
|
630 |
| short elemID, short attrID) { |
|
631 |
| |
|
632 |
103
| Object aValue;
|
|
633 |
103
| if (itsValueType != STRING) {
|
|
634 |
| |
|
635 |
| |
|
636 |
77
| aValue = getTypedValue(value);
|
|
637 |
| } else { |
|
638 |
26
| aValue = value;
|
|
639 |
| } |
|
640 |
| |
|
641 |
| |
|
642 |
103
| TreeSet aLocatorSet = (TreeSet) itsValues.get(aValue);
|
|
643 |
| |
|
644 |
| |
|
645 |
103
| if (aLocatorSet == null) {
|
|
646 |
89
| aLocatorSet = new TreeSet();
|
|
647 |
| |
|
648 |
| |
|
649 |
89
| itsValues.put(aValue, aLocatorSet);
|
|
650 |
| } |
|
651 |
| |
|
652 |
| |
|
653 |
103
| aLocatorSet.add(new ValueLocator(key, pos, len, elemID, attrID));
|
|
654 |
| |
|
655 |
| |
|
656 |
103
| ++itsValueLocatorCount;
|
|
657 |
| } |
|
658 |
| |
|
659 |
1
| public synchronized void onValueDeleted(IndexPattern pattern, String value, Key key, int pos, int len,
|
|
660 |
| short elemID, short attrID) { |
|
661 |
1
| Object aValue;
|
|
662 |
| |
|
663 |
1
| if (itsValueType != STRING) {
|
|
664 |
| |
|
665 |
| |
|
666 |
0
| aValue = getTypedValue(value);
|
|
667 |
| } else { |
|
668 |
1
| aValue = value;
|
|
669 |
| } |
|
670 |
| |
|
671 |
| |
|
672 |
1
| TreeSet aLocatorSet = (TreeSet) itsValues.get(aValue);
|
|
673 |
| |
|
674 |
| |
|
675 |
1
| if (aLocatorSet != null) {
|
|
676 |
1
| if (aLocatorSet.remove(new ValueLocator(key, pos, len, elemID, attrID))) {
|
|
677 |
| |
|
678 |
| |
|
679 |
| |
|
680 |
1
| if (aLocatorSet.size() == 0) {
|
|
681 |
1
| itsValues.remove(value);
|
|
682 |
| } |
|
683 |
| |
|
684 |
| |
|
685 |
1
| --itsValueLocatorCount;
|
|
686 |
| } |
|
687 |
| } |
|
688 |
| } |
|
689 |
| }; |
|
690 |
| } |
|
691 |
| |
|
692 |
| |
|
693 |
| |
|
694 |
| |
|
695 |
| |
|
696 |
| |
|
697 |
| |
|
698 |
0
| public Configuration getConfig() {
|
|
699 |
0
| return itsConfig;
|
|
700 |
| } |
|
701 |
| |
|
702 |
| |
|
703 |
| |
|
704 |
| |
|
705 |
| |
|
706 |
| |
|
707 |
| |
|
708 |
24
| public boolean create() throws DBException {
|
|
709 |
24
| itsOpen = false;
|
|
710 |
| |
|
711 |
| |
|
712 |
| |
|
713 |
24
| itsValues = new TreeMap(ValueComparator.INSTANCE);
|
|
714 |
24
| return true;
|
|
715 |
| } |
|
716 |
| |
|
717 |
| |
|
718 |
| |
|
719 |
| |
|
720 |
| |
|
721 |
| |
|
722 |
| |
|
723 |
| |
|
724 |
| |
|
725 |
| |
|
726 |
| |
|
727 |
24
| public synchronized boolean open() throws DBException {
|
|
728 |
24
| if (itsValues == null || itsConfig == null) {
|
|
729 |
0
| return false;
|
|
730 |
| } |
|
731 |
24
| itsOpen = true;
|
|
732 |
24
| return true;
|
|
733 |
| } |
|
734 |
| |
|
735 |
| |
|
736 |
| |
|
737 |
| |
|
738 |
| |
|
739 |
| |
|
740 |
0
| public synchronized boolean isOpened() {
|
|
741 |
0
| return itsValues != null && itsOpen;
|
|
742 |
| } |
|
743 |
| |
|
744 |
| |
|
745 |
| |
|
746 |
| |
|
747 |
| |
|
748 |
| |
|
749 |
| |
|
750 |
| |
|
751 |
24
| public synchronized boolean exists() throws DBException {
|
|
752 |
24
| return itsValues != null;
|
|
753 |
| } |
|
754 |
| |
|
755 |
| |
|
756 |
| |
|
757 |
| |
|
758 |
| |
|
759 |
| |
|
760 |
| |
|
761 |
| |
|
762 |
24
| public synchronized boolean drop() throws DBException {
|
|
763 |
24
| itsOpen = false;
|
|
764 |
24
| itsValues = null;
|
|
765 |
24
| return true;
|
|
766 |
| } |
|
767 |
| |
|
768 |
| |
|
769 |
| |
|
770 |
| |
|
771 |
| |
|
772 |
| |
|
773 |
| |
|
774 |
0
| public synchronized boolean close() throws DBException {
|
|
775 |
0
| itsOpen = false;
|
|
776 |
0
| return true;
|
|
777 |
| } |
|
778 |
| |
|
779 |
| |
|
780 |
| |
|
781 |
| |
|
782 |
| |
|
783 |
| |
|
784 |
| |
|
785 |
| |
|
786 |
48
| public String getName() {
|
|
787 |
48
| return itsName;
|
|
788 |
| } |
|
789 |
| |
|
790 |
| |
|
791 |
| |
|
792 |
| |
|
793 |
| |
|
794 |
| |
|
795 |
| |
|
796 |
| |
|
797 |
| |
|
798 |
| |
|
799 |
| |
|
800 |
| |
|
801 |
109
| private Object getTypedValue(String theValue) {
|
|
802 |
109
| if (itsValueType != STRING && itsValueType != TRIMMED) {
|
|
803 |
109
| theValue = theValue.trim();
|
|
804 |
| } else { |
|
805 |
0
| if (itsValueType == TRIMMED) {
|
|
806 |
0
| theValue = QueryEngine.normalizeString(theValue);
|
|
807 |
| } |
|
808 |
| } |
|
809 |
| |
|
810 |
109
| if (theValue.length() == 0) {
|
|
811 |
0
| return EmptyValue.INSTANCE;
|
|
812 |
| } |
|
813 |
| |
|
814 |
109
| try {
|
|
815 |
109
| switch (itsValueType) {
|
|
816 |
0
| default :
|
|
817 |
0
| break;
|
|
818 |
0
| case STRING:
|
|
819 |
0
| case TRIMMED:
|
|
820 |
0
| return theValue;
|
|
821 |
| |
|
822 |
0
| case SHORT:
|
|
823 |
0
| return new Short(theValue);
|
|
824 |
| |
|
825 |
0
| case INTEGER:
|
|
826 |
0
| return new Integer(theValue);
|
|
827 |
| |
|
828 |
90
| case LONG:
|
|
829 |
90
| return new Long(theValue);
|
|
830 |
| |
|
831 |
10
| case FLOAT:
|
|
832 |
10
| return new Float(theValue);
|
|
833 |
| |
|
834 |
0
| case DOUBLE:
|
|
835 |
0
| return new Double(theValue);
|
|
836 |
| |
|
837 |
3
| case BYTE:
|
|
838 |
3
| return new Byte(theValue);
|
|
839 |
| |
|
840 |
3
| case CHAR:
|
|
841 |
3
| return new Character(theValue.charAt(0));
|
|
842 |
| |
|
843 |
3
| case BOOLEAN:
|
|
844 |
| |
|
845 |
3
| return "[true][yes][1][y][on]".indexOf("[" + theValue.toLowerCase() + "]") == -1 ? new Byte((byte) 0) : new Byte((byte) 1);
|
|
846 |
| |
|
847 |
| } |
|
848 |
| } catch (Exception anException) { |
|
849 |
0
| if (log.isDebugEnabled()) {
|
|
850 |
0
| log.debug("Exception while converting value \"" + theValue + "\" from String to " + itsValueTypeName, anException);
|
|
851 |
| } |
|
852 |
| } |
|
853 |
0
| return "";
|
|
854 |
| } |
|
855 |
| |
|
856 |
| |
|
857 |
| |
|
858 |
| |
|
859 |
| |
|
860 |
| |
|
861 |
| |
|
862 |
| |
|
863 |
14
| private Object getNextValueOf(Object theValue) {
|
|
864 |
14
| return getNextValueOf(theValue, itsValueType);
|
|
865 |
| } |
|
866 |
| |
|
867 |
| |
|
868 |
| |
|
869 |
| |
|
870 |
| |
|
871 |
| |
|
872 |
| |
|
873 |
| |
|
874 |
| |
|
875 |
| |
|
876 |
18
| private Object getNextValueOf(Object theValue, int theType) {
|
|
877 |
18
| if (theValue instanceof EmptyValue) {
|
|
878 |
0
| return "\0";
|
|
879 |
| } |
|
880 |
| |
|
881 |
18
| Object aReturn = null;
|
|
882 |
| |
|
883 |
18
| switch (theType) {
|
|
884 |
0
| default :
|
|
885 |
0
| break;
|
|
886 |
4
| case STRING:
|
|
887 |
0
| case TRIMMED:
|
|
888 |
| |
|
889 |
4
| int aLength = ((String) theValue).length();
|
|
890 |
4
| if (aLength == 0) {
|
|
891 |
| |
|
892 |
0
| return theValue + "\0";
|
|
893 |
| } |
|
894 |
4
| char aLastChar = ((String) theValue).charAt(aLength - 1);
|
|
895 |
4
| if (aLastChar == Character.MAX_VALUE) {
|
|
896 |
| |
|
897 |
0
| return theValue + "\0";
|
|
898 |
| } |
|
899 |
| |
|
900 |
| |
|
901 |
4
| aLastChar += 1;
|
|
902 |
4
| aReturn = ((String) theValue).substring(0, aLength - 1) + aLastChar;
|
|
903 |
4
| break;
|
|
904 |
0
| case SHORT:
|
|
905 |
| { |
|
906 |
0
| short aValue = ((Short) theValue).shortValue();
|
|
907 |
0
| aReturn = aValue == Short.MAX_VALUE ? null : new Short((short) (aValue + 1));
|
|
908 |
| } |
|
909 |
0
| break;
|
|
910 |
0
| case INTEGER:
|
|
911 |
| { |
|
912 |
0
| int aValue = ((Integer) theValue).intValue();
|
|
913 |
0
| aReturn = aValue == Integer.MAX_VALUE ? null : new Integer(aValue + 1);
|
|
914 |
| } |
|
915 |
0
| break;
|
|
916 |
13
| case LONG:
|
|
917 |
| { |
|
918 |
13
| long aValue = ((Long) theValue).longValue();
|
|
919 |
13
| aReturn = aValue == Long.MAX_VALUE ? null : new Long(aValue + 1);
|
|
920 |
| } |
|
921 |
13
| break;
|
|
922 |
0
| case FLOAT:
|
|
923 |
| { |
|
924 |
0
| float aValue = ((Float) theValue).floatValue();
|
|
925 |
| |
|
926 |
0
| aReturn = aValue == Float.MAX_VALUE ? null : new Float(aValue + Float.MIN_VALUE);
|
|
927 |
| } |
|
928 |
0
| break;
|
|
929 |
0
| case DOUBLE:
|
|
930 |
| { |
|
931 |
0
| double aValue = ((Double) theValue).doubleValue();
|
|
932 |
| |
|
933 |
0
| aReturn = aValue == Double.MAX_VALUE ? null : new Double(aValue + Double.MIN_VALUE);
|
|
934 |
| } |
|
935 |
0
| break;
|
|
936 |
0
| case CHAR:
|
|
937 |
| { |
|
938 |
| |
|
939 |
0
| char aValue = ((Character) theValue).charValue();
|
|
940 |
0
| aReturn = aValue == Character.MAX_VALUE ? null : new Character((char) (aValue + 1));
|
|
941 |
| } |
|
942 |
0
| break;
|
|
943 |
0
| case BOOLEAN:
|
|
944 |
| |
|
945 |
1
| case BYTE:
|
|
946 |
| { |
|
947 |
1
| byte aValue = ((Byte) theValue).byteValue();
|
|
948 |
1
| aReturn = aValue == Byte.MAX_VALUE ? null : new Byte((byte) (aValue + 1));
|
|
949 |
| } |
|
950 |
1
| break;
|
|
951 |
| } |
|
952 |
| |
|
953 |
18
| return aReturn;
|
|
954 |
| } |
|
955 |
| |
|
956 |
| |
|
957 |
| |
|
958 |
| |
|
959 |
| |
|
960 |
| |
|
961 |
| |
|
962 |
| |
|
963 |
| |
|
964 |
| |
|
965 |
25
| private void addMatches(LinkedList theList, Map theMap, IndexPattern queryPattern) {
|
|
966 |
25
| if (theMap == null) {
|
|
967 |
2
| return;
|
|
968 |
| } |
|
969 |
| |
|
970 |
23
| Iterator aValueIterator = theMap.entrySet().iterator();
|
|
971 |
| |
|
972 |
| |
|
973 |
23
| while (aValueIterator.hasNext()) {
|
|
974 |
| |
|
975 |
42
| addMatches(theList, (TreeSet) ((Map.Entry) aValueIterator.next()).getValue(), queryPattern);
|
|
976 |
| } |
|
977 |
| } |
|
978 |
| |
|
979 |
| |
|
980 |
| |
|
981 |
| |
|
982 |
| |
|
983 |
| |
|
984 |
| |
|
985 |
| |
|
986 |
| |
|
987 |
59
| private void addMatches(LinkedList theList, Collection theSet, IndexPattern queryPattern) {
|
|
988 |
59
| if (theSet == null) {
|
|
989 |
0
| return;
|
|
990 |
| } |
|
991 |
| |
|
992 |
59
| for (Iterator aLocatorIterator = theSet.iterator(); aLocatorIterator.hasNext(); ) {
|
|
993 |
70
| ValueLocator aLocator = (ValueLocator) aLocatorIterator.next();
|
|
994 |
70
| if (itsWildcard) {
|
|
995 |
2
| IndexPattern matchElement = new IndexPattern(itsCollection.getSymbols(), aLocator.getElementID(), aLocator.getAttributeID());
|
|
996 |
2
| IndexPattern queryElement = new IndexPattern(itsCollection.getSymbols(), queryPattern.getElementID(),
|
|
997 |
| queryPattern.getAttributeID()); |
|
998 |
2
| if (matchElement.getMatchLevel(queryElement) > 0) {
|
|
999 |
1
| theList.add(new IndexMatch(aLocator.getKey(), aLocator.getElementID(), aLocator.getAttributeID()));
|
|
1000 |
| } |
|
1001 |
| } else { |
|
1002 |
68
| theList.add(new IndexMatch(aLocator.getKey(), aLocator.getElementID(), aLocator.getAttributeID()));
|
|
1003 |
| } |
|
1004 |
| } |
|
1005 |
| } |
|
1006 |
| |
|
1007 |
| |
|
1008 |
| |
|
1009 |
| |
|
1010 |
| |
|
1011 |
| |
|
1012 |
| |
|
1013 |
| |
|
1014 |
| private static class EmptyValue implements Comparable { |
|
1015 |
| |
|
1016 |
| |
|
1017 |
| |
|
1018 |
| |
|
1019 |
0
| EmptyValue() {
|
|
1020 |
| } |
|
1021 |
| |
|
1022 |
| |
|
1023 |
| |
|
1024 |
| |
|
1025 |
| |
|
1026 |
| |
|
1027 |
| |
|
1028 |
| |
|
1029 |
| |
|
1030 |
| |
|
1031 |
0
| public int compareTo(Object theCompareTo) {
|
|
1032 |
0
| if (theCompareTo instanceof EmptyValue) {
|
|
1033 |
0
| return 0;
|
|
1034 |
| } |
|
1035 |
0
| return "".compareTo(theCompareTo.toString());
|
|
1036 |
| } |
|
1037 |
| |
|
1038 |
| |
|
1039 |
| |
|
1040 |
| |
|
1041 |
| |
|
1042 |
| |
|
1043 |
| |
|
1044 |
0
| public boolean equals(Object theCompareTo) {
|
|
1045 |
| |
|
1046 |
0
| if (theCompareTo instanceof EmptyValue) {
|
|
1047 |
0
| return true;
|
|
1048 |
| } |
|
1049 |
| |
|
1050 |
0
| return theCompareTo.toString().length() == 0;
|
|
1051 |
| } |
|
1052 |
| |
|
1053 |
| |
|
1054 |
| |
|
1055 |
| |
|
1056 |
| |
|
1057 |
| |
|
1058 |
0
| public int hashCode() {
|
|
1059 |
0
| return 1;
|
|
1060 |
| } |
|
1061 |
| |
|
1062 |
| |
|
1063 |
| |
|
1064 |
| |
|
1065 |
| |
|
1066 |
| |
|
1067 |
0
| public String toString() {
|
|
1068 |
0
| return EMPTY_STRING;
|
|
1069 |
| } |
|
1070 |
| |
|
1071 |
| |
|
1072 |
| |
|
1073 |
| |
|
1074 |
| |
|
1075 |
| |
|
1076 |
0
| public EmptyValue getInstance() {
|
|
1077 |
0
| return INSTANCE;
|
|
1078 |
| } |
|
1079 |
| |
|
1080 |
| |
|
1081 |
| |
|
1082 |
| |
|
1083 |
| private static final String EMPTY_STRING = ""; |
|
1084 |
| |
|
1085 |
| |
|
1086 |
| |
|
1087 |
| |
|
1088 |
| public final static EmptyValue INSTANCE = new EmptyValue(); |
|
1089 |
| } |
|
1090 |
| |
|
1091 |
| |
|
1092 |
| |
|
1093 |
| |
|
1094 |
| |
|
1095 |
| |
|
1096 |
| private static class ValueComparator implements Comparator { |
|
1097 |
| |
|
1098 |
| |
|
1099 |
| |
|
1100 |
| |
|
1101 |
| |
|
1102 |
| |
|
1103 |
| |
|
1104 |
| |
|
1105 |
| |
|
1106 |
423
| public int compare(Object theObject1, Object theObject2) {
|
|
1107 |
423
| if (theObject1 instanceof Comparable && theObject1.getClass() == theObject2.getClass()) {
|
|
1108 |
423
| return ((Comparable) theObject1).compareTo(theObject2);
|
|
1109 |
| } |
|
1110 |
0
| return theObject1.toString().compareTo(theObject2.toString());
|
|
1111 |
| } |
|
1112 |
| |
|
1113 |
| |
|
1114 |
| |
|
1115 |
| |
|
1116 |
| |
|
1117 |
| |
|
1118 |
| |
|
1119 |
| |
|
1120 |
0
| public boolean equals(Object theCompareTo) {
|
|
1121 |
0
| return theCompareTo instanceof ValueComparator;
|
|
1122 |
| } |
|
1123 |
| |
|
1124 |
| |
|
1125 |
| |
|
1126 |
| |
|
1127 |
| |
|
1128 |
| |
|
1129 |
0
| public ValueComparator getInstance() {
|
|
1130 |
0
| return INSTANCE;
|
|
1131 |
| } |
|
1132 |
| |
|
1133 |
| |
|
1134 |
| |
|
1135 |
| |
|
1136 |
| public static final ValueComparator INSTANCE = new ValueComparator(); |
|
1137 |
| } |
|
1138 |
| |
|
1139 |
| |
|
1140 |
| |
|
1141 |
| |
|
1142 |
| |
|
1143 |
| |
|
1144 |
| private class ValueLocator implements Comparable { |
|
1145 |
| |
|
1146 |
| |
|
1147 |
| |
|
1148 |
| |
|
1149 |
| private Key itsKey; |
|
1150 |
| |
|
1151 |
| |
|
1152 |
| |
|
1153 |
| |
|
1154 |
| private final int itsPosition; |
|
1155 |
| |
|
1156 |
| |
|
1157 |
| |
|
1158 |
| |
|
1159 |
| private final int itsLength; |
|
1160 |
| |
|
1161 |
| |
|
1162 |
| |
|
1163 |
| |
|
1164 |
| private final short itsElementID; |
|
1165 |
| |
|
1166 |
| |
|
1167 |
| |
|
1168 |
| |
|
1169 |
| private final short itsAttributeID; |
|
1170 |
| |
|
1171 |
| |
|
1172 |
| |
|
1173 |
| |
|
1174 |
| |
|
1175 |
| |
|
1176 |
| |
|
1177 |
| |
|
1178 |
| |
|
1179 |
| |
|
1180 |
| |
|
1181 |
| |
|
1182 |
| |
|
1183 |
| |
|
1184 |
104
| public ValueLocator(Key theKey, int thePosition, int theLength, short theElementID, short theAttributeID) {
|
|
1185 |
104
| itsKey = theKey;
|
|
1186 |
104
| itsPosition = thePosition;
|
|
1187 |
104
| itsLength = theLength;
|
|
1188 |
104
| itsElementID = theElementID;
|
|
1189 |
104
| itsAttributeID = theAttributeID;
|
|
1190 |
| } |
|
1191 |
| |
|
1192 |
| |
|
1193 |
| |
|
1194 |
| |
|
1195 |
| |
|
1196 |
| |
|
1197 |
69
| public Key getKey() {
|
|
1198 |
69
| return itsKey;
|
|
1199 |
| } |
|
1200 |
| |
|
1201 |
| |
|
1202 |
| |
|
1203 |
| |
|
1204 |
| |
|
1205 |
| |
|
1206 |
0
| public final int getPosition() {
|
|
1207 |
0
| return itsPosition;
|
|
1208 |
| } |
|
1209 |
| |
|
1210 |
| |
|
1211 |
| |
|
1212 |
| |
|
1213 |
| |
|
1214 |
| |
|
1215 |
0
| public final int getLength() {
|
|
1216 |
0
| return itsLength;
|
|
1217 |
| } |
|
1218 |
| |
|
1219 |
| |
|
1220 |
| |
|
1221 |
| |
|
1222 |
| |
|
1223 |
| |
|
1224 |
71
| public final short getElementID() {
|
|
1225 |
71
| return itsElementID;
|
|
1226 |
| } |
|
1227 |
| |
|
1228 |
| |
|
1229 |
| |
|
1230 |
| |
|
1231 |
| |
|
1232 |
| |
|
1233 |
71
| public final short getAttributeID() {
|
|
1234 |
71
| return itsAttributeID;
|
|
1235 |
| } |
|
1236 |
| |
|
1237 |
| |
|
1238 |
| |
|
1239 |
| |
|
1240 |
| |
|
1241 |
| |
|
1242 |
| |
|
1243 |
| |
|
1244 |
| |
|
1245 |
| |
|
1246 |
| |
|
1247 |
| |
|
1248 |
| |
|
1249 |
| |
|
1250 |
| |
|
1251 |
| |
|
1252 |
| |
|
1253 |
| |
|
1254 |
| |
|
1255 |
| |
|
1256 |
| |
|
1257 |
| |
|
1258 |
| |
|
1259 |
| |
|
1260 |
| |
|
1261 |
| |
|
1262 |
| |
|
1263 |
| |
|
1264 |
| |
|
1265 |
| |
|
1266 |
| |
|
1267 |
| |
|
1268 |
| |
|
1269 |
16
| public final int compareTo(Object theObject) {
|
|
1270 |
16
| if (!(theObject instanceof ValueLocator)) {
|
|
1271 |
0
| throw new ClassCastException("Can't compare object of type " + theObject.getClass().getName() + " to ValueLocator");
|
|
1272 |
| } |
|
1273 |
| |
|
1274 |
16
| ValueLocator aCompareTo = (ValueLocator) theObject;
|
|
1275 |
| |
|
1276 |
| |
|
1277 |
16
| int result = itsKey.compareTo(aCompareTo.itsKey);
|
|
1278 |
16
| if (result != 0) {
|
|
1279 |
15
| return result;
|
|
1280 |
| } |
|
1281 |
| |
|
1282 |
| |
|
1283 |
1
| if (itsPosition != aCompareTo.itsPosition) {
|
|
1284 |
0
| return itsPosition > aCompareTo.itsPosition ? 1 : -1;
|
|
1285 |
| } |
|
1286 |
| |
|
1287 |
| |
|
1288 |
1
| if (itsLength != aCompareTo.itsLength) {
|
|
1289 |
0
| return itsLength > aCompareTo.itsLength ? 1 : -1;
|
|
1290 |
| } |
|
1291 |
| |
|
1292 |
| |
|
1293 |
1
| if (itsElementID != aCompareTo.itsElementID) {
|
|
1294 |
0
| return itsElementID > aCompareTo.itsElementID ? 1 : -1;
|
|
1295 |
| } |
|
1296 |
| |
|
1297 |
| |
|
1298 |
1
| if (itsAttributeID != aCompareTo.itsAttributeID) {
|
|
1299 |
0
| return itsAttributeID > aCompareTo.itsAttributeID ? 1 : -1;
|
|
1300 |
| } |
|
1301 |
| |
|
1302 |
| |
|
1303 |
1
| return 0;
|
|
1304 |
| } |
|
1305 |
| } |
|
1306 |
| } |