Print this page
rev 5615 : 6336885: RFE: Locale Data Deployment Enhancements
4609153: Provide locale data for Indic locales
5104387: Support for gl_ES locale (galician language)
6337471: desktop/system locale preferences support
7056139: (cal) SPI support for locale-dependent Calendar parameters
7058206: Provide CalendarData SPI for week params and display field value names
7073852: Support multiple scripts for digits and decimal symbols per locale
7079560: [Fmt-Da] Context dependent month names support in SimpleDateFormat
7171324: getAvailableLocales() of locale sensitive services should return the actual availability of locales
7151414: (cal) Support calendar type identification
7168528: LocaleServiceProvider needs to be aware of Locale extensions
7171372: (cal) locale's default Calendar should be created if unknown calendar is specified
Summary: JEP 127: Improve Locale Data Packaging and Adopt Unicode CLDR Data (part 1 w/o Jigsaw. by Naoto Sato and Masayoshi Okutsu)
Split |
Close |
Expand all |
Collapse all |
--- old/src/share/classes/java/text/Collator.java
+++ new/src/share/classes/java/text/Collator.java
1 1 /*
2 - * Copyright (c) 1997, 2006, Oracle and/or its affiliates. All rights reserved.
2 + * Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved.
3 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 4 *
5 5 * This code is free software; you can redistribute it and/or modify it
6 6 * under the terms of the GNU General Public License version 2 only, as
7 7 * published by the Free Software Foundation. Oracle designates this
8 8 * particular file as subject to the "Classpath" exception as provided
9 9 * by Oracle in the LICENSE file that accompanied this code.
10 10 *
11 11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 14 * version 2 for more details (a copy is included in the LICENSE file that
15 15 * accompanied this code).
16 16 *
17 17 * You should have received a copy of the GNU General Public License version
18 18 * 2 along with this work; if not, write to the Free Software Foundation,
19 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 20 *
21 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 22 * or visit www.oracle.com if you need additional information or have any
23 23 * questions.
24 24 */
25 25
26 26 /*
27 27 * (C) Copyright Taligent, Inc. 1996-1998 - All Rights Reserved
28 28 * (C) Copyright IBM Corp. 1996-1998 - All Rights Reserved
29 29 *
30 30 * The original version of this source code and documentation is copyrighted
↓ open down ↓ |
18 lines elided |
↑ open up ↑ |
31 31 * and owned by Taligent, Inc., a wholly-owned subsidiary of IBM. These
32 32 * materials are provided under terms of a License Agreement between Taligent
33 33 * and Sun. This technology is protected by multiple US and International
34 34 * patents. This notice and attribution to Taligent may not be removed.
35 35 * Taligent is a registered trademark of Taligent, Inc.
36 36 *
37 37 */
38 38
39 39 package java.text;
40 40
41 +import java.lang.ref.SoftReference;
41 42 import java.text.spi.CollatorProvider;
42 43 import java.util.Locale;
43 -import java.util.MissingResourceException;
44 44 import java.util.ResourceBundle;
45 -import java.util.spi.LocaleServiceProvider;
46 -import sun.misc.SoftCache;
47 -import sun.util.resources.LocaleData;
48 -import sun.util.LocaleServiceProviderPool;
45 +import java.util.concurrent.ConcurrentHashMap;
46 +import java.util.concurrent.ConcurrentMap;
47 +import sun.util.locale.provider.LocaleProviderAdapter;
48 +import sun.util.locale.provider.LocaleServiceProviderPool;
49 49
50 50
51 51 /**
52 52 * The <code>Collator</code> class performs locale-sensitive
53 53 * <code>String</code> comparison. You use this class to build
54 54 * searching and sorting routines for natural language text.
55 55 *
56 56 * <p>
57 57 * <code>Collator</code> is an abstract base class. Subclasses
58 58 * implement specific collation strategies. One subclass,
59 59 * <code>RuleBasedCollator</code>, is currently provided with
60 60 * the Java Platform and is applicable to a wide set of languages. Other
61 61 * subclasses may be created to handle more specialized needs.
62 62 *
63 63 * <p>
64 64 * Like other locale-sensitive classes, you can use the static
65 65 * factory method, <code>getInstance</code>, to obtain the appropriate
66 66 * <code>Collator</code> object for a given locale. You will only need
67 67 * to look at the subclasses of <code>Collator</code> if you need
68 68 * to understand the details of a particular collation strategy or
69 69 * if you need to modify that strategy.
70 70 *
71 71 * <p>
72 72 * The following example shows how to compare two strings using
73 73 * the <code>Collator</code> for the default locale.
74 74 * <blockquote>
75 75 * <pre>
76 76 * // Compare two strings in the default locale
77 77 * Collator myCollator = Collator.getInstance();
78 78 * if( myCollator.compare("abc", "ABC") < 0 )
79 79 * System.out.println("abc is less than ABC");
80 80 * else
81 81 * System.out.println("abc is greater than or equal to ABC");
82 82 * </pre>
83 83 * </blockquote>
84 84 *
85 85 * <p>
86 86 * You can set a <code>Collator</code>'s <em>strength</em> property
87 87 * to determine the level of difference considered significant in
88 88 * comparisons. Four strengths are provided: <code>PRIMARY</code>,
89 89 * <code>SECONDARY</code>, <code>TERTIARY</code>, and <code>IDENTICAL</code>.
90 90 * The exact assignment of strengths to language features is
91 91 * locale dependant. For example, in Czech, "e" and "f" are considered
92 92 * primary differences, while "e" and "ě" are secondary differences,
93 93 * "e" and "E" are tertiary differences and "e" and "e" are identical.
94 94 * The following shows how both case and accents could be ignored for
95 95 * US English.
96 96 * <blockquote>
97 97 * <pre>
98 98 * //Get the Collator for US English and set its strength to PRIMARY
99 99 * Collator usCollator = Collator.getInstance(Locale.US);
100 100 * usCollator.setStrength(Collator.PRIMARY);
101 101 * if( usCollator.compare("abc", "ABC") == 0 ) {
102 102 * System.out.println("Strings are equivalent");
103 103 * }
104 104 * </pre>
105 105 * </blockquote>
106 106 * <p>
107 107 * For comparing <code>String</code>s exactly once, the <code>compare</code>
108 108 * method provides the best performance. When sorting a list of
109 109 * <code>String</code>s however, it is generally necessary to compare each
110 110 * <code>String</code> multiple times. In this case, <code>CollationKey</code>s
111 111 * provide better performance. The <code>CollationKey</code> class converts
112 112 * a <code>String</code> to a series of bits that can be compared bitwise
113 113 * against other <code>CollationKey</code>s. A <code>CollationKey</code> is
114 114 * created by a <code>Collator</code> object for a given <code>String</code>.
115 115 * <br>
116 116 * <strong>Note:</strong> <code>CollationKey</code>s from different
117 117 * <code>Collator</code>s can not be compared. See the class description
118 118 * for {@link CollationKey}
119 119 * for an example using <code>CollationKey</code>s.
120 120 *
121 121 * @see RuleBasedCollator
122 122 * @see CollationKey
123 123 * @see CollationElementIterator
124 124 * @see Locale
125 125 * @author Helena Shih, Laura Werner, Richard Gillam
126 126 */
127 127
128 128 public abstract class Collator
129 129 implements java.util.Comparator<Object>, Cloneable
130 130 {
131 131 /**
132 132 * Collator strength value. When set, only PRIMARY differences are
133 133 * considered significant during comparison. The assignment of strengths
134 134 * to language features is locale dependant. A common example is for
135 135 * different base letters ("a" vs "b") to be considered a PRIMARY difference.
136 136 * @see java.text.Collator#setStrength
137 137 * @see java.text.Collator#getStrength
138 138 */
139 139 public final static int PRIMARY = 0;
140 140 /**
141 141 * Collator strength value. When set, only SECONDARY and above differences are
142 142 * considered significant during comparison. The assignment of strengths
143 143 * to language features is locale dependant. A common example is for
144 144 * different accented forms of the same base letter ("a" vs "\u00E4") to be
145 145 * considered a SECONDARY difference.
146 146 * @see java.text.Collator#setStrength
147 147 * @see java.text.Collator#getStrength
148 148 */
149 149 public final static int SECONDARY = 1;
150 150 /**
151 151 * Collator strength value. When set, only TERTIARY and above differences are
152 152 * considered significant during comparison. The assignment of strengths
153 153 * to language features is locale dependant. A common example is for
154 154 * case differences ("a" vs "A") to be considered a TERTIARY difference.
155 155 * @see java.text.Collator#setStrength
156 156 * @see java.text.Collator#getStrength
157 157 */
158 158 public final static int TERTIARY = 2;
159 159
160 160 /**
161 161 * Collator strength value. When set, all differences are
162 162 * considered significant during comparison. The assignment of strengths
163 163 * to language features is locale dependant. A common example is for control
164 164 * characters ("\u0001" vs "\u0002") to be considered equal at the
165 165 * PRIMARY, SECONDARY, and TERTIARY levels but different at the IDENTICAL
166 166 * level. Additionally, differences between pre-composed accents such as
167 167 * "\u00C0" (A-grave) and combining accents such as "A\u0300"
168 168 * (A, combining-grave) will be considered significant at the IDENTICAL
169 169 * level if decomposition is set to NO_DECOMPOSITION.
170 170 */
171 171 public final static int IDENTICAL = 3;
172 172
173 173 /**
174 174 * Decomposition mode value. With NO_DECOMPOSITION
175 175 * set, accented characters will not be decomposed for collation. This
176 176 * is the default setting and provides the fastest collation but
177 177 * will only produce correct results for languages that do not use accents.
178 178 * @see java.text.Collator#getDecomposition
179 179 * @see java.text.Collator#setDecomposition
180 180 */
181 181 public final static int NO_DECOMPOSITION = 0;
182 182
183 183 /**
184 184 * Decomposition mode value. With CANONICAL_DECOMPOSITION
185 185 * set, characters that are canonical variants according to Unicode
186 186 * standard will be decomposed for collation. This should be used to get
187 187 * correct collation of accented characters.
188 188 * <p>
189 189 * CANONICAL_DECOMPOSITION corresponds to Normalization Form D as
190 190 * described in
191 191 * <a href="http://www.unicode.org/unicode/reports/tr15/tr15-23.html">Unicode
192 192 * Technical Report #15</a>.
193 193 * @see java.text.Collator#getDecomposition
194 194 * @see java.text.Collator#setDecomposition
195 195 */
196 196 public final static int CANONICAL_DECOMPOSITION = 1;
197 197
198 198 /**
199 199 * Decomposition mode value. With FULL_DECOMPOSITION
200 200 * set, both Unicode canonical variants and Unicode compatibility variants
201 201 * will be decomposed for collation. This causes not only accented
202 202 * characters to be collated, but also characters that have special formats
203 203 * to be collated with their norminal form. For example, the half-width and
204 204 * full-width ASCII and Katakana characters are then collated together.
205 205 * FULL_DECOMPOSITION is the most complete and therefore the slowest
206 206 * decomposition mode.
207 207 * <p>
208 208 * FULL_DECOMPOSITION corresponds to Normalization Form KD as
209 209 * described in
210 210 * <a href="http://www.unicode.org/unicode/reports/tr15/tr15-23.html">Unicode
211 211 * Technical Report #15</a>.
212 212 * @see java.text.Collator#getDecomposition
213 213 * @see java.text.Collator#setDecomposition
214 214 */
215 215 public final static int FULL_DECOMPOSITION = 2;
216 216
217 217 /**
218 218 * Gets the Collator for the current default locale.
219 219 * The default locale is determined by java.util.Locale.getDefault.
220 220 * @return the Collator for the default locale.(for example, en_US)
221 221 * @see java.util.Locale#getDefault
222 222 */
223 223 public static synchronized Collator getInstance() {
↓ open down ↓ |
165 lines elided |
↑ open up ↑ |
224 224 return getInstance(Locale.getDefault());
225 225 }
226 226
227 227 /**
228 228 * Gets the Collator for the desired locale.
229 229 * @param desiredLocale the desired locale.
230 230 * @return the Collator for the desired locale.
231 231 * @see java.util.Locale
232 232 * @see java.util.ResourceBundle
233 233 */
234 - public static synchronized
235 - Collator getInstance(Locale desiredLocale)
236 - {
237 - Collator result = (Collator) cache.get(desiredLocale);
238 - if (result != null) {
239 - return (Collator)result.clone(); // make the world safe
240 - }
241 -
242 - // Check whether a provider can provide an implementation that's closer
243 - // to the requested locale than what the Java runtime itself can provide.
244 - LocaleServiceProviderPool pool =
245 - LocaleServiceProviderPool.getPool(CollatorProvider.class);
246 - if (pool.hasProviders()) {
247 - Collator providersInstance = pool.getLocalizedObject(
248 - CollatorGetter.INSTANCE,
249 - desiredLocale,
250 - desiredLocale);
251 - if (providersInstance != null) {
252 - return providersInstance;
234 + public static Collator getInstance(Locale desiredLocale) {
235 + SoftReference<Collator> ref = cache.get(desiredLocale);
236 + Collator result = (ref != null) ? ref.get() : null;
237 + if (result == null) {
238 + LocaleProviderAdapter adapter = LocaleProviderAdapter.getAdapter(CollatorProvider.class,
239 + desiredLocale);
240 + CollatorProvider provider = adapter.getCollatorProvider();
241 + result = provider.getInstance(desiredLocale);
242 + if (result == null) {
243 + if (adapter.getAdapterType() != LocaleProviderAdapter.Type.JRE) {
244 + result = LocaleProviderAdapter.forJRE()
245 + .getCollatorProvider().getInstance(desiredLocale);
246 + }
247 + if (result == null) {
248 + throw new InternalError("Collator instance creation failed. (provider="
249 + + provider + ")");
253 250 }
254 - }
255 -
256 - // Load the resource of the desired locale from resource
257 - // manager.
258 - String colString = "";
259 - try {
260 - ResourceBundle resource = LocaleData.getCollationData(desiredLocale);
261 -
262 - colString = resource.getString("Rule");
263 - } catch (MissingResourceException e) {
264 - // Use default values
265 - }
266 - try
267 - {
268 - result = new RuleBasedCollator( CollationRules.DEFAULTRULES +
269 - colString,
270 - CANONICAL_DECOMPOSITION );
271 - }
272 - catch(ParseException foo)
273 - {
274 - // predefined tables should contain correct grammar
275 - try {
276 - result = new RuleBasedCollator( CollationRules.DEFAULTRULES );
277 - } catch (ParseException bar) {
278 - // do nothing
279 251 }
252 + while (true) {
253 + if (ref != null) {
254 + // Remove the empty SoftReference if any
255 + cache.remove(desiredLocale, ref);
256 + }
257 + ref = cache.putIfAbsent(desiredLocale, new SoftReference<>(result));
258 + if (ref == null) {
259 + break;
260 + }
261 + Collator cachedColl = ref.get();
262 + if (cachedColl != null) {
263 + result = cachedColl;
264 + break;
265 + }
266 + }
280 267 }
281 - // Now that RuleBasedCollator adds expansions for pre-composed characters
282 - // into their decomposed equivalents, the default collators don't need
283 - // to have decomposition turned on. Laura, 5/5/98, bug 4114077
284 - result.setDecomposition(NO_DECOMPOSITION);
285 -
286 - cache.put(desiredLocale,result);
287 - return (Collator)result.clone();
268 + return (Collator) result.clone(); // make the world safe
288 269 }
289 270
290 271 /**
291 272 * Compares the source string to the target string according to the
292 273 * collation rules for this Collator. Returns an integer less than,
293 274 * equal to or greater than zero depending on whether the source String is
294 275 * less than, equal to or greater than the target string. See the Collator
295 276 * class description for an example of use.
296 277 * <p>
297 278 * For a one time comparison, this method has the best performance. If a
298 279 * given String will be involved in multiple comparisons, CollationKey.compareTo
299 280 * has the best performance. See the Collator class description for an example
300 281 * using CollationKeys.
301 282 * @param source the source string.
302 283 * @param target the target string.
303 284 * @return Returns an integer value. Value is less than zero if source is less than
304 285 * target, value is zero if source and target are equal, value is greater than zero
305 286 * if source is greater than target.
306 287 * @see java.text.CollationKey
307 288 * @see java.text.Collator#getCollationKey
308 289 */
309 290 public abstract int compare(String source, String target);
310 291
311 292 /**
312 293 * Compares its two arguments for order. Returns a negative integer,
313 294 * zero, or a positive integer as the first argument is less than, equal
314 295 * to, or greater than the second.
315 296 * <p>
↓ open down ↓ |
18 lines elided |
↑ open up ↑ |
316 297 * This implementation merely returns
317 298 * <code> compare((String)o1, (String)o2) </code>.
318 299 *
319 300 * @return a negative integer, zero, or a positive integer as the
320 301 * first argument is less than, equal to, or greater than the
321 302 * second.
322 303 * @exception ClassCastException the arguments cannot be cast to Strings.
323 304 * @see java.util.Comparator
324 305 * @since 1.2
325 306 */
307 + @Override
326 308 public int compare(Object o1, Object o2) {
327 309 return compare((String)o1, (String)o2);
328 310 }
329 311
330 312 /**
331 313 * Transforms the String into a series of bits that can be compared bitwise
332 314 * to other CollationKeys. CollationKeys provide better performance than
333 315 * Collator.compare when Strings are involved in multiple comparisons.
334 316 * See the Collator class description for an example using CollationKeys.
335 317 * @param source the string to be transformed into a collation key.
336 318 * @return the CollationKey for the given String based on this Collator's collation
337 319 * rules. If the source String is null, a null CollationKey is returned.
338 320 * @see java.text.CollationKey
339 321 * @see java.text.Collator#compare
340 322 */
341 323 public abstract CollationKey getCollationKey(String source);
342 324
343 325 /**
344 326 * Convenience method for comparing the equality of two strings based on
345 327 * this Collator's collation rules.
346 328 * @param source the source string to be compared with.
347 329 * @param target the target string to be compared with.
348 330 * @return true if the strings are equal according to the collation
349 331 * rules. false, otherwise.
350 332 * @see java.text.Collator#compare
351 333 */
352 334 public boolean equals(String source, String target)
353 335 {
354 336 return (compare(source, target) == Collator.EQUAL);
355 337 }
356 338
357 339 /**
358 340 * Returns this Collator's strength property. The strength property determines
359 341 * the minimum level of difference considered significant during comparison.
360 342 * See the Collator class description for an example of use.
361 343 * @return this Collator's current strength property.
362 344 * @see java.text.Collator#setStrength
363 345 * @see java.text.Collator#PRIMARY
364 346 * @see java.text.Collator#SECONDARY
365 347 * @see java.text.Collator#TERTIARY
366 348 * @see java.text.Collator#IDENTICAL
367 349 */
368 350 public synchronized int getStrength()
369 351 {
370 352 return strength;
371 353 }
372 354
373 355 /**
374 356 * Sets this Collator's strength property. The strength property determines
375 357 * the minimum level of difference considered significant during comparison.
376 358 * See the Collator class description for an example of use.
377 359 * @param newStrength the new strength value.
378 360 * @see java.text.Collator#getStrength
379 361 * @see java.text.Collator#PRIMARY
↓ open down ↓ |
44 lines elided |
↑ open up ↑ |
380 362 * @see java.text.Collator#SECONDARY
381 363 * @see java.text.Collator#TERTIARY
382 364 * @see java.text.Collator#IDENTICAL
383 365 * @exception IllegalArgumentException If the new strength value is not one of
384 366 * PRIMARY, SECONDARY, TERTIARY or IDENTICAL.
385 367 */
386 368 public synchronized void setStrength(int newStrength) {
387 369 if ((newStrength != PRIMARY) &&
388 370 (newStrength != SECONDARY) &&
389 371 (newStrength != TERTIARY) &&
390 - (newStrength != IDENTICAL))
372 + (newStrength != IDENTICAL)) {
391 373 throw new IllegalArgumentException("Incorrect comparison level.");
374 + }
392 375 strength = newStrength;
393 376 }
394 377
395 378 /**
396 379 * Get the decomposition mode of this Collator. Decomposition mode
397 380 * determines how Unicode composed characters are handled. Adjusting
398 381 * decomposition mode allows the user to select between faster and more
399 382 * complete collation behavior.
400 383 * <p>The three values for decomposition mode are:
401 384 * <UL>
402 385 * <LI>NO_DECOMPOSITION,
403 386 * <LI>CANONICAL_DECOMPOSITION
404 387 * <LI>FULL_DECOMPOSITION.
405 388 * </UL>
406 389 * See the documentation for these three constants for a description
407 390 * of their meaning.
408 391 * @return the decomposition mode
409 392 * @see java.text.Collator#setDecomposition
410 393 * @see java.text.Collator#NO_DECOMPOSITION
411 394 * @see java.text.Collator#CANONICAL_DECOMPOSITION
412 395 * @see java.text.Collator#FULL_DECOMPOSITION
413 396 */
414 397 public synchronized int getDecomposition()
415 398 {
416 399 return decmp;
417 400 }
418 401 /**
419 402 * Set the decomposition mode of this Collator. See getDecomposition
420 403 * for a description of decomposition mode.
421 404 * @param decompositionMode the new decomposition mode.
↓ open down ↓ |
20 lines elided |
↑ open up ↑ |
422 405 * @see java.text.Collator#getDecomposition
423 406 * @see java.text.Collator#NO_DECOMPOSITION
424 407 * @see java.text.Collator#CANONICAL_DECOMPOSITION
425 408 * @see java.text.Collator#FULL_DECOMPOSITION
426 409 * @exception IllegalArgumentException If the given value is not a valid decomposition
427 410 * mode.
428 411 */
429 412 public synchronized void setDecomposition(int decompositionMode) {
430 413 if ((decompositionMode != NO_DECOMPOSITION) &&
431 414 (decompositionMode != CANONICAL_DECOMPOSITION) &&
432 - (decompositionMode != FULL_DECOMPOSITION))
415 + (decompositionMode != FULL_DECOMPOSITION)) {
433 416 throw new IllegalArgumentException("Wrong decomposition mode.");
417 + }
434 418 decmp = decompositionMode;
435 419 }
436 420
437 421 /**
438 422 * Returns an array of all locales for which the
439 423 * <code>getInstance</code> methods of this class can return
440 424 * localized instances.
441 425 * The returned array represents the union of locales supported
442 426 * by the Java runtime and by installed
443 427 * {@link java.text.spi.CollatorProvider CollatorProvider} implementations.
444 428 * It must contain at least a Locale instance equal to
445 429 * {@link java.util.Locale#US Locale.US}.
446 430 *
447 431 * @return An array of locales for which localized
448 432 * <code>Collator</code> instances are available.
↓ open down ↓ |
5 lines elided |
↑ open up ↑ |
449 433 */
450 434 public static synchronized Locale[] getAvailableLocales() {
451 435 LocaleServiceProviderPool pool =
452 436 LocaleServiceProviderPool.getPool(CollatorProvider.class);
453 437 return pool.getAvailableLocales();
454 438 }
455 439
456 440 /**
457 441 * Overrides Cloneable
458 442 */
443 + @Override
459 444 public Object clone()
460 445 {
461 446 try {
462 447 return (Collator)super.clone();
463 448 } catch (CloneNotSupportedException e) {
464 449 throw new InternalError(e);
465 450 }
466 451 }
467 452
468 453 /**
469 454 * Compares the equality of two Collators.
470 455 * @param that the Collator to be compared with this.
471 456 * @return true if this Collator is the same as that Collator;
472 457 * false otherwise.
473 458 */
459 + @Override
474 460 public boolean equals(Object that)
475 461 {
476 - if (this == that) return true;
477 - if (that == null) return false;
478 - if (getClass() != that.getClass()) return false;
462 + if (this == that) {
463 + return true;
464 + }
465 + if (that == null) {
466 + return false;
467 + }
468 + if (getClass() != that.getClass()) {
469 + return false;
470 + }
479 471 Collator other = (Collator) that;
480 472 return ((strength == other.strength) &&
481 473 (decmp == other.decmp));
482 474 }
483 475
484 476 /**
485 477 * Generates the hash code for this Collator.
486 478 */
479 + @Override
487 480 abstract public int hashCode();
488 481
489 482 /**
490 483 * Default constructor. This constructor is
491 484 * protected so subclasses can get access to it. Users typically create
492 485 * a Collator sub-class by calling the factory method getInstance.
493 486 * @see java.text.Collator#getInstance
494 487 */
495 488 protected Collator()
496 489 {
497 490 strength = TERTIARY;
498 491 decmp = CANONICAL_DECOMPOSITION;
499 492 }
500 493
501 494 private int strength = 0;
502 495 private int decmp = 0;
503 - private static SoftCache cache = new SoftCache();
496 + private static final ConcurrentMap<Locale, SoftReference<Collator>> cache
497 + = new ConcurrentHashMap<>();
504 498
505 499 //
506 500 // FIXME: These three constants should be removed.
507 501 //
508 502 /**
509 503 * LESS is returned if source string is compared to be less than target
510 504 * string in the compare() method.
511 505 * @see java.text.Collator#compare
512 506 */
513 507 final static int LESS = -1;
514 508 /**
515 509 * EQUAL is returned if source string is compared to be equal to target
↓ open down ↓ |
2 lines elided |
↑ open up ↑ |
516 510 * string in the compare() method.
517 511 * @see java.text.Collator#compare
518 512 */
519 513 final static int EQUAL = 0;
520 514 /**
521 515 * GREATER is returned if source string is compared to be greater than
522 516 * target string in the compare() method.
523 517 * @see java.text.Collator#compare
524 518 */
525 519 final static int GREATER = 1;
526 -
527 - /**
528 - * Obtains a Collator instance from a CollatorProvider
529 - * implementation.
530 - */
531 - private static class CollatorGetter
532 - implements LocaleServiceProviderPool.LocalizedObjectGetter<CollatorProvider, Collator> {
533 - private static final CollatorGetter INSTANCE = new CollatorGetter();
534 -
535 - public Collator getObject(CollatorProvider collatorProvider,
536 - Locale locale,
537 - String key,
538 - Object... params) {
539 - assert params.length == 1;
540 - Collator result = collatorProvider.getInstance(locale);
541 - if (result != null) {
542 - // put this Collator instance in the cache for two locales, one
543 - // is for the desired locale, and the other is for the actual
544 - // locale where the provider is found, which may be a fall back locale.
545 - cache.put((Locale)params[0], result);
546 - cache.put(locale, result);
547 - return (Collator)result.clone();
548 - }
549 -
550 - return null;
551 - }
552 - }
553 520 }
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX