use of sun.util.locale.provider.LocaleProviderAdapter in project jdk8u_jdk by JetBrains.
the class LocaleProviders method bug8010666Test.
// This test assumes Windows localized language/country display names.
static void bug8010666Test() {
if (System.getProperty("os.name").startsWith("Windows")) {
NumberFormat nf = NumberFormat.getInstance(Locale.US);
try {
double ver = nf.parse(System.getProperty("os.version")).doubleValue();
System.out.printf("Windows version: %.1f\n", ver);
if (ver >= 6.0) {
LocaleProviderAdapter lda = LocaleProviderAdapter.getAdapter(LocaleNameProvider.class, Locale.ENGLISH);
LocaleProviderAdapter.Type type = lda.getAdapterType();
if (type == LocaleProviderAdapter.Type.HOST) {
LocaleNameProvider lnp = lda.getLocaleNameProvider();
Locale mkmk = Locale.forLanguageTag("mk-MK");
String result = mkmk.getDisplayLanguage(Locale.ENGLISH);
String hostResult = lnp.getDisplayLanguage(mkmk.getLanguage(), Locale.ENGLISH);
System.out.printf(" Display language name for" + " (mk_MK): result(HOST): \"%s\", returned: \"%s\"\n", hostResult, result);
if (result == null || hostResult != null && !result.equals(hostResult)) {
throw new RuntimeException("Display language name" + " mismatch for \"mk\". Returned name was" + " \"" + result + "\", result(HOST): \"" + hostResult + "\"");
}
result = Locale.US.getDisplayLanguage(Locale.ENGLISH);
hostResult = lnp.getDisplayLanguage(Locale.US.getLanguage(), Locale.ENGLISH);
System.out.printf(" Display language name for" + " (en_US): result(HOST): \"%s\", returned: \"%s\"\n", hostResult, result);
if (result == null || hostResult != null && !result.equals(hostResult)) {
throw new RuntimeException("Display language name" + " mismatch for \"en\". Returned name was" + " \"" + result + "\", result(HOST): \"" + hostResult + "\"");
}
if (ver >= 6.1) {
result = Locale.US.getDisplayCountry(Locale.ENGLISH);
hostResult = lnp.getDisplayCountry(Locale.US.getCountry(), Locale.ENGLISH);
System.out.printf(" Display country name for" + " (en_US): result(HOST): \"%s\", returned: \"%s\"\n", hostResult, result);
if (result == null || hostResult != null && !result.equals(hostResult)) {
throw new RuntimeException("Display country name" + " mismatch for \"US\". Returned name was" + " \"" + result + "\", result(HOST): \"" + hostResult + "\"");
}
}
} else {
throw new RuntimeException("Windows Host" + " LocaleProviderAdapter was not selected for" + " English locale.");
}
}
} catch (ParseException pe) {
throw new RuntimeException("Parsing Windows version failed: " + pe.toString());
}
}
}
use of sun.util.locale.provider.LocaleProviderAdapter in project jdk8u_jdk by JetBrains.
the class LocaleProviders method adapterTest.
static void adapterTest(String expected, String lang, String ctry) {
Locale testLocale = new Locale(lang, ctry);
LocaleProviderAdapter ldaExpected = LocaleProviderAdapter.forType(LocaleProviderAdapter.Type.valueOf(expected));
if (!ldaExpected.getDateFormatProvider().isSupportedLocale(testLocale)) {
System.out.println("test locale: " + testLocale + " is not supported by the expected provider: " + ldaExpected + ". Ignoring the test.");
return;
}
String preference = System.getProperty("java.locale.providers", "");
LocaleProviderAdapter lda = LocaleProviderAdapter.getAdapter(DateFormatProvider.class, testLocale);
LocaleProviderAdapter.Type type = lda.getAdapterType();
System.out.printf("testLocale: %s, got: %s, expected: %s\n", testLocale, type, expected);
if (!type.toString().equals(expected)) {
throw new RuntimeException("Returned locale data adapter is not correct.");
}
}
use of sun.util.locale.provider.LocaleProviderAdapter in project jdk8u_jdk by JetBrains.
the class DateFormatSymbols method getProviderInstance.
private static DateFormatSymbols getProviderInstance(Locale locale) {
LocaleProviderAdapter adapter = LocaleProviderAdapter.getAdapter(DateFormatSymbolsProvider.class, locale);
DateFormatSymbolsProvider provider = adapter.getDateFormatSymbolsProvider();
DateFormatSymbols dfsyms = provider.getInstance(locale);
if (dfsyms == null) {
provider = LocaleProviderAdapter.forJRE().getDateFormatSymbolsProvider();
dfsyms = provider.getInstance(locale);
}
return dfsyms;
}
use of sun.util.locale.provider.LocaleProviderAdapter in project jdk8u_jdk by JetBrains.
the class NumberFormat method getInstance.
// =======================privates===============================
private static NumberFormat getInstance(Locale desiredLocale, int choice) {
LocaleProviderAdapter adapter;
adapter = LocaleProviderAdapter.getAdapter(NumberFormatProvider.class, desiredLocale);
NumberFormat numberFormat = getInstance(adapter, desiredLocale, choice);
if (numberFormat == null) {
numberFormat = getInstance(LocaleProviderAdapter.forJRE(), desiredLocale, choice);
}
return numberFormat;
}
use of sun.util.locale.provider.LocaleProviderAdapter 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