author | stefank |
Mon, 25 Aug 2014 09:10:13 +0200 | |
changeset 26314 | f8bc1966fb30 |
parent 10836 | d9ac699afc2a |
child 40801 | 9bf0aafeb2bb |
permissions | -rw-r--r-- |
10836
d9ac699afc2a
6755060: Collator.compare() does not compare correctly for the Thai locale
yhuang
parents:
diff
changeset
|
1 |
/* |
d9ac699afc2a
6755060: Collator.compare() does not compare correctly for the Thai locale
yhuang
parents:
diff
changeset
|
2 |
* Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved. |
d9ac699afc2a
6755060: Collator.compare() does not compare correctly for the Thai locale
yhuang
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
d9ac699afc2a
6755060: Collator.compare() does not compare correctly for the Thai locale
yhuang
parents:
diff
changeset
|
4 |
* |
d9ac699afc2a
6755060: Collator.compare() does not compare correctly for the Thai locale
yhuang
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
d9ac699afc2a
6755060: Collator.compare() does not compare correctly for the Thai locale
yhuang
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
d9ac699afc2a
6755060: Collator.compare() does not compare correctly for the Thai locale
yhuang
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
d9ac699afc2a
6755060: Collator.compare() does not compare correctly for the Thai locale
yhuang
parents:
diff
changeset
|
8 |
* |
d9ac699afc2a
6755060: Collator.compare() does not compare correctly for the Thai locale
yhuang
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
d9ac699afc2a
6755060: Collator.compare() does not compare correctly for the Thai locale
yhuang
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
d9ac699afc2a
6755060: Collator.compare() does not compare correctly for the Thai locale
yhuang
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
d9ac699afc2a
6755060: Collator.compare() does not compare correctly for the Thai locale
yhuang
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
d9ac699afc2a
6755060: Collator.compare() does not compare correctly for the Thai locale
yhuang
parents:
diff
changeset
|
13 |
* accompanied this code). |
d9ac699afc2a
6755060: Collator.compare() does not compare correctly for the Thai locale
yhuang
parents:
diff
changeset
|
14 |
* |
d9ac699afc2a
6755060: Collator.compare() does not compare correctly for the Thai locale
yhuang
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
d9ac699afc2a
6755060: Collator.compare() does not compare correctly for the Thai locale
yhuang
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
d9ac699afc2a
6755060: Collator.compare() does not compare correctly for the Thai locale
yhuang
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
d9ac699afc2a
6755060: Collator.compare() does not compare correctly for the Thai locale
yhuang
parents:
diff
changeset
|
18 |
* |
d9ac699afc2a
6755060: Collator.compare() does not compare correctly for the Thai locale
yhuang
parents:
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
d9ac699afc2a
6755060: Collator.compare() does not compare correctly for the Thai locale
yhuang
parents:
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
d9ac699afc2a
6755060: Collator.compare() does not compare correctly for the Thai locale
yhuang
parents:
diff
changeset
|
21 |
* questions. |
d9ac699afc2a
6755060: Collator.compare() does not compare correctly for the Thai locale
yhuang
parents:
diff
changeset
|
22 |
*/ |
d9ac699afc2a
6755060: Collator.compare() does not compare correctly for the Thai locale
yhuang
parents:
diff
changeset
|
23 |
|
d9ac699afc2a
6755060: Collator.compare() does not compare correctly for the Thai locale
yhuang
parents:
diff
changeset
|
24 |
/* |
d9ac699afc2a
6755060: Collator.compare() does not compare correctly for the Thai locale
yhuang
parents:
diff
changeset
|
25 |
* @test |
d9ac699afc2a
6755060: Collator.compare() does not compare correctly for the Thai locale
yhuang
parents:
diff
changeset
|
26 |
* @bug 6755060 |
d9ac699afc2a
6755060: Collator.compare() does not compare correctly for the Thai locale
yhuang
parents:
diff
changeset
|
27 |
* @summary updating collation tables for thai to make it consistent with CLDR 1.9 |
d9ac699afc2a
6755060: Collator.compare() does not compare correctly for the Thai locale
yhuang
parents:
diff
changeset
|
28 |
*/ |
d9ac699afc2a
6755060: Collator.compare() does not compare correctly for the Thai locale
yhuang
parents:
diff
changeset
|
29 |
|
d9ac699afc2a
6755060: Collator.compare() does not compare correctly for the Thai locale
yhuang
parents:
diff
changeset
|
30 |
import java.text.*; |
d9ac699afc2a
6755060: Collator.compare() does not compare correctly for the Thai locale
yhuang
parents:
diff
changeset
|
31 |
import java.util.*; |
d9ac699afc2a
6755060: Collator.compare() does not compare correctly for the Thai locale
yhuang
parents:
diff
changeset
|
32 |
|
d9ac699afc2a
6755060: Collator.compare() does not compare correctly for the Thai locale
yhuang
parents:
diff
changeset
|
33 |
public class Bug6755060 { |
d9ac699afc2a
6755060: Collator.compare() does not compare correctly for the Thai locale
yhuang
parents:
diff
changeset
|
34 |
|
d9ac699afc2a
6755060: Collator.compare() does not compare correctly for the Thai locale
yhuang
parents:
diff
changeset
|
35 |
/******************************************************** |
d9ac699afc2a
6755060: Collator.compare() does not compare correctly for the Thai locale
yhuang
parents:
diff
changeset
|
36 |
*********************************************************/ |
d9ac699afc2a
6755060: Collator.compare() does not compare correctly for the Thai locale
yhuang
parents:
diff
changeset
|
37 |
public static void main (String[] args) { |
d9ac699afc2a
6755060: Collator.compare() does not compare correctly for the Thai locale
yhuang
parents:
diff
changeset
|
38 |
|
d9ac699afc2a
6755060: Collator.compare() does not compare correctly for the Thai locale
yhuang
parents:
diff
changeset
|
39 |
Locale reservedLocale = Locale.getDefault(); |
d9ac699afc2a
6755060: Collator.compare() does not compare correctly for the Thai locale
yhuang
parents:
diff
changeset
|
40 |
|
d9ac699afc2a
6755060: Collator.compare() does not compare correctly for the Thai locale
yhuang
parents:
diff
changeset
|
41 |
try{ |
d9ac699afc2a
6755060: Collator.compare() does not compare correctly for the Thai locale
yhuang
parents:
diff
changeset
|
42 |
|
d9ac699afc2a
6755060: Collator.compare() does not compare correctly for the Thai locale
yhuang
parents:
diff
changeset
|
43 |
int errors=0; |
d9ac699afc2a
6755060: Collator.compare() does not compare correctly for the Thai locale
yhuang
parents:
diff
changeset
|
44 |
|
d9ac699afc2a
6755060: Collator.compare() does not compare correctly for the Thai locale
yhuang
parents:
diff
changeset
|
45 |
Locale loc = new Locale ("th", "TH"); // Thai |
d9ac699afc2a
6755060: Collator.compare() does not compare correctly for the Thai locale
yhuang
parents:
diff
changeset
|
46 |
|
d9ac699afc2a
6755060: Collator.compare() does not compare correctly for the Thai locale
yhuang
parents:
diff
changeset
|
47 |
Locale.setDefault (loc); |
d9ac699afc2a
6755060: Collator.compare() does not compare correctly for the Thai locale
yhuang
parents:
diff
changeset
|
48 |
Collator col = Collator.getInstance (); |
d9ac699afc2a
6755060: Collator.compare() does not compare correctly for the Thai locale
yhuang
parents:
diff
changeset
|
49 |
|
d9ac699afc2a
6755060: Collator.compare() does not compare correctly for the Thai locale
yhuang
parents:
diff
changeset
|
50 |
/* |
d9ac699afc2a
6755060: Collator.compare() does not compare correctly for the Thai locale
yhuang
parents:
diff
changeset
|
51 |
* The original data "data" are the data to be sorted provided by the submitter of the CR. |
d9ac699afc2a
6755060: Collator.compare() does not compare correctly for the Thai locale
yhuang
parents:
diff
changeset
|
52 |
* It's in correct order in accord with thai collation in CLDR 1.9. If we use old Java without this fix, |
d9ac699afc2a
6755060: Collator.compare() does not compare correctly for the Thai locale
yhuang
parents:
diff
changeset
|
53 |
* the output order will be incorrect. Correct order will be turned into incorrect order. |
d9ac699afc2a
6755060: Collator.compare() does not compare correctly for the Thai locale
yhuang
parents:
diff
changeset
|
54 |
|
d9ac699afc2a
6755060: Collator.compare() does not compare correctly for the Thai locale
yhuang
parents:
diff
changeset
|
55 |
* If fix is there, "data" after sorting will be unchanged, same as "sortedData". If fix is lost (regression), |
d9ac699afc2a
6755060: Collator.compare() does not compare correctly for the Thai locale
yhuang
parents:
diff
changeset
|
56 |
* "data" after sorting will be changed, not as "sortedData".(not correct anymore) |
d9ac699afc2a
6755060: Collator.compare() does not compare correctly for the Thai locale
yhuang
parents:
diff
changeset
|
57 |
|
d9ac699afc2a
6755060: Collator.compare() does not compare correctly for the Thai locale
yhuang
parents:
diff
changeset
|
58 |
* The submitter of the CR also gives a expected "sortedData" in the CR, but it's in accord with collation in CLDR 1.4. |
d9ac699afc2a
6755060: Collator.compare() does not compare correctly for the Thai locale
yhuang
parents:
diff
changeset
|
59 |
* His data to be sorted are actually well sorted in accord with CLDR 1.9. |
d9ac699afc2a
6755060: Collator.compare() does not compare correctly for the Thai locale
yhuang
parents:
diff
changeset
|
60 |
*/ |
d9ac699afc2a
6755060: Collator.compare() does not compare correctly for the Thai locale
yhuang
parents:
diff
changeset
|
61 |
|
d9ac699afc2a
6755060: Collator.compare() does not compare correctly for the Thai locale
yhuang
parents:
diff
changeset
|
62 |
String[] data = {"\u0e01", "\u0e01\u0e2f", "\u0e01\u0e46", "\u0e01\u0e4f", "\u0e01\u0e5a", "\u0e01\u0e5b", "\u0e01\u0e4e", "\u0e01\u0e4c", "\u0e01\u0e48", "\u0e01\u0e01", "\u0e01\u0e4b\u0e01", "\u0e01\u0e4d", "\u0e01\u0e30", "\u0e01\u0e31\u0e01", "\u0e01\u0e32", "\u0e01\u0e33", "\u0e01\u0e34", "\u0e01\u0e35", "\u0e01\u0e36", "\u0e01\u0e37", "\u0e01\u0e38", "\u0e01\u0e39", "\u0e40\u0e01", "\u0e40\u0e01\u0e48", "\u0e40\u0e01\u0e49", "\u0e40\u0e01\u0e4b", "\u0e41\u0e01", "\u0e42\u0e01", "\u0e43\u0e01", "\u0e44\u0e01", "\u0e01\u0e3a", "\u0e24\u0e32", "\u0e24\u0e45", "\u0e40\u0e25", "\u0e44\u0e26"}; |
d9ac699afc2a
6755060: Collator.compare() does not compare correctly for the Thai locale
yhuang
parents:
diff
changeset
|
63 |
|
d9ac699afc2a
6755060: Collator.compare() does not compare correctly for the Thai locale
yhuang
parents:
diff
changeset
|
64 |
String[] sortedData = {"\u0e01", "\u0e01\u0e2f", "\u0e01\u0e46", "\u0e01\u0e4f", "\u0e01\u0e5a", "\u0e01\u0e5b", "\u0e01\u0e4e", "\u0e01\u0e4c", "\u0e01\u0e48", "\u0e01\u0e01", "\u0e01\u0e4b\u0e01", "\u0e01\u0e4d", "\u0e01\u0e30", "\u0e01\u0e31\u0e01", "\u0e01\u0e32", "\u0e01\u0e33", "\u0e01\u0e34", "\u0e01\u0e35", "\u0e01\u0e36", "\u0e01\u0e37", "\u0e01\u0e38", "\u0e01\u0e39", "\u0e40\u0e01", "\u0e40\u0e01\u0e48", "\u0e40\u0e01\u0e49", "\u0e40\u0e01\u0e4b", "\u0e41\u0e01", "\u0e42\u0e01", "\u0e43\u0e01", "\u0e44\u0e01", "\u0e01\u0e3a", "\u0e24\u0e32", "\u0e24\u0e45", "\u0e40\u0e25", "\u0e44\u0e26"}; |
d9ac699afc2a
6755060: Collator.compare() does not compare correctly for the Thai locale
yhuang
parents:
diff
changeset
|
65 |
|
d9ac699afc2a
6755060: Collator.compare() does not compare correctly for the Thai locale
yhuang
parents:
diff
changeset
|
66 |
Arrays.sort (data, col); |
d9ac699afc2a
6755060: Collator.compare() does not compare correctly for the Thai locale
yhuang
parents:
diff
changeset
|
67 |
|
d9ac699afc2a
6755060: Collator.compare() does not compare correctly for the Thai locale
yhuang
parents:
diff
changeset
|
68 |
System.out.println ("Using " + loc.getDisplayName()); |
d9ac699afc2a
6755060: Collator.compare() does not compare correctly for the Thai locale
yhuang
parents:
diff
changeset
|
69 |
for (int i = 0; i < data.length; i++) { |
d9ac699afc2a
6755060: Collator.compare() does not compare correctly for the Thai locale
yhuang
parents:
diff
changeset
|
70 |
System.out.println(data[i] + " : " + sortedData[i]); |
d9ac699afc2a
6755060: Collator.compare() does not compare correctly for the Thai locale
yhuang
parents:
diff
changeset
|
71 |
if (sortedData[i].compareTo(data[i]) != 0) { |
d9ac699afc2a
6755060: Collator.compare() does not compare correctly for the Thai locale
yhuang
parents:
diff
changeset
|
72 |
errors++; |
d9ac699afc2a
6755060: Collator.compare() does not compare correctly for the Thai locale
yhuang
parents:
diff
changeset
|
73 |
} |
d9ac699afc2a
6755060: Collator.compare() does not compare correctly for the Thai locale
yhuang
parents:
diff
changeset
|
74 |
}//end for |
d9ac699afc2a
6755060: Collator.compare() does not compare correctly for the Thai locale
yhuang
parents:
diff
changeset
|
75 |
|
d9ac699afc2a
6755060: Collator.compare() does not compare correctly for the Thai locale
yhuang
parents:
diff
changeset
|
76 |
if (errors > 0){ |
d9ac699afc2a
6755060: Collator.compare() does not compare correctly for the Thai locale
yhuang
parents:
diff
changeset
|
77 |
StringBuffer expected = new StringBuffer(), actual = new StringBuffer(); |
d9ac699afc2a
6755060: Collator.compare() does not compare correctly for the Thai locale
yhuang
parents:
diff
changeset
|
78 |
expected.append(sortedData[0]); |
d9ac699afc2a
6755060: Collator.compare() does not compare correctly for the Thai locale
yhuang
parents:
diff
changeset
|
79 |
actual.append(data[0]); |
d9ac699afc2a
6755060: Collator.compare() does not compare correctly for the Thai locale
yhuang
parents:
diff
changeset
|
80 |
|
d9ac699afc2a
6755060: Collator.compare() does not compare correctly for the Thai locale
yhuang
parents:
diff
changeset
|
81 |
for (int i=1; i<data.length; i++) { |
d9ac699afc2a
6755060: Collator.compare() does not compare correctly for the Thai locale
yhuang
parents:
diff
changeset
|
82 |
expected.append(","); |
d9ac699afc2a
6755060: Collator.compare() does not compare correctly for the Thai locale
yhuang
parents:
diff
changeset
|
83 |
expected.append(sortedData[i]); |
d9ac699afc2a
6755060: Collator.compare() does not compare correctly for the Thai locale
yhuang
parents:
diff
changeset
|
84 |
|
d9ac699afc2a
6755060: Collator.compare() does not compare correctly for the Thai locale
yhuang
parents:
diff
changeset
|
85 |
actual.append(","); |
d9ac699afc2a
6755060: Collator.compare() does not compare correctly for the Thai locale
yhuang
parents:
diff
changeset
|
86 |
actual.append(data[i]); |
d9ac699afc2a
6755060: Collator.compare() does not compare correctly for the Thai locale
yhuang
parents:
diff
changeset
|
87 |
} |
d9ac699afc2a
6755060: Collator.compare() does not compare correctly for the Thai locale
yhuang
parents:
diff
changeset
|
88 |
|
d9ac699afc2a
6755060: Collator.compare() does not compare correctly for the Thai locale
yhuang
parents:
diff
changeset
|
89 |
String errmsg = "Error is found in collation testing in Thai\n" + "exepected order is: " + expected.toString() + "\n" + "actual order is: " + actual.toString() + "\n"; |
d9ac699afc2a
6755060: Collator.compare() does not compare correctly for the Thai locale
yhuang
parents:
diff
changeset
|
90 |
|
d9ac699afc2a
6755060: Collator.compare() does not compare correctly for the Thai locale
yhuang
parents:
diff
changeset
|
91 |
throw new RuntimeException(errmsg); |
d9ac699afc2a
6755060: Collator.compare() does not compare correctly for the Thai locale
yhuang
parents:
diff
changeset
|
92 |
} |
d9ac699afc2a
6755060: Collator.compare() does not compare correctly for the Thai locale
yhuang
parents:
diff
changeset
|
93 |
}finally{ |
d9ac699afc2a
6755060: Collator.compare() does not compare correctly for the Thai locale
yhuang
parents:
diff
changeset
|
94 |
// restore the reserved locale |
d9ac699afc2a
6755060: Collator.compare() does not compare correctly for the Thai locale
yhuang
parents:
diff
changeset
|
95 |
Locale.setDefault(reservedLocale); |
d9ac699afc2a
6755060: Collator.compare() does not compare correctly for the Thai locale
yhuang
parents:
diff
changeset
|
96 |
} |
d9ac699afc2a
6755060: Collator.compare() does not compare correctly for the Thai locale
yhuang
parents:
diff
changeset
|
97 |
|
d9ac699afc2a
6755060: Collator.compare() does not compare correctly for the Thai locale
yhuang
parents:
diff
changeset
|
98 |
}//end main |
d9ac699afc2a
6755060: Collator.compare() does not compare correctly for the Thai locale
yhuang
parents:
diff
changeset
|
99 |
|
d9ac699afc2a
6755060: Collator.compare() does not compare correctly for the Thai locale
yhuang
parents:
diff
changeset
|
100 |
}//end class CollatorTest |