3909N/A * Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved. 0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 0N/A * This code is free software; you can redistribute it and/or modify it 0N/A * under the terms of the GNU General Public License version 2 only, as 2362N/A * published by the Free Software Foundation. Oracle designates this 0N/A * particular file as subject to the "Classpath" exception as provided 2362N/A * by Oracle in the LICENSE file that accompanied this code. 0N/A * This code is distributed in the hope that it will be useful, but WITHOUT 0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 0N/A * version 2 for more details (a copy is included in the LICENSE file that 0N/A * accompanied this code). 0N/A * You should have received a copy of the GNU General Public License version 0N/A * 2 along with this work; if not, write to the Free Software Foundation, 0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 2362N/A * or visit www.oracle.com if you need additional information or have any 0N/A * Represents a currency. Currencies are identified by their ISO 4217 currency 0N/A * ISO web site</a> for more information, including a table of 0N/A * The class is designed so that there's never more than one 0N/A * <code>Currency</code> instance for any given currency. Therefore, there's 0N/A * no public constructor. You obtain a <code>Currency</code> instance using 0N/A * the <code>getInstance</code> methods. 0N/A * Users can supersede the Java runtime currency data by creating a properties 0N/A * of the properties file are key/value pairs of the ISO 3166 country codes 0N/A * and the ISO 4217 currency data respectively. The value part consists of 0N/A * three ISO 4217 values of a currency, i.e., an alphabetic code, a numeric 0N/A * code, and a minor unit. Those three ISO 4217 values are separated by commas. 0N/A * The lines which start with '#'s are considered comment lines. For example, 0N/A * #Sample currency properties<br> 0N/A * will supersede the currency data for Japan. 0N/A * ISO 4217 currency code for this currency. 0N/A * Default fraction digits for this currency. 0N/A * Set from currency data tables. 0N/A * ISO 4217 numeric code for this currency. 0N/A * Set from currency data tables. 0N/A // class data: instance map 0N/A // Class data: currency data obtained from currency.data file. 0N/A // - determine valid country codes 0N/A // - determine valid currency codes 0N/A // - map country codes to currency codes 0N/A // - obtain default fraction digits for currency codes 0N/A // sc = special case; dfd = default fraction digits 0N/A // Simple countries are those where the country code is a prefix of the 0N/A // currency code, and there are no known plans to change the currency. 0N/A // - maps country code to 32-bit int 0N/A // - 26*26 entries, corresponding to [A-Z]*[A-Z] 0N/A // - \u007F -> not valid country 0N/A // - bits 18-31: unused 0N/A // - bits 8-17: numeric code (0 to 1023) 0N/A // - bit 7: 1 - special case, bits 0-4 indicate which one 0N/A // 0 - simple country, bits 0-4 indicate final char of currency code 0N/A // - bits 5-6: fraction digits for simple countries, 0 for special cases 0N/A // - bits 0-4: final char for currency code for simple country, or ID of special case 0N/A // - special case IDs: 0N/A // - 0: country has no currency 0N/A // - other: index into sc* arrays + 1 0N/A // - scCutOverTimes: cut-over time in millis as returned by 0N/A // System.currentTimeMillis for special case countries that are changing 0N/A // currencies; Long.MAX_VALUE for countries that are not changing currencies 0N/A // - scOldCurrencies: old currencies for special case countries 0N/A // - scNewCurrencies: new currencies for special case countries that are 0N/A // changing currencies; null for others 0N/A // - scOldCurrenciesDFD: default fraction digits for old currencies 0N/A // - scNewCurrenciesDFD: default fraction digits for new currencies, 0 for 0N/A // countries that are not changing currencies 0N/A // - otherCurrencies: concatenation of all currency codes that are not the 0N/A // main currency of a simple country, separated by "-" 0N/A // - otherCurrenciesDFD: decimal format digits for currencies in otherCurrencies, same order 0N/A // handy constants - must match definitions in GenerateCurrencyData 0N/A // number of characters from A to Z 0N/A private static final int A_TO_Z = (
'Z' -
'A') +
1;
0N/A // entry for invalid country codes 0N/A // entry for countries without currency 0N/A // mask for simple case country entries 0N/A // mask for simple case country entry final character 0N/A // mask for simple case country entry default currency digits 0N/A // shift count for simple case country entry default currency digits 0N/A // mask for special case country entries 0N/A // mask for special case country index 0N/A // delta from entry index component in main table to index into special case tables 0N/A // mask for distinguishing simple and special case countries 0N/A // mask for the numeric code of the currency 0N/A // shift count for the numeric code of the currency 0N/A // Currency data format version 0N/A // look for the properties file for overrides 0N/A * Constants for retrieving localized names from the name providers. 0N/A * Constructs a <code>Currency</code> instance. The constructor is private 0N/A * so that we can insure that there's never more than one instance for a 0N/A * Returns the <code>Currency</code> instance for the given currency code. 0N/A * @param currencyCode the ISO 4217 code of the currency 0N/A * @return the <code>Currency</code> instance for the given currency code 0N/A * @exception NullPointerException if <code>currencyCode</code> is null 0N/A * @exception IllegalArgumentException if <code>currencyCode</code> is not 0N/A * a supported ISO 4217 code. 0N/A // Try to look up the currency code in the instances table. 0N/A // This does the null pointer check as a side effect. 0N/A // Also, if there already is an entry, the currencyCode must be valid. 0N/A // Currency code not internally generated, need to verify first 0N/A // A currency code must have 3 characters and exist in the main table 0N/A // or in the list of other currencies. 0N/A // Check for '-' separately so we don't get false hits in the table. 0N/A * Returns the <code>Currency</code> instance for the country of the 0N/A * given locale. The language and variant components of the locale 0N/A * are ignored. The result may vary over time, as countries change their 0N/A * currencies. For example, for the original member countries of the 0N/A * European Monetary Union, the method returns the old national currencies 0N/A * until December 31, 2001, and the Euro from January 1, 2002, local time 0N/A * of the respective countries. 0N/A * The method returns <code>null</code> for territories that don't 0N/A * have a currency, such as Antarctica. 0N/A * @param locale the locale for whose country a <code>Currency</code> 0N/A * instance is needed 0N/A * @return the <code>Currency</code> instance for the country of the given 0N/A * @exception NullPointerException if <code>locale</code> or its country 0N/A * @exception IllegalArgumentException if the country of the given locale 0N/A * is not a supported ISO 3166 country code. 0N/A * Gets the set of available currencies. The returned set of currencies 0N/A * contains all of the available currencies, which may include currencies 0N/A * that represent obsolete ISO 4217 codes. The set can be modified 0N/A * without affecting the available currencies in the runtime. 0N/A * @return the set of available currencies. If there is no currency 0N/A * available in the runtime, the returned set is empty. 0N/A // Add simple currencies first 0N/A // Now add other currencies 0N/A * Gets the ISO 4217 currency code of this currency. 0N/A * @return the ISO 4217 currency code of this currency. 0N/A * Gets the symbol of this currency for the default locale. 0N/A * For example, for the US Dollar, the symbol is "$" if the default 0N/A * locale is the US, while for other locales it may be "US$". If no 0N/A * symbol can be determined, the ISO 4217 currency code is returned. 0N/A * @return the symbol of this currency for the default locale 0N/A * Gets the symbol of this currency for the specified locale. 0N/A * For example, for the US Dollar, the symbol is "$" if the specified 0N/A * locale is the US, while for other locales it may be "US$". If no 0N/A * symbol can be determined, the ISO 4217 currency code is returned. 0N/A * @param locale the locale for which a display name for this currency is 0N/A * @return the symbol of this currency for the specified locale 0N/A * @exception NullPointerException if <code>locale</code> is null 0N/A // Check whether a provider can provide an implementation that's closer 0N/A // to the requested locale than what the Java runtime itself can provide. 0N/A // Assuming that all the country locales include necessary currency 0N/A // symbols in the Java runtime's resources, so there is no need to 0N/A // examine whether Java runtime's currency resource bundle is missing 0N/A // names. Therefore, no resource bundle is provided for calling this 0N/A // use currency code as symbol of last resort 0N/A * Gets the default number of fraction digits used with this currency. 0N/A * For example, the default number of fraction digits for the Euro is 2, 0N/A * while for the Japanese Yen it's 0. 0N/A * In the case of pseudo-currencies, such as IMF Special Drawing Rights, 0N/A * @return the default number of fraction digits used with this currency 0N/A * Returns the ISO 4217 numeric code of this currency. 0N/A * @return the ISO 4217 numeric code of this currency 0N/A * Gets the name that is suitable for displaying this currency for 0N/A * the default locale. If there is no suitable display name found 0N/A * for the default locale, the ISO 4217 currency code is returned. 0N/A * @return the display name of this currency for the default locale 0N/A * Gets the name that is suitable for displaying this currency for 0N/A * the specified locale. If there is no suitable display name found 0N/A * for the specified locale, the ISO 4217 currency code is returned. 0N/A * @param locale the locale for which a display name for this currency is 0N/A * @return the display name of this currency for the specified locale 0N/A * @exception NullPointerException if <code>locale</code> is null 0N/A // Check whether a provider can provide an implementation that's closer 0N/A // to the requested locale than what the Java runtime itself can provide. 0N/A // use currency code as symbol of last resort 0N/A * Returns the ISO 4217 currency code of this currency. 0N/A * @return the ISO 4217 currency code of this currency 0N/A * Resolves instances being deserialized to a single instance per currency. 0N/A * Gets the main table entry for the country whose country code consists 0N/A * of char1 and char2. 0N/A * Sets the main table entry for the country whose country code consists 0N/A * of char1 and char2. 0N/A * Obtains a localized currency names from a CurrencyNameProvider 0N/A assert false;
// shouldn't happen 0N/A * @param pattern regex pattern for the properties 0N/A * @param ctry country code 0N/A * @param data currency data. This is a comma separated string that 0N/A * consists of "three-letter alphabet code", "three-digit numeric code", 0N/A * and "one-digit (0,1,2, or 3) default fraction digit". 0N/A * For example, "JPZ,392,0". 0N/A // ignore invalid country code 0N/A // format is not recognized. ignore the data 0N/A .
append(
" is ignored because the value format is not recognized.")