| 1 | // CollationKey.java - Sort key for locale-sensitive String.
|
|---|
| 2 |
|
|---|
| 3 | /* Copyright (C) 1999, 2000 Free Software Foundation
|
|---|
| 4 |
|
|---|
| 5 | This file is part of libgcj.
|
|---|
| 6 |
|
|---|
| 7 | This software is copyrighted work licensed under the terms of the
|
|---|
| 8 | Libgcj License. Please consult the file "LIBGCJ_LICENSE" for
|
|---|
| 9 | details. */
|
|---|
| 10 |
|
|---|
| 11 | package java.text;
|
|---|
| 12 |
|
|---|
| 13 | /**
|
|---|
| 14 | * @author Tom Tromey <[email protected]>
|
|---|
| 15 | * @date March 25, 1999
|
|---|
| 16 | */
|
|---|
| 17 | /* Written using "Java Class Libraries", 2nd edition, plus online
|
|---|
| 18 | * API docs for JDK 1.2 from http://www.javasoft.com.
|
|---|
| 19 | * Status: Believed complete and correct.
|
|---|
| 20 | */
|
|---|
| 21 |
|
|---|
| 22 | public final class CollationKey implements Comparable
|
|---|
| 23 | {
|
|---|
| 24 | public int compareTo (CollationKey target)
|
|---|
| 25 | {
|
|---|
| 26 | int max = Math.min(key.length, target.key.length);
|
|---|
| 27 |
|
|---|
| 28 | for (int i = 0; i < max; ++i)
|
|---|
| 29 | {
|
|---|
| 30 | if (key[i] != target.key[i])
|
|---|
| 31 | return key[i] - target.key[i];
|
|---|
| 32 | }
|
|---|
| 33 |
|
|---|
| 34 | return key.length - target.key.length;
|
|---|
| 35 | }
|
|---|
| 36 |
|
|---|
| 37 | public int compareTo (Object o)
|
|---|
| 38 | {
|
|---|
| 39 | return compareTo ((CollationKey) o);
|
|---|
| 40 | }
|
|---|
| 41 |
|
|---|
| 42 | public boolean equals (Object obj)
|
|---|
| 43 | {
|
|---|
| 44 | if (! (obj instanceof CollationKey))
|
|---|
| 45 | return false;
|
|---|
| 46 |
|
|---|
| 47 | CollationKey ck = (CollationKey) obj;
|
|---|
| 48 |
|
|---|
| 49 | if (key.length != ck.key.length)
|
|---|
| 50 | return false;
|
|---|
| 51 |
|
|---|
| 52 | for (int i = 0; i < key.length; ++i)
|
|---|
|
|---|