jdk/src/share/classes/sun/util/locale/provider/CurrencyNameProviderImpl.java
author sherman
Tue, 12 Feb 2013 09:25:43 -0800
changeset 15658 55b829ca2334
parent 15260 7af2d7a87806
child 23010 6dadb192ad81
permissions -rw-r--r--
8007392: JSR 310: DateTime API Updates 8007520: Update date/time classes in j.util and j.sql packages 8007572: Replace existing jdk timezone data at <java.home>/lib/zi with JSR310's tzdb Summary: Integration of JSR310 Date/Time API for M7 Reviewed-by: darcy, alanb, naoto Contributed-by: scolebourne@joda.org, roger.riggs@oracle.com, masayoshi.okutsu@oracle.com, patrick.zhang@oracle.com
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
13583
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents:
diff changeset
     1
/*
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents:
diff changeset
     2
 * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved.
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents:
diff changeset
     4
 *
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents:
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents:
diff changeset
    10
 *
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents:
diff changeset
    15
 * accompanied this code).
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents:
diff changeset
    16
 *
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents:
diff changeset
    20
 *
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents:
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents:
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents:
diff changeset
    23
 * questions.
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents:
diff changeset
    24
 */
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents:
diff changeset
    25
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents:
diff changeset
    26
package sun.util.locale.provider;
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents:
diff changeset
    27
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents:
diff changeset
    28
import java.util.Locale;
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents:
diff changeset
    29
import java.util.Set;
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents:
diff changeset
    30
import java.util.spi.CurrencyNameProvider;
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents:
diff changeset
    31
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents:
diff changeset
    32
/**
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents:
diff changeset
    33
 * Concrete implementation of the
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents:
diff changeset
    34
 * {@link java.util.spi.CurrencyNameProvider CurrencyNameProvider} class
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents:
diff changeset
    35
 * for the JRE LocaleProviderAdapter.
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents:
diff changeset
    36
 *
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents:
diff changeset
    37
 * @author Naoto Sato
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents:
diff changeset
    38
 * @author Masayoshi Okutsu
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents:
diff changeset
    39
 */
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents:
diff changeset
    40
