use of java.text.spi.CollatorProvider in project jdk8u_jdk by JetBrains.
the class Collator method getInstance.
/**
* Gets the Collator for the desired locale.
* @param desiredLocale the desired locale.
* @return the Collator for the desired locale.
* @see java.util.Locale
* @see java.util.ResourceBundle
*/
public static Collator getInstance(Locale desiredLocale) {
SoftReference<Collator> ref = cache.get(desiredLocale);
Collator result = (ref != null) ? ref.get() : null;
if (result == null) {
LocaleProviderAdapter adapter;
adapter = LocaleProviderAdapter.getAdapter(CollatorProvider.class, desiredLocale);
CollatorProvider provider = adapter.getCollatorProvider();
result = provider.getInstance(desiredLocale);
if (result == null) {
result = LocaleProviderAdapter.forJRE().getCollatorProvider().getInstance(desiredLocale);
}
while (true) {
if (ref != null) {
// Remove the empty SoftReference if any
cache.remove(desiredLocale, ref);
}
ref = cache.putIfAbsent(desiredLocale, new SoftReference<>(result));
if (ref == null) {
break;
}
Collator cachedColl = ref.get();
if (cachedColl != null) {
result = cachedColl;
break;
}
}
}
// make the world safe
return (Collator) result.clone();
}
Aggregations