src/share/classes/java/util/spi/CurrencyNameProvider.java

Print this page
rev 5615 : 6336885: RFE: Locale Data Deployment Enhancements
4609153: Provide locale data for Indic locales
5104387: Support for gl_ES locale (galician language)
6337471: desktop/system locale preferences support
7056139: (cal) SPI support for locale-dependent Calendar parameters
7058206: Provide CalendarData SPI for week params and display field value names
7073852: Support multiple scripts for digits and decimal symbols per locale
7079560: [Fmt-Da] Context dependent month names support in SimpleDateFormat
7171324: getAvailableLocales() of locale sensitive services should return the actual availability of locales
7151414: (cal) Support calendar type identification
7168528: LocaleServiceProvider needs to be aware of Locale extensions
7171372: (cal) locale's default Calendar should be created if unknown calendar is specified
Summary: JEP 127: Improve Locale Data Packaging and Adopt Unicode CLDR Data (part 1 w/o Jigsaw. by Naoto Sato and Masayoshi Okutsu)


  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 java.util.spi;
  27 
  28 import java.util.Arrays;
  29 import java.util.Currency;
  30 import java.util.List;
  31 import java.util.Locale;

  32 
  33 /**
  34  * An abstract class for service providers that
  35  * provide localized currency symbols and display names for the
  36  * {@link java.util.Currency Currency} class.
  37  * Note that currency symbols are considered names when determining
  38  * behaviors described in the
  39  * {@link java.util.spi.LocaleServiceProvider LocaleServiceProvider}
  40  * specification.
  41  *
  42  * @since        1.6
  43  */
  44 public abstract class CurrencyNameProvider extends LocaleServiceProvider {
  45 
  46     /**
  47      * Sole constructor.  (For invocation by subclass constructors, typically
  48      * implicit.)
  49      */
  50     protected CurrencyNameProvider() {
  51     }


  92      *     <code>locale</code> is <code>null</code>
  93      * @since 1.7
  94      */
  95     public String getDisplayName(String currencyCode, Locale locale) {
  96         if (currencyCode == null || locale == null) {
  97             throw new NullPointerException();
  98         }
  99 
 100         // Check whether the currencyCode is valid
 101         char[] charray = currencyCode.toCharArray();
 102         if (charray.length != 3) {
 103             throw new IllegalArgumentException("The currencyCode is not in the form of three upper-case letters.");
 104         }
 105         for (char c : charray) {
 106             if (c < 'A' || c > 'Z') {
 107                 throw new IllegalArgumentException("The currencyCode is not in the form of three upper-case letters.");
 108             }
 109         }
 110 
 111         // Check whether the locale is valid
 112         List<Locale> avail = Arrays.asList(getAvailableLocales());
 113         if (!avail.contains(locale)) {
 114             throw new IllegalArgumentException("The locale is not available");

 115         }

 116 
 117         return null;
 118     }
 119 }


  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 java.util.spi;
  27 
  28 import java.util.Arrays;
  29 import java.util.Currency;
  30 import java.util.List;
  31 import java.util.Locale;
  32 import java.util.ResourceBundle.Control;
  33 
  34 /**
  35  * An abstract class for service providers that
  36  * provide localized currency symbols and display names for the
  37  * {@link java.util.Currency Currency} class.
  38  * Note that currency symbols are considered names when determining
  39  * behaviors described in the
  40  * {@link java.util.spi.LocaleServiceProvider LocaleServiceProvider}
  41  * specification.
  42  *
  43  * @since        1.6
  44  */
  45 public abstract class CurrencyNameProvider extends LocaleServiceProvider {
  46 
  47     /**
  48      * Sole constructor.  (For invocation by subclass constructors, typically
  49      * implicit.)
  50      */
  51     protected CurrencyNameProvider() {
  52     }


  93      *     <code>locale</code> is <code>null</code>
  94      * @since 1.7
  95      */
  96     public String getDisplayName(String currencyCode, Locale locale) {
  97         if (currencyCode == null || locale == null) {
  98             throw new NullPointerException();
  99         }
 100 
 101         // Check whether the currencyCode is valid
 102         char[] charray = currencyCode.toCharArray();
 103         if (charray.length != 3) {
 104             throw new IllegalArgumentException("The currencyCode is not in the form of three upper-case letters.");
 105         }
 106         for (char c : charray) {
 107             if (c < 'A' || c > 'Z') {
 108                 throw new IllegalArgumentException("The currencyCode is not in the form of three upper-case letters.");
 109             }
 110         }
 111 
 112         // Check whether the locale is valid
 113         Control c = Control.getNoFallbackControl(Control.FORMAT_DEFAULT);
 114         for (Locale l : getAvailableLocales()) {
 115             if (c.getCandidateLocales("", l).contains(locale)) {
 116                 return null;
 117             }
 118         }
 119 
 120         throw new IllegalArgumentException("The locale is not available");
 121     }
 122 }