@Override public CollatorProvider getCollatorProvider() { if (collatorProvider == null) { CollatorProvider provider = AccessController.doPrivileged( (PrivilegedAction<CollatorProvider>) () -> new CollatorProviderImpl( getAdapterType(), getLanguageTagSet("CollationData"))); synchronized (this) { if (collatorProvider == null) { collatorProvider = provider; } } } return collatorProvider; }
public Collator getObject(CollatorProvider collatorProvider, Locale locale, String key, Object... params) { assert params.length == 1; Collator result = collatorProvider.getInstance(locale); if (result != null) { // put this Collator instance in the cache for two locales, one // is for the desired locale, and the other is for the actual // locale where the provider is found, which may be a fall back locale. cache.put((Locale)params[0], result); cache.put(locale, result); return (Collator)result.clone(); } return null; }
/** * 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; } } } return (Collator) result.clone(); // make the world safe }
@Override public CollatorProvider getCollatorProvider() { if (collatorProvider == null) { CollatorProvider provider = new CollatorProviderImpl(getAdapterType(), getLanguageTagSet("CollationData")); synchronized (this) { if (collatorProvider == null) { collatorProvider = provider; } } } return collatorProvider; }
@Override public CollatorProvider getCollatorProvider() { return getLocaleServiceProvider(CollatorProvider.class); }
@Override public void addImpl(CollatorProvider impl) { for (Locale l : impl.getAvailableLocales()) { map.putIfAbsent(l, impl); } }
@Override public CollatorProvider getImpl(Locale locale) { return SPILocaleProviderAdapter.getImpl(map, locale); }
@Override public CollatorProvider getCollatorProvider() { return null; }