author | okutsu |
Mon, 10 Dec 2012 10:52:11 +0900 | |
changeset 14765 | 0987999ed367 |
child 29720 | 374070bf0fdf |
permissions | -rw-r--r-- |
14765
0987999ed367
8000983: Support narrow display names for calendar fields
okutsu
parents:
diff
changeset
|
1 |
/* |
0987999ed367
8000983: Support narrow display names for calendar fields
okutsu
parents:
diff
changeset
|
2 |
* Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. |
0987999ed367
8000983: Support narrow display names for calendar fields
okutsu
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
0987999ed367
8000983: Support narrow display names for calendar fields
okutsu
parents:
diff
changeset
|
4 |
* |
0987999ed367
8000983: Support narrow display names for calendar fields
okutsu
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
0987999ed367
8000983: Support narrow display names for calendar fields
okutsu
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
0987999ed367
8000983: Support narrow display names for calendar fields
okutsu
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
0987999ed367
8000983: Support narrow display names for calendar fields
okutsu
parents:
diff
changeset
|
8 |
* |
0987999ed367
8000983: Support narrow display names for calendar fields
okutsu
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
0987999ed367
8000983: Support narrow display names for calendar fields
okutsu
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
0987999ed367
8000983: Support narrow display names for calendar fields
okutsu
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
0987999ed367
8000983: Support narrow display names for calendar fields
okutsu
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
0987999ed367
8000983: Support narrow display names for calendar fields
okutsu
parents:
diff
changeset
|
13 |
* accompanied this code). |
0987999ed367
8000983: Support narrow display names for calendar fields
okutsu
parents:
diff
changeset
|
14 |
* |
0987999ed367
8000983: Support narrow display names for calendar fields
okutsu
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
0987999ed367
8000983: Support narrow display names for calendar fields
okutsu
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
0987999ed367
8000983: Support narrow display names for calendar fields
okutsu
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
0987999ed367
8000983: Support narrow display names for calendar fields
okutsu
parents:
diff
changeset
|
18 |
* |
0987999ed367
8000983: Support narrow display names for calendar fields
okutsu
parents:
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
0987999ed367
8000983: Support narrow display names for calendar fields
okutsu
parents:
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
0987999ed367
8000983: Support narrow display names for calendar fields
okutsu
parents:
diff
changeset
|
21 |
* questions. |
0987999ed367
8000983: Support narrow display names for calendar fields
okutsu
parents:
diff
changeset
|
22 |
*/ |
0987999ed367
8000983: Support narrow display names for calendar fields
okutsu
parents:
diff
changeset
|
23 |
|
0987999ed367
8000983: Support narrow display names for calendar fields
okutsu
parents:
diff
changeset
|
24 |
import java.util.*; |
0987999ed367
8000983: Support narrow display names for calendar fields
okutsu
parents:
diff
changeset
|
25 |
import static java.util.GregorianCalendar.*; |
0987999ed367
8000983: Support narrow display names for calendar fields
okutsu
parents:
diff
changeset
|
26 |
|
0987999ed367
8000983: Support narrow display names for calendar fields
okutsu
parents:
diff
changeset
|
27 |
public class NarrowNamesTest { |
0987999ed367
8000983: Support narrow display names for calendar fields
okutsu
parents:
diff
changeset
|
28 |
private static final Locale US = Locale.US; |
0987999ed367
8000983: Support narrow display names for calendar fields
okutsu
parents:
diff
changeset
|
29 |
private static final Locale JAJPJP = new Locale("ja", "JP", "JP"); |
0987999ed367
8000983: Support narrow display names for calendar fields
okutsu
parents:
diff
changeset
|
30 |
private static final Locale THTH = new Locale("th", "TH"); |
0987999ed367
8000983: Support narrow display names for calendar fields
okutsu
parents:
diff
changeset
|
31 |
|
0987999ed367
8000983: Support narrow display names for calendar fields
okutsu
parents:
diff
changeset
|
32 |
private static final String RESET_INDEX = "RESET_INDEX"; |
0987999ed367
8000983: Support narrow display names for calendar fields
okutsu
parents:
diff
changeset
|
33 |
|
0987999ed367
8000983: Support narrow display names for calendar fields
okutsu
parents:
diff
changeset
|
34 |
private static int errors = 0; |
0987999ed367
8000983: Support narrow display names for calendar fields
okutsu
parents:
diff
changeset
|
35 |
|
0987999ed367
8000983: Support narrow display names for calendar fields
okutsu
parents:
diff
changeset
|
36 |
// This test is locale data-dependent. |
0987999ed367
8000983: Support narrow display names for calendar fields
okutsu
parents:
diff
changeset
|
37 |
public static void main(String[] args) { |
0987999ed367
8000983: Support narrow display names for calendar fields
okutsu
parents:
diff
changeset
|
38 |
test(US, ERA, "B", |
0987999ed367
8000983: Support narrow display names for calendar fields
okutsu
parents:
diff
changeset
|
39 |
ERA, BC, YEAR, 1); |
0987999ed367
8000983: Support narrow display names for calendar fields
okutsu
parents:
diff
changeset
|
40 |
test(US, ERA, "A", |
0987999ed367
8000983: Support narrow display names for calendar fields
okutsu
parents:
diff
changeset
|
41 |
ERA, AD, YEAR, 2012); |
0987999ed367
8000983: Support narrow display names for calendar fields
okutsu
parents:
diff
changeset
|
42 |
test(US, DAY_OF_WEEK, "S", |
0987999ed367
8000983: Support narrow display names for calendar fields
okutsu
parents:
diff
changeset
|
43 |
YEAR, 2012, MONTH, DECEMBER, DAY_OF_MONTH, 23); |
0987999ed367
8000983: Support narrow display names for calendar fields
okutsu
parents:
diff
changeset
|
44 |
test(US, AM_PM, "a", |
0987999ed367
8000983: Support narrow display names for calendar fields
okutsu
parents:
diff
changeset
|
45 |
HOUR_OF_DAY, 10); |
0987999ed367
8000983: Support narrow display names for calendar fields
okutsu
parents:
diff
changeset
|
46 |
test(US, AM_PM, "p", |
0987999ed367
8000983: Support narrow display names for calendar fields
okutsu
parents:
diff
changeset
|
47 |
HOUR_OF_DAY, 23); |
0987999ed367
8000983: Support narrow display names for calendar fields
okutsu
parents:
diff
changeset
|
48 |
test(JAJPJP, DAY_OF_WEEK, "\u65e5", |
0987999ed367
8000983: Support narrow display names for calendar fields
okutsu
parents:
diff
changeset
|
49 |
YEAR, 24, MONTH, DECEMBER, DAY_OF_MONTH, 23); |
0987999ed367
8000983: Support narrow display names for calendar fields
okutsu
parents:
diff
changeset
|
50 |
test(THTH, MONTH, NARROW_STANDALONE, "\u0e18.\u0e04.", |
0987999ed367
8000983: Support narrow display names for calendar fields
okutsu
parents:
diff
changeset
|
51 |
YEAR, 2555, MONTH, DECEMBER, DAY_OF_MONTH, 5); |
0987999ed367
8000983: Support narrow display names for calendar fields
okutsu
parents:
diff
changeset
|
52 |
test(THTH, DAY_OF_WEEK, "\u0e1e", |
0987999ed367
8000983: Support narrow display names for calendar fields
okutsu
parents:
diff
changeset
|
53 |
YEAR, 2555, MONTH, DECEMBER, DAY_OF_MONTH, 5); |
0987999ed367
8000983: Support narrow display names for calendar fields
okutsu
parents:
diff
changeset
|
54 |
|
0987999ed367
8000983: Support narrow display names for calendar fields
okutsu
parents:
diff
changeset
|
55 |
testMap(US, DAY_OF_WEEK, ALL_STYLES, // shouldn't include any narrow names |
0987999ed367
8000983: Support narrow display names for calendar fields
okutsu
parents:
diff
changeset
|
56 |
"", // 1-based indexing for DAY_OF_WEEK |
0987999ed367
8000983: Support narrow display names for calendar fields
okutsu
parents:
diff
changeset
|
57 |
"Sunday", // Sunday |
0987999ed367
8000983: Support narrow display names for calendar fields
okutsu
parents:
diff
changeset
|
58 |
"Monday", // Monday |
0987999ed367
8000983: Support narrow display names for calendar fields
okutsu
parents:
diff
changeset
|
59 |
"Tuesday", // Tuesday |
0987999ed367
8000983: Support narrow display names for calendar fields
okutsu
parents:
diff
changeset
|
60 |
"Wednesday", // Wednesday |
0987999ed367
8000983: Support narrow display names for calendar fields
okutsu
parents:
diff
changeset
|
61 |
"Thursday", // Thursday |
0987999ed367
8000983: Support narrow display names for calendar fields
okutsu
parents:
diff
changeset
|
62 |
"Friday", // Friday |
0987999ed367
8000983: Support narrow display names for calendar fields
okutsu
parents:
diff
changeset
|
63 |
"Saturday", // Saturday |
0987999ed367
8000983: Support narrow display names for calendar fields
okutsu
parents:
diff
changeset
|
64 |
RESET_INDEX, |
0987999ed367
8000983: Support narrow display names for calendar fields
okutsu
parents:
diff
changeset
|
65 |
"", // 1-based indexing for DAY_OF_WEEK |
0987999ed367
8000983: Support narrow display names for calendar fields
okutsu
parents:
diff
changeset
|
66 |
"Sun", // abb Sunday |
0987999ed367
8000983: Support narrow display names for calendar fields
okutsu
parents:
diff
changeset
|
67 |
"Mon", // abb Monday |
0987999ed367
8000983: Support narrow display names for calendar fields
okutsu
parents:
diff
changeset
|
68 |
"Tue", // abb Tuesday |
0987999ed367
8000983: Support narrow display names for calendar fields
okutsu
parents:
diff
changeset
|
69 |
"Wed", // abb Wednesday |
0987999ed367
8000983: Support narrow display names for calendar fields
okutsu
parents:
diff
changeset
|
70 |
"Thu", // abb Thursday |
0987999ed367
8000983: Support narrow display names for calendar fields
okutsu
parents:
diff
changeset
|
71 |
"Fri", // abb Friday |
0987999ed367
8000983: Support narrow display names for calendar fields
okutsu
parents:
diff
changeset
|
72 |
"Sat" // abb Saturday |
0987999ed367
8000983: Support narrow display names for calendar fields
okutsu
parents:
diff
changeset
|
73 |
); |
0987999ed367
8000983: Support narrow display names for calendar fields
okutsu
parents:
diff
changeset
|
74 |
testMap(US, DAY_OF_WEEK, NARROW_FORMAT); // expect null |
0987999ed367
8000983: Support narrow display names for calendar fields
okutsu
parents:
diff
changeset
|
75 |
testMap(US, AM_PM, ALL_STYLES, |
0987999ed367
8000983: Support narrow display names for calendar fields
okutsu
parents:
diff
changeset
|
76 |
"AM", "PM", |
0987999ed367
8000983: Support narrow display names for calendar fields
okutsu
parents:
diff
changeset
|
77 |
RESET_INDEX, |
0987999ed367
8000983: Support narrow display names for calendar fields
okutsu
parents:
diff
changeset
|
78 |
"a", "p"); |
0987999ed367
8000983: Support narrow display names for calendar fields
okutsu
parents:
diff
changeset
|
79 |
testMap(JAJPJP, DAY_OF_WEEK, NARROW_STANDALONE); // expect null |
0987999ed367
8000983: Support narrow display names for calendar fields
okutsu
parents:
diff
changeset
|
80 |
testMap(JAJPJP, DAY_OF_WEEK, NARROW_FORMAT, |
0987999ed367
8000983: Support narrow display names for calendar fields
okutsu
parents:
diff
changeset
|
81 |
"", // 1-based indexing for DAY_OF_WEEK |
0987999ed367
8000983: Support narrow display names for calendar fields
okutsu
parents:
diff
changeset
|
82 |
"\u65e5", |
0987999ed367
8000983: Support narrow display names for calendar fields
okutsu
parents:
diff
changeset
|
83 |
"\u6708", |
0987999ed367
8000983: Support narrow display names for calendar fields
okutsu
parents:
diff
changeset
|
84 |
"\u706b", |
0987999ed367
8000983: Support narrow display names for calendar fields
okutsu
parents:
diff
changeset
|
85 |
"\u6c34", |
0987999ed367
8000983: Support narrow display names for calendar fields
okutsu
parents:
diff
changeset
|
86 |
"\u6728", |
0987999ed367
8000983: Support narrow display names for calendar fields
okutsu
parents:
diff
changeset
|
87 |
"\u91d1", |
0987999ed367
8000983: Support narrow display names for calendar fields
okutsu
parents:
diff
changeset
|
88 |
"\u571f"); |
0987999ed367
8000983: Support narrow display names for calendar fields
okutsu
parents:
diff
changeset
|
89 |
testMap(THTH, MONTH, NARROW_FORMAT); // expect null |
0987999ed367
8000983: Support narrow display names for calendar fields
okutsu
parents:
diff
changeset
|
90 |
testMap(THTH, MONTH, NARROW_STANDALONE, |
0987999ed367
8000983: Support narrow display names for calendar fields
okutsu
parents:
diff
changeset
|
91 |
"\u0e21.\u0e04.", |
0987999ed367
8000983: Support narrow display names for calendar fields
okutsu
parents:
diff
changeset
|
92 |
"\u0e01.\u0e1e.", |
0987999ed367
8000983: Support narrow display names for calendar fields
okutsu
parents:
diff
changeset
|
93 |
"\u0e21\u0e35.\u0e04.", |
0987999ed367
8000983: Support narrow display names for calendar fields
okutsu
parents:
diff
changeset
|
94 |
"\u0e40\u0e21.\u0e22.", |
0987999ed367
8000983: Support narrow display names for calendar fields
okutsu
parents:
diff
changeset
|
95 |
"\u0e1e.\u0e04.", |
0987999ed367
8000983: Support narrow display names for calendar fields
okutsu
parents:
diff
changeset
|
96 |
"\u0e21\u0e34.\u0e22.", |
0987999ed367
8000983: Support narrow display names for calendar fields
okutsu
parents:
diff
changeset
|
97 |
"\u0e01.\u0e04.", |
0987999ed367
8000983: Support narrow display names for calendar fields
okutsu
parents:
diff
changeset
|
98 |
"\u0e2a.\u0e04.", |
0987999ed367
8000983: Support narrow display names for calendar fields
okutsu
parents:
diff
changeset
|
99 |
"\u0e01.\u0e22.", |
0987999ed367
8000983: Support narrow display names for calendar fields
okutsu
parents:
diff
changeset
|
100 |
"\u0e15.\u0e04.", |
0987999ed367
8000983: Support narrow display names for calendar fields
okutsu
parents:
diff
changeset
|
101 |
"\u0e1e.\u0e22.", |
0987999ed367
8000983: Support narrow display names for calendar fields
okutsu
parents:
diff
changeset
|
102 |
"\u0e18.\u0e04."); |
0987999ed367
8000983: Support narrow display names for calendar fields
okutsu
parents:
diff
changeset
|
103 |
|
0987999ed367
8000983: Support narrow display names for calendar fields
okutsu
parents:
diff
changeset
|
104 |
if (errors != 0) { |
0987999ed367
8000983: Support narrow display names for calendar fields
okutsu
parents:
diff
changeset
|
105 |
throw new RuntimeException("test failed"); |
0987999ed367
8000983: Support narrow display names for calendar fields
okutsu
parents:
diff
changeset
|
106 |
} |
0987999ed367
8000983: Support narrow display names for calendar fields
okutsu
parents:
diff
changeset
|
107 |
} |
0987999ed367
8000983: Support narrow display names for calendar fields
okutsu
parents:
diff
changeset
|
108 |
|
0987999ed367
8000983: Support narrow display names for calendar fields
okutsu
parents:
diff
changeset
|
109 |
private static void test(Locale locale, int field, String expected, int... data) { |
0987999ed367
8000983: Support narrow display names for calendar fields
okutsu
parents:
diff
changeset
|
110 |
test(locale, field, NARROW_FORMAT, expected, data); |
0987999ed367
8000983: Support narrow display names for calendar fields
okutsu
parents:
diff
changeset
|
111 |
} |
0987999ed367
8000983: Support narrow display names for calendar fields
okutsu
parents:
diff
changeset
|
112 |
|
0987999ed367
8000983: Support narrow display names for calendar fields
okutsu
parents:
diff
changeset
|
113 |
private static void test(Locale locale, int field, int style, String expected, int... fieldValuePairs) { |
0987999ed367
8000983: Support narrow display names for calendar fields
okutsu
parents:
diff
changeset
|
114 |
Calendar cal = Calendar.getInstance(locale); |
0987999ed367
8000983: Support narrow display names for calendar fields
okutsu
parents:
diff
changeset
|
115 |
cal.clear(); |
0987999ed367
8000983: Support narrow display names for calendar fields
okutsu
parents:
diff
changeset
|
116 |
for (int i = 0; i < fieldValuePairs.length;) { |
0987999ed367
8000983: Support narrow display names for calendar fields
okutsu
parents:
diff
changeset
|
117 |
int f = fieldValuePairs[i++]; |
0987999ed367
8000983: Support narrow display names for calendar fields
okutsu
parents:
diff
changeset
|
118 |
int v = fieldValuePairs[i++]; |
0987999ed367
8000983: Support narrow display names for calendar fields
okutsu
parents:
diff
changeset
|
119 |
cal.set(f, v); |
0987999ed367
8000983: Support narrow display names for calendar fields
okutsu
parents:
diff
changeset
|
120 |
} |
0987999ed367
8000983: Support narrow display names for calendar fields
okutsu
parents:
diff
changeset
|
121 |
String got = cal.getDisplayName(field, style, locale); |
0987999ed367
8000983: Support narrow display names for calendar fields
okutsu
parents:
diff
changeset
|
122 |
if (!expected.equals(got)) { |
0987999ed367
8000983: Support narrow display names for calendar fields
okutsu
parents:
diff
changeset
|
123 |
System.err.printf("test: locale=%s, field=%d, value=%d, style=%d, got=\"%s\", expected=\"%s\"%n", |
0987999ed367
8000983: Support narrow display names for calendar fields
okutsu
parents:
diff
changeset
|
124 |
locale, field, cal.get(field), style, got, expected); |
0987999ed367
8000983: Support narrow display names for calendar fields
okutsu
parents:
diff
changeset
|
125 |
errors++; |
0987999ed367
8000983: Support narrow display names for calendar fields
okutsu
parents:
diff
changeset
|
126 |
} |
0987999ed367
8000983: Support narrow display names for calendar fields
okutsu
parents:
diff
changeset
|
127 |
} |
0987999ed367
8000983: Support narrow display names for calendar fields
okutsu
parents:
diff
changeset
|
128 |
|
0987999ed367
8000983: Support narrow display names for calendar fields
okutsu
parents:
diff
changeset
|
129 |
private static void testMap(Locale locale, int field, int style, String... expected) { |
0987999ed367
8000983: Support narrow display names for calendar fields
okutsu
parents:
diff
changeset
|
130 |
Map<String, Integer> expectedMap = null; |
0987999ed367
8000983: Support narrow display names for calendar fields
okutsu
parents:
diff
changeset
|
131 |
if (expected.length > 0) { |
0987999ed367
8000983: Support narrow display names for calendar fields
okutsu
parents:
diff
changeset
|
132 |
expectedMap = new TreeMap<>(LengthBasedComparator.INSTANCE); |
0987999ed367
8000983: Support narrow display names for calendar fields
okutsu
parents:
diff
changeset
|
133 |
int index = 0; |
0987999ed367
8000983: Support narrow display names for calendar fields
okutsu
parents:
diff
changeset
|
134 |
for (int i = 0; i < expected.length; i++) { |
0987999ed367
8000983: Support narrow display names for calendar fields
okutsu
parents:
diff
changeset
|
135 |
if (expected[i].isEmpty()) { |
0987999ed367
8000983: Support narrow display names for calendar fields
okutsu
parents:
diff
changeset
|
136 |
index++; |
0987999ed367
8000983: Support narrow display names for calendar fields
okutsu
parents:
diff
changeset
|
137 |
continue; |
0987999ed367
8000983: Support narrow display names for calendar fields
okutsu
parents:
diff
changeset
|
138 |
} |
0987999ed367
8000983: Support narrow display names for calendar fields
okutsu
parents:
diff
changeset
|
139 |
if (expected[i] == RESET_INDEX) { |
0987999ed367
8000983: Support narrow display names for calendar fields
okutsu
parents:
diff
changeset
|
140 |
index = 0; |
0987999ed367
8000983: Support narrow display names for calendar fields
okutsu
parents:
diff
changeset
|
141 |
continue; |
0987999ed367
8000983: Support narrow display names for calendar fields
okutsu
parents:
diff
changeset
|
142 |
} |
0987999ed367
8000983: Support narrow display names for calendar fields
okutsu
parents:
diff
changeset
|
143 |
expectedMap.put(expected[i], index++); |
0987999ed367
8000983: Support narrow display names for calendar fields
okutsu
parents:
diff
changeset
|
144 |
} |
0987999ed367
8000983: Support narrow display names for calendar fields
okutsu
parents:
diff
changeset
|
145 |
} |
0987999ed367
8000983: Support narrow display names for calendar fields
okutsu
parents:
diff
changeset
|
146 |
Calendar cal = Calendar.getInstance(locale); |
0987999ed367
8000983: Support narrow display names for calendar fields
okutsu
parents:
diff
changeset
|
147 |
Map<String, Integer> got = cal.getDisplayNames(field, style, locale); |
0987999ed367
8000983: Support narrow display names for calendar fields
okutsu
parents:
diff
changeset
|
148 |
if (!(expectedMap == null && got == null) |
0987999ed367
8000983: Support narrow display names for calendar fields
okutsu
parents:
diff
changeset
|
149 |
&& !expectedMap.equals(got)) { |
0987999ed367
8000983: Support narrow display names for calendar fields
okutsu
parents:
diff
changeset
|
150 |
System.err.printf("testMap: locale=%s, field=%d, style=%d, expected=%s, got=%s%n", |
0987999ed367
8000983: Support narrow display names for calendar fields
okutsu
parents:
diff
changeset
|
151 |
locale, field, style, expectedMap, got); |
0987999ed367
8000983: Support narrow display names for calendar fields
okutsu
parents:
diff
changeset
|
152 |
errors++; |
0987999ed367
8000983: Support narrow display names for calendar fields
okutsu
parents:
diff
changeset
|
153 |
} |
0987999ed367
8000983: Support narrow display names for calendar fields
okutsu
parents:
diff
changeset
|
154 |
} |
0987999ed367
8000983: Support narrow display names for calendar fields
okutsu
parents:
diff
changeset
|
155 |
|
0987999ed367
8000983: Support narrow display names for calendar fields
okutsu
parents:
diff
changeset
|
156 |
/** |
0987999ed367
8000983: Support narrow display names for calendar fields
okutsu
parents:
diff
changeset
|
157 |
* Comparator implementation for TreeMap which iterates keys from longest |
0987999ed367
8000983: Support narrow display names for calendar fields
okutsu
parents:
diff
changeset
|
158 |
* to shortest. |
0987999ed367
8000983: Support narrow display names for calendar fields
okutsu
parents:
diff
changeset
|
159 |
*/ |
0987999ed367
8000983: Support narrow display names for calendar fields
okutsu
parents:
diff
changeset
|
160 |
private static class LengthBasedComparator implements Comparator<String> { |
0987999ed367
8000983: Support narrow display names for calendar fields
okutsu
parents:
diff
changeset
|
161 |
private static final LengthBasedComparator INSTANCE = new LengthBasedComparator(); |
0987999ed367
8000983: Support narrow display names for calendar fields
okutsu
parents:
diff
changeset
|
162 |
|
0987999ed367
8000983: Support narrow display names for calendar fields
okutsu
parents:
diff
changeset
|
163 |
private LengthBasedComparator() { |
0987999ed367
8000983: Support narrow display names for calendar fields
okutsu
parents:
diff
changeset
|
164 |
} |
0987999ed367
8000983: Support narrow display names for calendar fields
okutsu
parents:
diff
changeset
|
165 |
|
0987999ed367
8000983: Support narrow display names for calendar fields
okutsu
parents:
diff
changeset
|
166 |
@Override |
0987999ed367
8000983: Support narrow display names for calendar fields
okutsu
parents:
diff
changeset
|
167 |
public int compare(String o1, String o2) { |
0987999ed367
8000983: Support narrow display names for calendar fields
okutsu
parents:
diff
changeset
|
168 |
int n = o2.length() - o1.length(); |
0987999ed367
8000983: Support narrow display names for calendar fields
okutsu
parents:
diff
changeset
|
169 |
return (n == 0) ? o1.compareTo(o2) : n; |
0987999ed367
8000983: Support narrow display names for calendar fields
okutsu
parents:
diff
changeset
|
170 |
} |
0987999ed367
8000983: Support narrow display names for calendar fields
okutsu
parents:
diff
changeset
|
171 |
} |
0987999ed367
8000983: Support narrow display names for calendar fields
okutsu
parents:
diff
changeset
|
172 |
} |