src/java.base/share/classes/sun/util/locale/provider/LocaleNameProviderImpl.java

Print this page
rev 10528 : 8038436: Re-examine the mechanism to determine available localedata and cldrdata
Reviewed-by:

*** 1,7 **** /* ! * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. Oracle designates this --- 1,7 ---- /* ! * Copyright (c) 2012, 2014, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. Oracle designates this
*** 37,51 **** * @author Naoto Sato * @author Masayoshi Okutsu */ public class LocaleNameProviderImpl extends LocaleNameProvider implements AvailableLanguageTags { private final LocaleProviderAdapter.Type type; ! private final Set<String> langtags; ! public LocaleNameProviderImpl(LocaleProviderAdapter.Type type, Set<String> langtags) { this.type = type; - this.langtags = langtags; } /** * Returns an array of all locales for which this locale service provider * can provide localized objects or names. --- 37,50 ---- * @author Naoto Sato * @author Masayoshi Okutsu */ public class LocaleNameProviderImpl extends LocaleNameProvider implements AvailableLanguageTags { private final LocaleProviderAdapter.Type type; ! private Set<String> langtags; ! public LocaleNameProviderImpl(LocaleProviderAdapter.Type type) { this.type = type; } /** * Returns an array of all locales for which this locale service provider * can provide localized objects or names.
*** 53,68 **** * @return An array of all locales for which this locale service provider * can provide localized objects or names. */ @Override public Locale[] getAvailableLocales() { ! return LocaleProviderAdapter.toLocaleArray(langtags); } @Override public boolean isSupportedLocale(Locale locale) { ! return LocaleProviderAdapter.isSupportedLocale(locale, type, langtags); } /** * Returns a localized name for the given ISO 639 language code and the * given locale that is appropriate for display to the user. --- 52,67 ---- * @return An array of all locales for which this locale service provider * can provide localized objects or names. */ @Override public Locale[] getAvailableLocales() { ! return LocaleProviderAdapter.toLocaleArray(getLangTags()); } @Override public boolean isSupportedLocale(Locale locale) { ! return LocaleProviderAdapter.isSupportedLocale(locale, type, getLangTags()); } /** * Returns a localized name for the given ISO 639 language code and the * given locale that is appropriate for display to the user.
*** 84,95 **** * {@link java.util.spi.LocaleServiceProvider#getAvailableLocales() * getAvailableLocales()}. * @see java.util.Locale#getDisplayLanguage(java.util.Locale) */ @Override ! public String getDisplayLanguage(String lang, Locale locale) { ! return getDisplayString(lang, locale); } /** * Returns a localized name for the given <a href="http://www.rfc-editor.org/rfc/bcp/bcp47.txt"> * IETF BCP47</a> script code and the given locale that is appropriate for --- 83,94 ---- * {@link java.util.spi.LocaleServiceProvider#getAvailableLocales() * getAvailableLocales()}. * @see java.util.Locale#getDisplayLanguage(java.util.Locale) */ @Override ! public String getDisplayLanguage(String languageCode, Locale locale) { ! return getDisplayString(languageCode, locale); } /** * Returns a localized name for the given <a href="http://www.rfc-editor.org/rfc/bcp/bcp47.txt"> * IETF BCP47</a> script code and the given locale that is appropriate for
*** 141,152 **** * {@link java.util.spi.LocaleServiceProvider#getAvailableLocales() * getAvailableLocales()}. * @see java.util.Locale#getDisplayCountry(java.util.Locale) */ @Override ! public String getDisplayCountry(String ctry, Locale locale) { ! return getDisplayString(ctry, locale); } /** * Returns a localized name for the given variant code and the given locale that * is appropriate for display to the user. --- 140,151 ---- * {@link java.util.spi.LocaleServiceProvider#getAvailableLocales() * getAvailableLocales()}. * @see java.util.Locale#getDisplayCountry(java.util.Locale) */ @Override ! public String getDisplayCountry(String countryCode, Locale locale) { ! return getDisplayString(countryCode, locale); } /** * Returns a localized name for the given variant code and the given locale that * is appropriate for display to the user.
*** 162,173 **** * {@link java.util.spi.LocaleServiceProvider#getAvailableLocales() * getAvailableLocales()}. * @see java.util.Locale#getDisplayVariant(java.util.Locale) */ @Override ! public String getDisplayVariant(String vrnt, Locale locale) { ! return getDisplayString("%%"+vrnt, locale); } private String getDisplayString(String key, Locale locale) { if (key == null || locale == null) { throw new NullPointerException(); --- 161,172 ---- * {@link java.util.spi.LocaleServiceProvider#getAvailableLocales() * getAvailableLocales()}. * @see java.util.Locale#getDisplayVariant(java.util.Locale) */ @Override ! public String getDisplayVariant(String variant, Locale locale) { ! return getDisplayString("%%"+variant, locale); } private String getDisplayString(String key, Locale locale) { if (key == null || locale == null) { throw new NullPointerException();
*** 176,183 **** --- 175,189 ---- return LocaleProviderAdapter.forType(type).getLocaleResources(locale).getLocaleName(key); } @Override public Set<String> getAvailableLanguageTags() { + return getLangTags(); + } + + private Set<String> getLangTags() { + if (langtags == null) { + langtags = ((JRELocaleProviderAdapter)LocaleProviderAdapter.forType(type)).getLanguageTagSet("LocaleNames"); + } return langtags; } }