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

Print this page
rev 6352 : imported patch 7162007


   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 package sun.util.locale.provider;
  27 
  28 import java.util.Locale;
  29 import java.util.ResourceBundle;
  30 import java.util.Set;
  31 import java.util.spi.CurrencyNameProvider;
  32 
  33 /**
  34  * Concrete implementation of the
  35  * {@link java.util.spi.CurrencyNameProvider CurrencyNameProvider} class
  36  * for the JRE LocaleProviderAdapter.
  37  *
  38  * @author Naoto Sato
  39  * @author Masayoshi Okutsu
  40  */
  41 public class CurrencyNameProviderImpl extends CurrencyNameProvider
  42                                       implements AvailableLanguageTags {
  43     private final LocaleProviderAdapter.Type type;
  44     private final Set<String> langtags;
  45 
  46     public CurrencyNameProviderImpl(LocaleProviderAdapter.Type type, Set<String> langtags) {
  47         this.type = type;
  48         this.langtags = langtags;
  49     }


 103      *     user, or null if the name is not available for the locale
 104      * @exception IllegalArgumentException if <code>currencyCode</code> is not in
 105      *     the form of three upper-case letters, or <code>locale</code> isn't
 106      *     one of the locales returned from
 107      *     {@link java.util.spi.LocaleServiceProvider#getAvailableLocales()
 108      *     getAvailableLocales()}.
 109      * @exception NullPointerException if <code>currencyCode</code> or
 110      *     <code>locale</code> is <code>null</code>
 111      * @since 1.7
 112      */
 113     @Override
 114     public String getDisplayName(String currencyCode, Locale locale) {
 115         return getString(currencyCode.toLowerCase(Locale.ROOT), locale);
 116     }
 117 
 118     private String getString(String key, Locale locale) {
 119         if (locale == null) {
 120             throw new NullPointerException();
 121         }
 122 
 123         ResourceBundle bundle = LocaleProviderAdapter.forType(type).getLocaleData().getCurrencyNames(locale);
 124         if (bundle.containsKey(key)) {
 125                 return bundle.getString(key);
 126             }
 127 
 128         return null;
 129     }
 130 }


   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 package sun.util.locale.provider;
  27 
  28 import java.util.Locale;

  29 import java.util.Set;
  30 import java.util.spi.CurrencyNameProvider;
  31 
  32 /**
  33  * Concrete implementation of the
  34  * {@link java.util.spi.CurrencyNameProvider CurrencyNameProvider} class
  35  * for the JRE LocaleProviderAdapter.
  36  *
  37  * @author Naoto Sato
  38  * @author Masayoshi Okutsu
  39  */
  40 public class CurrencyNameProviderImpl extends CurrencyNameProvider
  41                                       implements AvailableLanguageTags {
  42     private final LocaleProviderAdapter.Type type;
  43     private final Set<String> langtags;
  44 
  45     public CurrencyNameProviderImpl(LocaleProviderAdapter.Type type, Set<String> langtags) {
  46         this.type = type;
  47         this.langtags = langtags;
  48     }


 102      *     user, or null if the name is not available for the locale
 103      * @exception IllegalArgumentException if <code>currencyCode</code> is not in
 104      *     the form of three upper-case letters, or <code>locale</code> isn't
 105      *     one of the locales returned from
 106      *     {@link java.util.spi.LocaleServiceProvider#getAvailableLocales()
 107      *     getAvailableLocales()}.
 108      * @exception NullPointerException if <code>currencyCode</code> or
 109      *     <code>locale</code> is <code>null</code>
 110      * @since 1.7
 111      */
 112     @Override
 113     public String getDisplayName(String currencyCode, Locale locale) {
 114         return getString(currencyCode.toLowerCase(Locale.ROOT), locale);
 115     }
 116 
 117     private String getString(String key, Locale locale) {
 118         if (locale == null) {
 119             throw new NullPointerException();
 120         }
 121 
 122         return LocaleProviderAdapter.forType(type).getLocaleResources(locale).getCurrencyName(key);


 123     }



 124 }