Line 0
Link Here
|
|
|
1 |
/* |
2 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. |
3 |
* |
4 |
* Copyright 1997-2009 Sun Microsystems, Inc. All rights reserved. |
5 |
* |
6 |
* The contents of this file are subject to the terms of either the GNU |
7 |
* General Public License Version 2 only ("GPL") or the Common |
8 |
* Development and Distribution License("CDDL") (collectively, the |
9 |
* "License"). You may not use this file except in compliance with the |
10 |
* License. You can obtain a copy of the License at |
11 |
* http://www.netbeans.org/cddl-gplv2.html |
12 |
* or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the |
13 |
* specific language governing permissions and limitations under the |
14 |
* License. When distributing the software, include this License Header |
15 |
* Notice in each file and include the License file at |
16 |
* nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this |
17 |
* particular file as subject to the "Classpath" exception as provided |
18 |
* by Sun in the GPL Version 2 section of the License file that |
19 |
* accompanied this code. If applicable, add the following below the |
20 |
* License Header, with the fields enclosed by brackets [] replaced by |
21 |
* your own identifying information: |
22 |
* "Portions Copyrighted [year] [name of copyright owner]" |
23 |
* |
24 |
* If you wish your version of this file to be governed by only the CDDL |
25 |
* or only the GPL Version 2, indicate your decision by adding |
26 |
* "[Contributor] elects to include this software in this distribution |
27 |
* under the [CDDL or GPL Version 2] license." If you do not indicate a |
28 |
* single choice of license, a recipient has the option to distribute |
29 |
* your version of this file under either the CDDL, the GPL Version 2 or |
30 |
* to extend the choice of license to its licensees as provided above. |
31 |
* However, if you add GPL Version 2 code and therefore, elected the GPL |
32 |
* Version 2 license, then the option applies only if the new code is |
33 |
* made subject to such option by the copyright holder. |
34 |
* |
35 |
* Contributor(s): |
36 |
* |
37 |
* Portions Copyrighted 2007 Sun Microsystems, Inc. |
38 |
*/ |
39 |
|
40 |
package org.netbeans.modules.masterfs.filebasedfs.naming; |
41 |
|
42 |
import java.util.Arrays; |
43 |
import java.util.Comparator; |
44 |
|
45 |
/** |
46 |
* |
47 |
* @author Alexander Simon |
48 |
*/ |
49 |
public final class CompactString implements CompactCharSequence, Comparable<CharSequence> { |
50 |
private static final CompactCharSequence EMPTY = new CompactString(new byte[]{}); |
51 |
public static final Comparator<CharSequence> Comparator = new CharSequenceComparator(); |
52 |
public static final Comparator<CharSequence> ComparatorIgnoreCase = new CharSequenceComparatorIgnoreCase(); |
53 |
private final Object value; |
54 |
private int hash; |
55 |
|
56 |
public static CharSequence create(char buf[], int start, int count) { |
57 |
if (start < 0) { |
58 |
throw new StringIndexOutOfBoundsException(start); |
59 |
} |
60 |
if (count < 0) { |
61 |
throw new StringIndexOutOfBoundsException(count); |
62 |
} |
63 |
// Note: offset or count might be near -1>>>1. |
64 |
if (start > buf.length - count) { |
65 |
throw new StringIndexOutOfBoundsException(start + count); |
66 |
} |
67 |
int n = count; |
68 |
if (n == 0) { |
69 |
return EMPTY; |
70 |
} |
71 |
byte[] b = new byte[n]; |
72 |
boolean bytes = true; |
73 |
int o; |
74 |
for (int i = 0; i < n; i++) { |
75 |
o = buf[start + i]; |
76 |
if ((o & 0xFF) != o) { |
77 |
bytes = false; |
78 |
break; |
79 |
} |
80 |
b[i] = (byte) o; |
81 |
} |
82 |
if (bytes) { |
83 |
return createFromBytes(b, n); |
84 |
} |
85 |
char[] v = new char[count]; |
86 |
System.arraycopy(buf, start, v, 0, count); |
87 |
return new CompactString(v); |
88 |
} |
89 |
|
90 |
public static CharSequence create(CharSequence s) { |
91 |
if (s == null) { |
92 |
return null; |
93 |
} |
94 |
//return s.toString(); |
95 |
if (s instanceof CompactCharSequence) { |
96 |
return s; |
97 |
} |
98 |
int n = s.length(); |
99 |
if (n == 0) { |
100 |
return EMPTY; |
101 |
} |
102 |
byte[] b = new byte[n]; |
103 |
boolean bytes = true; |
104 |
int o; |
105 |
for(int i = 0; i < n; i++){ |
106 |
o = s.charAt(i); |
107 |
if ( (o & 0xFF) != o){ |
108 |
bytes = false; |
109 |
break; |
110 |
} |
111 |
b[i] = (byte)o; |
112 |
} |
113 |
if (bytes) { |
114 |
return createFromBytes(b, n); |
115 |
} |
116 |
char[] v = new char[n]; |
117 |
for(int i = 0; i < n; i++){ |
118 |
v[i] = s.charAt(i); |
119 |
} |
120 |
return new CompactString(v); |
121 |
} |
122 |
|
123 |
public static CharSequence empty(){ |
124 |
return EMPTY; |
125 |
} |
126 |
|
127 |
/** |
128 |
* Implementation of {@link String#indexOf(String)} for character sequences. |
129 |
*/ |
130 |
public static int indexOf(CharSequence text, CharSequence seq) { |
131 |
return indexOf(text, seq, 0); |
132 |
} |
133 |
|
134 |
/** |
135 |
* Implementation of {@link String#indexOf(String,int)} for character sequences. |
136 |
*/ |
137 |
public static int indexOf(CharSequence text, CharSequence seq, int fromIndex) { |
138 |
int textLength = text.length(); |
139 |
int seqLength = seq.length(); |
140 |
if (fromIndex >= textLength) { |
141 |
return (seqLength == 0 ? textLength : -1); |
142 |
} |
143 |
if (fromIndex < 0) { |
144 |
fromIndex = 0; |
145 |
} |
146 |
if (seqLength == 0) { |
147 |
return fromIndex; |
148 |
} |
149 |
|
150 |
char first = seq.charAt(0); |
151 |
int max = textLength - seqLength; |
152 |
|
153 |
for (int i = fromIndex; i <= max; i++) { |
154 |
// look for first character |
155 |
if (text.charAt(i) != first) { |
156 |
while (++i <= max && text.charAt(i) != first) {} |
157 |
} |
158 |
|
159 |
// found first character, now look at the rest of seq |
160 |
if (i <= max) { |
161 |
int j = i + 1; |
162 |
int end = j + seqLength - 1; |
163 |
for (int k = 1; j < end && text.charAt(j) == seq.charAt(k); j++, k++) {} |
164 |
if (j == end) { |
165 |
// found whole sequence |
166 |
return i; |
167 |
} |
168 |
} |
169 |
} |
170 |
return -1; |
171 |
} |
172 |
|
173 |
public static String toString(CharSequence prefix, char separator, CharSequence postfix) { |
174 |
int prefLength = prefix.length(); |
175 |
int postLength = postfix.length(); |
176 |
char[] chars = new char[prefLength + 1 + postLength]; |
177 |
int indx = 0; |
178 |
if (prefix instanceof String) { |
179 |
((String)prefix).getChars(0, prefLength, chars, indx); |
180 |
indx = prefLength; |
181 |
} else { |
182 |
for (int i = 0; i < prefLength; i++) { |
183 |
chars[indx++] = prefix.charAt(i); |
184 |
} |
185 |
} |
186 |
chars[indx++] = separator; |
187 |
if (postfix instanceof String) { |
188 |
((String)postfix).getChars(0, postLength, chars, indx); |
189 |
} else { |
190 |
for (int i = 0; i < postLength; i++) { |
191 |
chars[indx++] = postfix.charAt(i); |
192 |
} |
193 |
} |
194 |
return new String(chars); |
195 |
} |
196 |
|
197 |
private static CompactCharSequence createFromBytes(byte[] b, int n) { |
198 |
if (n < 8) { |
199 |
return new Fixed7CharSequenceKey(b, n); |
200 |
} else if (n < 16) { |
201 |
return new Fixed15CharSequenceKey(b, n); |
202 |
} else if (n < 24) { |
203 |
return new Fixed23CharSequenceKey(b, n); |
204 |
} |
205 |
return new CompactString(b); |
206 |
} |
207 |
|
208 |
private CompactString(byte[] b) { |
209 |
value = b; |
210 |
} |
211 |
|
212 |
private CompactString(char[] v) { |
213 |
value = v; |
214 |
} |
215 |
|
216 |
@Override |
217 |
public int length() { |
218 |
if (value instanceof byte[]) { |
219 |
return ((byte[]) value).length; |
220 |
} |
221 |
return ((char[]) value).length; |
222 |
} |
223 |
|
224 |
@Override |
225 |
public char charAt(int index) { |
226 |
if (value instanceof byte[]) { |
227 |
int r = ((byte[]) value)[index] & 0xFF; |
228 |
return (char) r; |
229 |
} |
230 |
return ((char[]) value)[index]; |
231 |
} |
232 |
|
233 |
@Override |
234 |
public boolean equals(Object object) { |
235 |
if (this == object) { |
236 |
return true; |
237 |
} |
238 |
if (object instanceof CompactString) { |
239 |
CompactString otherString = (CompactString)object; |
240 |
if (hash != 0 && otherString.hash != 0) { |
241 |
if (hash != otherString.hash) { |
242 |
return false; |
243 |
} |
244 |
} |
245 |
if ((value instanceof byte[]) && (otherString.value instanceof byte[])) { |
246 |
return Arrays.equals( (byte[])value, (byte[])otherString.value ); |
247 |
} else if ((value instanceof char[]) && (otherString.value instanceof char[])) { |
248 |
return Arrays.equals( (char[])value, (char[])otherString.value ); |
249 |
} |
250 |
} |
251 |
return false; |
252 |
} |
253 |
|
254 |
@Override |
255 |
public int hashCode() { |
256 |
int h = hash; |
257 |
if (h == 0) { |
258 |
if (value instanceof byte[]) { |
259 |
byte[] v = (byte[])value; |
260 |
int n = v.length; |
261 |
for (int i = 0; i < n; i++) { |
262 |
h = 31*h + v[i]; |
263 |
} |
264 |
} else { |
265 |
char[] v = (char[])value; |
266 |
int n = v.length; |
267 |
for (int i = 0; i < n; i++) { |
268 |
h = 31*h + v[i]; |
269 |
} |
270 |
} |
271 |
hash = h; |
272 |
} |
273 |
return h; |
274 |
} |
275 |
|
276 |
@Override |
277 |
public CharSequence subSequence(int beginIndex, int endIndex) { |
278 |
return create(toString().substring(beginIndex, endIndex)); |
279 |
} |
280 |
|
281 |
@Override |
282 |
public String toString() { |
283 |
if (value instanceof byte[]) { |
284 |
byte[] v = (byte[]) value; |
285 |
int n = v.length; |
286 |
char[] r = new char[n]; |
287 |
for (int i = 0; i < n; i++) { |
288 |
int c = v[i] & 0xFF; |
289 |
r[i] = (char) c; |
290 |
} |
291 |
return new String(r); |
292 |
} |
293 |
char[] v = (char[]) value; |
294 |
return new String(v); |
295 |
} |
296 |
|
297 |
private static class CharSequenceComparator implements Comparator<CharSequence> { |
298 |
@Override |
299 |
public int compare(CharSequence o1, CharSequence o2) { |
300 |
if ((o1 instanceof CompactString)){ |
301 |
if ((o2 instanceof CompactString)){ |
302 |
CompactString csk1 = (CompactString) o1; |
303 |
CompactString csk2 = (CompactString) o2; |
304 |
if ((csk1.value instanceof byte[]) && |
305 |
(csk2.value instanceof byte[])){ |
306 |
byte[] b1 = (byte[]) csk1.value; |
307 |
byte[] b2 = (byte[]) csk2.value; |
308 |
int len1 = b1.length; |
309 |
int len2 = b2.length; |
310 |
int n = Math.min(len1, len2); |
311 |
int k = 0; |
312 |
while (k < n) { |
313 |
if (b1[k] != b2[k]) { |
314 |
return (b1[k] & 0xFF) - (b2[k] & 0xFF); |
315 |
} |
316 |
k++; |
317 |
} |
318 |
return len1 - len2; |
319 |
} |
320 |
} else { |
321 |
CompactString csk1 = (CompactString) o1; |
322 |
if ((csk1.value instanceof byte[])){ |
323 |
byte[] b1 = (byte[]) csk1.value; |
324 |
int len1 = b1.length; |
325 |
int len2 = o2.length(); |
326 |
int n = Math.min(len1, len2); |
327 |
int k = 0; |
328 |
int c1,c2; |
329 |
while (k < n) { |
330 |
c1 = b1[k] & 0xFF; |
331 |
c2 = o2.charAt(k); |
332 |
if (c1 != c2) { |
333 |
return c1 - c2; |
334 |
} |
335 |
k++; |
336 |
} |
337 |
return len1 - len2; |
338 |
} |
339 |
} |
340 |
} else if ((o2 instanceof CompactString)){ |
341 |
CompactString csk2 = (CompactString) o2; |
342 |
if ((csk2.value instanceof byte[])){ |
343 |
byte[] b2 = (byte[]) csk2.value; |
344 |
int len1 = o1.length(); |
345 |
int len2 = b2.length; |
346 |
int n = Math.min(len1, len2); |
347 |
int k = 0; |
348 |
int c1,c2; |
349 |
while (k < n) { |
350 |
c1 = o1.charAt(k); |
351 |
c2 = b2[k] & 0xFF; |
352 |
if (c1 != c2) { |
353 |
return c1 - c2; |
354 |
} |
355 |
k++; |
356 |
} |
357 |
return len1 - len2; |
358 |
} |
359 |
} |
360 |
int len1 = o1.length(); |
361 |
int len2 = o2.length(); |
362 |
int n = Math.min(len1, len2); |
363 |
int k = 0; |
364 |
while (k < n) { |
365 |
char c1 = o1.charAt(k); |
366 |
char c2 = o2.charAt(k); |
367 |
if (c1 != c2) { |
368 |
return c1 - c2; |
369 |
} |
370 |
k++; |
371 |
} |
372 |
return len1 - len2; |
373 |
} |
374 |
} |
375 |
|
376 |
@Override |
377 |
public int compareTo(CharSequence o) { |
378 |
return Comparator.compare(this, o); |
379 |
} |
380 |
|
381 |
private static class CharSequenceComparatorIgnoreCase implements Comparator<CharSequence> { |
382 |
@Override |
383 |
public int compare(CharSequence o1, CharSequence o2) { |
384 |
int n1 = o1.length(); |
385 |
int n2 = o2.length(); |
386 |
for (int i1 = 0, i2 = 0; i1 < n1 && i2 < n2; i1++, i2++) { |
387 |
char c1 = o1.charAt(i1); |
388 |
char c2 = o2.charAt(i2); |
389 |
if (c1 != c2) { |
390 |
c1 = Character.toUpperCase(c1); |
391 |
c2 = Character.toUpperCase(c2); |
392 |
if (c1 != c2) { |
393 |
c1 = Character.toLowerCase(c1); |
394 |
c2 = Character.toLowerCase(c2); |
395 |
if (c1 != c2) { |
396 |
return c1 - c2; |
397 |
} |
398 |
} |
399 |
} |
400 |
} |
401 |
return n1 - n2; |
402 |
} |
403 |
} |
404 |
|
405 |
private static final class Fixed7CharSequenceKey implements CompactCharSequence, Comparable<CharSequence> { |
406 |
private final int i1; |
407 |
private final int i2; |
408 |
|
409 |
@SuppressWarnings("fallthrough") |
410 |
private Fixed7CharSequenceKey(byte[] b, int n){ |
411 |
int a1 = n; |
412 |
int a2 = 0; |
413 |
switch (n){ |
414 |
case 7: |
415 |
a2+=(b[6]&0xFF)<<24; |
416 |
case 6: |
417 |
a2+=(b[5]&0xFF)<<16; |
418 |
case 5: |
419 |
a2+=(b[4]&0xFF)<<8; |
420 |
case 4: |
421 |
a2+=b[3]&0xFF; |
422 |
case 3: |
423 |
a1+=(b[2]&0xFF)<<24; |
424 |
case 2: |
425 |
a1+=(b[1]&0xFF)<<16; |
426 |
case 1: |
427 |
a1+=(b[0]&0xFF)<<8; |
428 |
case 0: |
429 |
break; |
430 |
default: |
431 |
throw new IllegalArgumentException(); |
432 |
} |
433 |
i1 = a1; |
434 |
i2 = a2; |
435 |
} |
436 |
|
437 |
@Override |
438 |
public int length() { |
439 |
return i1&0xFF; |
440 |
} |
441 |
|
442 |
@Override |
443 |
public char charAt(int index) { |
444 |
int r = 0; |
445 |
switch(index) { |
446 |
case 0: r =(i1&0xFF00)>>8; break; |
447 |
case 1: r =(i1&0xFF0000)>>16; break; |
448 |
case 2: r =(i1>>24)&0xFF; break; |
449 |
case 3: r =i2&0xFF; break; |
450 |
case 4: r =(i2&0xFF00)>>8; break; |
451 |
case 5: r =(i2&0xFF0000)>>16; break; |
452 |
case 6: r =(i2>>24)&0xFF; break; |
453 |
} |
454 |
return (char)r; |
455 |
} |
456 |
|
457 |
@Override |
458 |
public String toString() { |
459 |
int n = length(); |
460 |
char[] r = new char[n]; |
461 |
for (int i = 0; i < n; i++) { |
462 |
r[i] = charAt(i); |
463 |
} |
464 |
return new String(r); |
465 |
} |
466 |
|
467 |
@Override |
468 |
public boolean equals(Object object) { |
469 |
if (this == object) { |
470 |
return true; |
471 |
} |
472 |
if (object instanceof Fixed7CharSequenceKey) { |
473 |
Fixed7CharSequenceKey otherString = (Fixed7CharSequenceKey)object; |
474 |
return i1 == otherString.i1 && i2 == otherString.i2; |
475 |
} |
476 |
return false; |
477 |
} |
478 |
|
479 |
@Override |
480 |
public int hashCode() { |
481 |
int hash = 0; |
482 |
for (int i = 0; i < length(); i++) { |
483 |
hash = 31*hash+charAt(i); |
484 |
} |
485 |
return hash; |
486 |
// return (i1 >> 4) + (i1 >> 8) + (i2 << 5) - i2; |
487 |
} |
488 |
|
489 |
@Override |
490 |
public CharSequence subSequence(int start, int end) { |
491 |
return CompactString.create(toString().substring(start, end)); |
492 |
} |
493 |
|
494 |
@Override |
495 |
public int compareTo(CharSequence o) { |
496 |
return Comparator.compare(this, o); |
497 |
} |
498 |
} |
499 |
|
500 |
private static final class Fixed15CharSequenceKey implements CompactCharSequence, Comparable<CharSequence> { |
501 |
private final int i1; |
502 |
private final int i2; |
503 |
private final int i3; |
504 |
private final int i4; |
505 |
|
506 |
@SuppressWarnings("fallthrough") |
507 |
private Fixed15CharSequenceKey(byte[] b, int n){ |
508 |
int a1 = n; |
509 |
int a2 = 0; |
510 |
int a3 = 0; |
511 |
int a4 = 0; |
512 |
switch (n){ |
513 |
case 15: |
514 |
a4+=(b[14]&0xFF)<<24; |
515 |
case 14: |
516 |
a4+=(b[13]&0xFF)<<16; |
517 |
case 13: |
518 |
a4+=(b[12]&0xFF)<<8; |
519 |
case 12: |
520 |
a4+=b[11]&0xFF; |
521 |
case 11: |
522 |
a3+=(b[10]&0xFF)<<24; |
523 |
case 10: |
524 |
a3+=(b[9]&0xFF)<<16; |
525 |
case 9: |
526 |
a3+=(b[8]&0xFF)<<8; |
527 |
case 8: |
528 |
a3+=b[7]&0xFF; |
529 |
case 7: |
530 |
a2+=(b[6]&0xFF)<<24; |
531 |
case 6: |
532 |
a2+=(b[5]&0xFF)<<16; |
533 |
case 5: |
534 |
a2+=(b[4]&0xFF)<<8; |
535 |
case 4: |
536 |
a2+=b[3]&0xFF; |
537 |
case 3: |
538 |
a1+=(b[2]&0xFF)<<24; |
539 |
case 2: |
540 |
a1+=(b[1]&0xFF)<<16; |
541 |
case 1: |
542 |
a1+=(b[0]&0xFF)<<8; |
543 |
case 0: |
544 |
break; |
545 |
default: |
546 |
throw new IllegalArgumentException(); |
547 |
} |
548 |
i1 = a1; |
549 |
i2 = a2; |
550 |
i3 = a3; |
551 |
i4 = a4; |
552 |
} |
553 |
|
554 |
@Override |
555 |
public int length() { |
556 |
return i1&0xFF; |
557 |
} |
558 |
|
559 |
@Override |
560 |
public char charAt(int index) { |
561 |
int r = 0; |
562 |
switch(index) { |
563 |
case 0: r =(i1&0xFF00)>>8; break; |
564 |
case 1: r =(i1&0xFF0000)>>16; break; |
565 |
case 2: r =(i1>>24)&0xFF; break; |
566 |
case 3: r =i2&0xFF; break; |
567 |
case 4: r =(i2&0xFF00)>>8; break; |
568 |
case 5: r =(i2&0xFF0000)>>16; break; |
569 |
case 6: r =(i2>>24)&0xFF; break; |
570 |
case 7: r =i3&0xFF; break; |
571 |
case 8: r =(i3&0xFF00)>>8; break; |
572 |
case 9: r =(i3&0xFF0000)>>16; break; |
573 |
case 10: r =(i3>>24)&0xFF; break; |
574 |
case 11: r =i4&0xFF; break; |
575 |
case 12: r =(i4&0xFF00)>>8; break; |
576 |
case 13: r =(i4&0xFF0000)>>16; break; |
577 |
case 14: r =(i4>>24)&0xFF; break; |
578 |
} |
579 |
return (char)r; |
580 |
} |
581 |
|
582 |
@Override |
583 |
public String toString() { |
584 |
int n = length(); |
585 |
char[] r = new char[n]; |
586 |
for (int i = 0; i < n; i++) { |
587 |
r[i] = charAt(i); |
588 |
} |
589 |
return new String(r); |
590 |
} |
591 |
|
592 |
@Override |
593 |
public boolean equals(Object object) { |
594 |
if (this == object) { |
595 |
return true; |
596 |
} |
597 |
if (object instanceof Fixed15CharSequenceKey) { |
598 |
Fixed15CharSequenceKey otherString = (Fixed15CharSequenceKey)object; |
599 |
return i1 == otherString.i1 && i2 == otherString.i2 && i3 == otherString.i3 && i4 == otherString.i4; |
600 |
} |
601 |
return false; |
602 |
} |
603 |
|
604 |
@Override |
605 |
public int hashCode() { |
606 |
return i1+31*(i2+ 31*(i3+31*i4)); |
607 |
} |
608 |
|
609 |
@Override |
610 |
public CharSequence subSequence(int start, int end) { |
611 |
return CompactString.create(toString().substring(start, end)); |
612 |
} |
613 |
|
614 |
@Override |
615 |
public int compareTo(CharSequence o) { |
616 |
return Comparator.compare(this, o); |
617 |
} |
618 |
} |
619 |
|
620 |
private static final class Fixed23CharSequenceKey implements CompactCharSequence, Comparable<CharSequence> { |
621 |
private final long i1; |
622 |
private final long i2; |
623 |
private final long i3; |
624 |
|
625 |
@SuppressWarnings("fallthrough") |
626 |
private Fixed23CharSequenceKey(byte[] b, int n){ |
627 |
long a1 = 0; |
628 |
long a2 = 0; |
629 |
long a3 = 0; |
630 |
switch (n){ |
631 |
case 23: |
632 |
a3+=(b[22]&0xFF)<<24; |
633 |
case 22: |
634 |
a3+=(b[21]&0xFF)<<16; |
635 |
case 21: |
636 |
a3+=(b[20]&0xFF)<<8; |
637 |
case 20: |
638 |
a3+=(b[19]&0xFF); |
639 |
a3<<=32; |
640 |
case 19: |
641 |
a3+=(b[18]&0xFF)<<24; |
642 |
case 18: |
643 |
a3+=(b[17]&0xFF)<<16; |
644 |
case 17: |
645 |
a3+=(b[16]&0xFF)<<8; |
646 |
case 16: |
647 |
a3+=b[15]&0xFF; |
648 |
case 15: |
649 |
a2+=(b[14]&0xFF)<<24; |
650 |
case 14: |
651 |
a2+=(b[13]&0xFF)<<16; |
652 |
case 13: |
653 |
a2+=(b[12]&0xFF)<<8; |
654 |
case 12: |
655 |
a2+=(b[11]&0xFF); |
656 |
a2<<=32; |
657 |
case 11: |
658 |
a2+=(b[10]&0xFF)<<24; |
659 |
case 10: |
660 |
a2+=(b[9]&0xFF)<<16; |
661 |
case 9: |
662 |
a2+=(b[8]&0xFF)<<8; |
663 |
case 8: |
664 |
a2+=b[7]&0xFF; |
665 |
case 7: |
666 |
a1+=(b[6]&0xFF)<<24; |
667 |
case 6: |
668 |
a1+=(b[5]&0xFF)<<16; |
669 |
case 5: |
670 |
a1+=(b[4]&0xFF)<<8; |
671 |
case 4: |
672 |
a1+=(b[3]&0xFF); |
673 |
a1<<=32; |
674 |
case 3: |
675 |
a1+=(b[2]&0xFF)<<24; |
676 |
case 2: |
677 |
a1+=(b[1]&0xFF)<<16; |
678 |
case 1: |
679 |
a1+=(b[0]&0xFF)<<8; |
680 |
case 0: |
681 |
a1+=n; |
682 |
break; |
683 |
default: |
684 |
throw new IllegalArgumentException(); |
685 |
} |
686 |
i1 = a1; |
687 |
i2 = a2; |
688 |
i3 = a3; |
689 |
} |
690 |
|
691 |
@Override |
692 |
public int length() { |
693 |
return (int) (i1 & 0xFF); |
694 |
} |
695 |
|
696 |
@Override |
697 |
public char charAt(int index) { |
698 |
int r = 0; |
699 |
switch(index) { |
700 |
case 0: r = (int) ((i1 >> 8) & 0xFFL); break; |
701 |
case 1: r = (int) ((i1 >> 16) & 0xFFL); break; |
702 |
case 2: r = (int) ((i1 >> 24) & 0xFFL); break; |
703 |
case 3: r = (int) ((i1 >> 32) & 0xFFL); break; |
704 |
case 4: r = (int) ((i1 >> 40) & 0xFFL); break; |
705 |
case 5: r = (int) ((i1 >> 48) & 0xFFL); break; |
706 |
case 6: r = (int) ((i1 >> 56) & 0xFFL); break; |
707 |
case 7: r = (int) (i2 & 0xFFL); break; |
708 |
case 8: r = (int) ((i2 >> 8) & 0xFFL); break; |
709 |
case 9: r = (int) ((i2 >> 16) & 0xFFL); break; |
710 |
case 10: r = (int) ((i2 >> 24) & 0xFFL); break; |
711 |
case 11: r = (int) ((i2 >> 32) & 0xFFL); break; |
712 |
case 12: r = (int) ((i2 >> 40) & 0xFFL); break; |
713 |
case 13: r = (int) ((i2 >> 48) & 0xFFL); break; |
714 |
case 14: r = (int) ((i2 >> 56) & 0xFFL); break; |
715 |
case 15: r = (int) (i3 & 0xFFL); break; |
716 |
case 16: r = (int) ((i3 >> 8) & 0xFFL); break; |
717 |
case 17: r = (int) ((i3 >> 16) & 0xFFL); break; |
718 |
case 18: r = (int) ((i3 >> 24) & 0xFFL); break; |
719 |
case 19: r = (int) ((i3 >> 32) & 0xFFL); break; |
720 |
case 20: r = (int) ((i3 >> 40) & 0xFFL); break; |
721 |
case 21: r = (int) ((i3 >> 48) & 0xFFL); break; |
722 |
case 22: r = (int) ((i3 >> 56) & 0xFFL); break; |
723 |
} |
724 |
return (char)r; |
725 |
} |
726 |
|
727 |
@Override |
728 |
public String toString() { |
729 |
int n = length(); |
730 |
char[] r = new char[n]; |
731 |
for (int i = 0; i < n; i++) { |
732 |
r[i] = charAt(i); |
733 |
} |
734 |
return new String(r); |
735 |
} |
736 |
|
737 |
@Override |
738 |
public boolean equals(Object object) { |
739 |
if (this == object) { |
740 |
return true; |
741 |
} |
742 |
if (object instanceof Fixed23CharSequenceKey) { |
743 |
Fixed23CharSequenceKey otherString = (Fixed23CharSequenceKey)object; |
744 |
return i1 == otherString.i1 && i2 == otherString.i2 && i3 == otherString.i3; |
745 |
} |
746 |
return false; |
747 |
} |
748 |
|
749 |
@Override |
750 |
public int hashCode() { |
751 |
long res = i1+31*(i2+ 31*i3); |
752 |
res = (res + (res >>32))& 0xFFFFFFFFL; |
753 |
return (int) res; |
754 |
} |
755 |
|
756 |
@Override |
757 |
public CharSequence subSequence(int start, int end) { |
758 |
return CompactString.create(toString().substring(start, end)); |
759 |
} |
760 |
|
761 |
@Override |
762 |
public int compareTo(CharSequence o) { |
763 |
return Comparator.compare(this, o); |
764 |
} |
765 |
} |
766 |
} |