Home | History | Annotate | Download | only in util
      1 //  2016 and later: Unicode, Inc. and others.
      2 // License & terms of use: http://www.unicode.org/copyright.html#License
      3 /*
      4  *******************************************************************************
      5  * Copyright (C) 2008-2012, International Business Machines Corporation and    *
      6  * others. All Rights Reserved.                                                *
      7  *******************************************************************************
      8  */
      9 package com.ibm.icu.impl.javaspi.util;
     10 
     11 import java.util.Locale;
     12 import java.util.spi.CurrencyNameProvider;
     13 
     14 import com.ibm.icu.impl.javaspi.ICULocaleServiceProvider;
     15 import com.ibm.icu.text.CurrencyDisplayNames;
     16 
     17 public class CurrencyNameProviderICU extends CurrencyNameProvider {
     18 
     19     @Override
     20     public String getSymbol(String currencyCode, Locale locale) {
     21         CurrencyDisplayNames curDispNames = CurrencyDisplayNames.getInstance(ICULocaleServiceProvider.toULocaleNoSpecialVariant(locale));
     22         String sym = curDispNames.getSymbol(currencyCode);
     23         if (sym == null || sym.equals(currencyCode)) {
     24             return null;
     25         }
     26         return sym;
     27     }
     28 
     29     // Not available in Java 6
     30     // @Override
     31     public String getDisplayName(String currencyCode, Locale locale) {
     32         CurrencyDisplayNames curDispNames = CurrencyDisplayNames.getInstance(ICULocaleServiceProvider.toULocaleNoSpecialVariant(locale));
     33         String name = curDispNames.getName(currencyCode);
     34         if (name == null || name.equals(currencyCode)) {
     35             return null;
     36         }
     37         return name;
     38     }
     39 
     40     @Override
     41     public Locale[] getAvailableLocales() {
     42         return ICULocaleServiceProvider.getAvailableLocales();
     43     }
     44 
     45 }
     46