public class CurrencyNameProviderImpl extends CurrencyNameProvider
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents:
diff changeset
    41
                                      implements AvailableLanguageTags {
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents:
diff changeset
    42
    private final LocaleProviderAdapter.Type type;
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents:
diff changeset
    43
    private final Set<String> langtags;
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents:
diff changeset
    44
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents:
diff changeset
    45
    public CurrencyNameProviderImpl(LocaleProviderAdapter.Type type, Set<String> langtags) {
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents:
diff changeset
    46
        this.type = type;
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents:
diff changeset
    47
        this.langtags = langtags;
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents:
diff changeset
    48
    }
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents:
diff changeset
    49
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents:
diff changeset
    50
    @Override
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents:
diff changeset
    51
    public Set<String> getAvailableLanguageTags() {
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents:
diff changeset
    52
        return langtags;
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents:
diff changeset
    53
    }
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents:
diff changeset
    54
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents:
diff changeset
    55
    /**
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents:
diff changeset
    56
     * Returns an array of all locales for which this locale service provider
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents:
diff changeset
    57
     * can provide localized objects or names.
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents:
diff changeset
    58
     *
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents:
diff changeset
    59
     * @return An array of all locales for which this locale service provider
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents:
diff changeset
    60
     * can provide localized objects or names.
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents:
diff changeset
    61
     */
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents:
diff changeset
    62
    @Override
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents:
diff changeset
    63
    public Locale[] getAvailableLocales() {
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents:
diff changeset
    64
        return LocaleProviderAdapter.toLocaleArray(langtags);
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents:
diff changeset
    65
    }
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents:
diff changeset
    66
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents:
diff changeset
    67
    /**
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents:
diff changeset
    68
     * Gets the symbol of the given currency code for the specified locale.
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents:
diff changeset
    69
     * For example, for "USD" (US Dollar), the symbol is "$" if the specified
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents:
diff changeset
    70
     * locale is the US, while for other locales it may be "US$". If no
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents:
diff changeset
    71
     * symbol can be determined, null should be returned.
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents:
diff changeset
    72
     *
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents:
diff changeset
    73
     * @param currencyCode the ISO 4217 currency code, which
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents:
diff changeset
    74
     *     consists of three upper-case letters between 'A' (U+0041) and
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents:
diff changeset
    75
     *     'Z' (U+005A)
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents:
diff changeset
    76
     * @param locale the desired locale
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents:
diff changeset
    77
     * @return the symbol of the given currency code for the specified locale, or null if
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents:
diff changeset
    78
     *     the symbol is not available for the locale
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents:
diff changeset
    79
     * @exception NullPointerException if <code>currencyCode</code> or
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents:
diff changeset
    80
     *     <code>locale</code> is null
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents:
diff changeset
    81
     * @exception IllegalArgumentException if <code>currencyCode</code> is not in
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents:
diff changeset
    82
     *     the form of three upper-case letters, or <code>locale</code> isn't
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents:
diff changeset
    83
     *     one of the locales returned from
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents:
diff changeset
    84
     *     {@link java.util.spi.LocaleServiceProvider#getAvailableLocales()
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents:
diff changeset
    85
     *     getAvailableLocales()}.
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents:
diff changeset
    86
     * @see java.util.Currency#getSymbol(java.util.Locale)
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents:
diff changeset
    87
     */
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents:
diff changeset
    88
    @Override
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents:
diff changeset
    89
    public String getSymbol(String currencyCode, Locale locale) {
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents:
diff changeset
    90
        return getString(currencyCode.toUpperCase(Locale.ROOT), locale);
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents:
diff changeset
    91
    }
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents:
diff changeset
    92
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents:
diff changeset
    93
    /**
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents:
diff changeset
    94
     * Returns a name for the currency that is appropriate for display to the
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents:
diff changeset
    95
     * user.  The default implementation returns null.
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents:
diff changeset
    96
     *
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents:
diff changeset
    97
     * @param currencyCode the ISO 4217 currency code, which
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents:
diff changeset
    98
     *     consists of three upper-case letters between 'A' (U+0041) and
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents:
diff changeset
    99
     *     'Z' (U+005A)
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents:
diff changeset
   100
     * @param locale the desired locale
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents:
diff changeset
   101
     * @return the name for the currency that is appropriate for display to the
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents:
diff changeset
   102
     *     user, or null if the name is not available for the locale
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents:
diff changeset
   103
     * @exception IllegalArgumentException if <code>currencyCode</code> is not in
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents:
diff changeset
   104
     *     the form of three upper-case letters, or <code>locale</code> isn't
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents:
diff changeset
   105
     *     one of the locales returned from
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents:
diff changeset
   106
     *     {@link java.util.spi.LocaleServiceProvider#getAvailableLocales()
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents:
diff changeset
   107
     *     getAvailableLocales()}.
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents:
diff changeset
   108
     * @exception NullPointerException if <code>currencyCode</code> or
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents:
diff changeset
   109
     *     <code>locale</code> is <code>null</code>
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents:
diff changeset
   110
     * @since 1.7
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents:
diff changeset
   111
     */
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents:
diff changeset
   112
    @Override
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents:
diff changeset
   113
    public String getDisplayName(String currencyCode, Locale locale) {
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents:
diff changeset
   114
        return getString(currencyCode.toLowerCase(Locale.ROOT), locale);
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents:
diff changeset
   115
    }
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents:
diff changeset
   116
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents:
diff changeset
   117
    private String getString(String key, Locale locale) {
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents:
diff changeset
   118
        if (locale == null) {
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents:
diff changeset
   119
            throw new NullPointerException();
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents:
diff changeset
   120
        }
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents:
diff changeset
   121
15260
7af2d7a87806 7162007: Clean up i18n related caches
naoto
parents: 14185
diff changeset
   122
        return LocaleProviderAdapter.forType(type).getLocaleResources(locale).getCurrencyName(key);
13583
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents:
diff changeset
   123
    }
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents:
diff changeset
   124
}