Path: blob/master/src/java.base/share/classes/sun/util/locale/provider/CurrencyNameProviderImpl.java
41161 views
/*1* Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/2425package sun.util.locale.provider;2627import java.util.Locale;28import java.util.Set;29import java.util.spi.CurrencyNameProvider;3031/**32* Concrete implementation of the33* {@link java.util.spi.CurrencyNameProvider CurrencyNameProvider} class34* for the JRE LocaleProviderAdapter.35*36* @author Naoto Sato37* @author Masayoshi Okutsu38*/39public class CurrencyNameProviderImpl extends CurrencyNameProvider40implements AvailableLanguageTags {41private final LocaleProviderAdapter.Type type;42private final Set<String> langtags;4344public CurrencyNameProviderImpl(LocaleProviderAdapter.Type type, Set<String> langtags) {45this.type = type;46this.langtags = langtags;47}4849@Override50public Set<String> getAvailableLanguageTags() {51return langtags;52}5354/**55* Returns an array of all locales for which this locale service provider56* can provide localized objects or names.57*58* @return An array of all locales for which this locale service provider59* can provide localized objects or names.60*/61@Override62public Locale[] getAvailableLocales() {63return LocaleProviderAdapter.toLocaleArray(langtags);64}6566/**67* Gets the symbol of the given currency code for the specified locale.68* For example, for "USD" (US Dollar), the symbol is "$" if the specified69* locale is the US, while for other locales it may be "US$". If no70* symbol can be determined, null should be returned.71*72* @param currencyCode the ISO 4217 currency code, which73* consists of three upper-case letters between 'A' (U+0041) and74* 'Z' (U+005A)75* @param locale the desired locale76* @return the symbol of the given currency code for the specified locale, or null if77* the symbol is not available for the locale78* @exception NullPointerException if <code>currencyCode</code> or79* <code>locale</code> is null80* @exception IllegalArgumentException if <code>currencyCode</code> is not in81* the form of three upper-case letters, or <code>locale</code> isn't82* one of the locales returned from83* {@link java.util.spi.LocaleServiceProvider#getAvailableLocales()84* getAvailableLocales()}.85* @see java.util.Currency#getSymbol(java.util.Locale)86*/87@Override88public String getSymbol(String currencyCode, Locale locale) {89return getString(currencyCode.toUpperCase(Locale.ROOT), locale);90}9192/**93* Returns a name for the currency that is appropriate for display to the94* user. The default implementation returns null.95*96* @param currencyCode the ISO 4217 currency code, which97* consists of three upper-case letters between 'A' (U+0041) and98* 'Z' (U+005A)99* @param locale the desired locale100* @return the name for the currency that is appropriate for display to the101* user, or null if the name is not available for the locale102* @exception IllegalArgumentException if <code>currencyCode</code> is not in103* the form of three upper-case letters, or <code>locale</code> isn't104* one of the locales returned from105* {@link java.util.spi.LocaleServiceProvider#getAvailableLocales()106* getAvailableLocales()}.107* @exception NullPointerException if <code>currencyCode</code> or108* <code>locale</code> is <code>null</code>109* @since 1.7110*/111@Override112public String getDisplayName(String currencyCode, Locale locale) {113return getString(currencyCode.toLowerCase(Locale.ROOT), locale);114}115116private String getString(String key, Locale locale) {117if (locale == null) {118throw new NullPointerException();119}120121return LocaleProviderAdapter.forType(type).getLocaleResources(locale).getCurrencyName(key);122}123}124125126