src/share/classes/sun/util/locale/provider/LocaleServiceProviderPool.java

Print this page
rev 6057 : imported patch 8001205.8001562

*** 24,33 **** --- 24,34 ---- */ package sun.util.locale.provider; import java.util.ArrayList; + import java.util.Arrays; import java.util.Collections; import java.util.HashSet; import java.util.IllformedLocaleException; import java.util.List; import java.util.Locale;
*** 175,185 **** static { Set<Locale> all = new HashSet<>(); for (Class<? extends LocaleServiceProvider> c : spiClasses) { LocaleServiceProviderPool pool = LocaleServiceProviderPool.getPool(c); ! all.addAll(pool.getAvailableLocaleList()); } allAvailableLocales = all.toArray(new Locale[0]); } --- 176,186 ---- static { Set<Locale> all = new HashSet<>(); for (Class<? extends LocaleServiceProvider> c : spiClasses) { LocaleServiceProviderPool pool = LocaleServiceProviderPool.getPool(c); ! all.addAll(pool.getAvailableLocaleSet()); } allAvailableLocales = all.toArray(new Locale[0]); }
*** 200,232 **** } /** * Returns an array of available locales. This array is a * merged array of all the locales that are provided by each ! * provider, including the JRE. * * @return an array of the available locales */ public Locale[] getAvailableLocales() { ! Set<Locale> locList = getAvailableLocaleList(); Locale[] tmp = new Locale[locList.size()]; locList.toArray(tmp); return tmp; } ! private synchronized Set<Locale> getAvailableLocaleList() { if (availableLocales == null) { availableLocales = new HashSet<>(); for (LocaleServiceProvider lsp : providers.values()) { Locale[] locales = lsp.getAvailableLocales(); for (Locale locale: locales) { availableLocales.add(getLookupLocale(locale)); } } - - // Remove Locale.ROOT for the compatibility. - availableLocales.remove(Locale.ROOT); } return availableLocales; } --- 201,240 ---- } /** * Returns an array of available locales. This array is a * merged array of all the locales that are provided by each ! * provider, including the JRE's FormatData locales. * * @return an array of the available locales */ public Locale[] getAvailableLocales() { ! Set<Locale> locList = new HashSet<>(); ! locList.addAll(getAvailableLocaleSet()); ! // Make sure it all contains JRE's FormatData locales for compatibility. ! locList.addAll(Arrays.asList(LocaleProviderAdapter.forJRE().getAvailableLocales())); Locale[] tmp = new Locale[locList.size()]; locList.toArray(tmp); return tmp; } ! /** ! * Returns the union of locale sets that are available from ! * each service provider. This method does NOT return the ! * defensive copy. ! * ! * @return a set of available locales ! */ ! private synchronized Set<Locale> getAvailableLocaleSet() { if (availableLocales == null) { availableLocales = new HashSet<>(); for (LocaleServiceProvider lsp : providers.values()) { Locale[] locales = lsp.getAvailableLocales(); for (Locale locale: locales) { availableLocales.add(getLookupLocale(locale)); } } } return availableLocales; }
*** 293,303 **** locale, key, params); } List<Locale> lookupLocales = getLookupLocales(locale); ! Set<Locale> available = getAvailableLocaleList(); for (Locale current : lookupLocales) { if (available.contains(current)) { S providersObj; for (LocaleProviderAdapter.Type type: findProviders(current)) { --- 301,311 ---- locale, key, params); } List<Locale> lookupLocales = getLookupLocales(locale); ! Set<Locale> available = getAvailableLocaleSet(); for (Locale current : lookupLocales) { if (available.contains(current)) { S providersObj; for (LocaleProviderAdapter.Type type: findProviders(current)) {