1 /*
2  * Copyright (C) 2014 The Android Open Source Project
3  * Copyright (c) 2000, 2015, Oracle and/or its affiliates. All rights reserved.
4  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5  *
6  * This code is free software; you can redistribute it and/or modify it
7  * under the terms of the GNU General Public License version 2 only, as
8  * published by the Free Software Foundation.  Oracle designates this
9  * particular file as subject to the "Classpath" exception as provided
10  * by Oracle in the LICENSE file that accompanied this code.
11  *
12  * This code is distributed in the hope that it will be useful, but WITHOUT
13  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
15  * version 2 for more details (a copy is included in the LICENSE file that
16  * accompanied this code).
17  *
18  * You should have received a copy of the GNU General Public License version
19  * 2 along with this work; if not, write to the Free Software Foundation,
20  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
21  *
22  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
23  * or visit www.oracle.com if you need additional information or have any
24  * questions.
25  */
26 
27 package java.util;
28 
29 import java.io.Serializable;
30 import java.util.concurrent.ConcurrentHashMap;
31 import java.util.concurrent.ConcurrentMap;
32 
33 import libcore.icu.ICU;
34 
35 // BEGIN Android-changed: Removed docs about superseding runtime currency data.
36 // Doing so via a properties file is not supported on Android.
37 /**
38  * Represents a currency. Currencies are identified by their ISO 4217 currency
39  * codes. Visit the <a href="http://www.iso.org/iso/home/standards/currency_codes.htm">
40  * ISO web site</a> for more information.
41  * <p>
42  * The class is designed so that there's never more than one
43  * <code>Currency</code> instance for any given currency. Therefore, there's
44  * no public constructor. You obtain a <code>Currency</code> instance using
45  * the <code>getInstance</code> methods.
46  *
47  * @since 1.4
48  */
49 // END Android-changed: Removed docs about superseding runtime currency data.
50 public final class Currency implements Serializable {
51 
52     private static final long serialVersionUID = -158308464356906721L;
53 
54     /**
55      * ISO 4217 currency code for this currency.
56      *
57      * @serial
58      */
59     private final String currencyCode;
60 
61     // BEGIN Android-changed: Use ICU.
62     // We do not keep track of defaultFractionDigits and numericCode separately.
63     /*
64     /**
65      * Default fraction digits for this currency.
66      * Set from currency data tables.
67      *
68     transient private final int defaultFractionDigits;
69 
70     /**
71      * ISO 4217 numeric code for this currency.
72      * Set from currency data tables.
73      *
74     transient private final int numericCode;
75     */
76     private transient final android.icu.util.Currency icuCurrency;
77     // END Android-changed: Use ICU.
78 
79 
80     // class data: instance map
81 
82     private static ConcurrentMap<String, Currency> instances = new ConcurrentHashMap<>(7);
83     private static HashSet<Currency> available;
84 
85     // BEGIN Android-removed: Use ICU.
86     // We don't need any of these static fields nor the static initializer.
87     /*
88     // Class data: currency data obtained from currency.data file.
89     // Purpose:
90     // - determine valid country codes
91     // - determine valid currency codes
92     // - map country codes to currency codes
93     // - obtain default fraction digits for currency codes
94     //
95     // sc = special case; dfd = default fraction digits
96     // Simple countries are those where the country code is a prefix of the
97     // currency code, and there are no known plans to change the currency.
98     //
99     // table formats:
100     // - mainTable:
101     //   - maps country code to 32-bit int
102     //   - 26*26 entries, corresponding to [A-Z]*[A-Z]
103     //   - \u007F -> not valid country
104     //   - bits 20-31: unused
105     //   - bits 10-19: numeric code (0 to 1023)
106     //   - bit 9: 1 - special case, bits 0-4 indicate which one
107     //            0 - simple country, bits 0-4 indicate final char of currency code
108     //   - bits 5-8: fraction digits for simple countries, 0 for special cases
109     //   - bits 0-4: final char for currency code for simple country, or ID of special case
110     // - special case IDs:
111     //   - 0: country has no currency
112     //   - other: index into sc* arrays + 1
113     // - scCutOverTimes: cut-over time in millis as returned by
114     //   System.currentTimeMillis for special case countries that are changing
115     //   currencies; Long.MAX_VALUE for countries that are not changing currencies
116     // - scOldCurrencies: old currencies for special case countries
117     // - scNewCurrencies: new currencies for special case countries that are
118     //   changing currencies; null for others
119     // - scOldCurrenciesDFD: default fraction digits for old currencies
120     // - scNewCurrenciesDFD: default fraction digits for new currencies, 0 for
121     //   countries that are not changing currencies
122     // - otherCurrencies: concatenation of all currency codes that are not the
123     //   main currency of a simple country, separated by "-"
124     // - otherCurrenciesDFD: decimal format digits for currencies in otherCurrencies, same order
125 
126     static int formatVersion;
127     static int dataVersion;
128     static int[] mainTable;
129     static long[] scCutOverTimes;
130     static String[] scOldCurrencies;
131     static String[] scNewCurrencies;
132     static int[] scOldCurrenciesDFD;
133     static int[] scNewCurrenciesDFD;
134     static int[] scOldCurrenciesNumericCode;
135     static int[] scNewCurrenciesNumericCode;
136     static String otherCurrencies;
137     static int[] otherCurrenciesDFD;
138     static int[] otherCurrenciesNumericCode;
139 
140     // handy constants - must match definitions in GenerateCurrencyData
141     // magic number
142     private static final int MAGIC_NUMBER = 0x43757244;
143     // number of characters from A to Z
144     private static final int A_TO_Z = ('Z' - 'A') + 1;
145     // entry for invalid country codes
146     private static final int INVALID_COUNTRY_ENTRY = 0x0000007F;
147     // entry for countries without currency
148     private static final int COUNTRY_WITHOUT_CURRENCY_ENTRY = 0x00000200;
149     // mask for simple case country entries
150     private static final int SIMPLE_CASE_COUNTRY_MASK = 0x00000000;
151     // mask for simple case country entry final character
152     private static final int SIMPLE_CASE_COUNTRY_FINAL_CHAR_MASK = 0x0000001F;
153     // mask for simple case country entry default currency digits
154     private static final int SIMPLE_CASE_COUNTRY_DEFAULT_DIGITS_MASK = 0x000001E0;
155     // shift count for simple case country entry default currency digits
156     private static final int SIMPLE_CASE_COUNTRY_DEFAULT_DIGITS_SHIFT = 5;
157     // maximum number for simple case country entry default currency digits
158     private static final int SIMPLE_CASE_COUNTRY_MAX_DEFAULT_DIGITS = 9;
159     // mask for special case country entries
160     private static final int SPECIAL_CASE_COUNTRY_MASK = 0x00000200;
161     // mask for special case country index
162     private static final int SPECIAL_CASE_COUNTRY_INDEX_MASK = 0x0000001F;
163     // delta from entry index component in main table to index into special case tables
164     private static final int SPECIAL_CASE_COUNTRY_INDEX_DELTA = 1;
165     // mask for distinguishing simple and special case countries
166     private static final int COUNTRY_TYPE_MASK = SIMPLE_CASE_COUNTRY_MASK | SPECIAL_CASE_COUNTRY_MASK;
167     // mask for the numeric code of the currency
168     private static final int NUMERIC_CODE_MASK = 0x000FFC00;
169     // shift count for the numeric code of the currency
170     private static final int NUMERIC_CODE_SHIFT = 10;
171 
172     // Currency data format version
173     private static final int VALID_FORMAT_VERSION = 2;
174 
175     static {
176         AccessController.doPrivileged(new PrivilegedAction<Void>() {
177             @Override
178             public Void run() {
179                 String homeDir = System.getProperty("java.home");
180                 try {
181                     String dataFile = homeDir + File.separator +
182                             "lib" + File.separator + "currency.data";
183                     try (DataInputStream dis = new DataInputStream(
184                              new BufferedInputStream(
185                              new FileInputStream(dataFile)))) {
186                         if (dis.readInt() != MAGIC_NUMBER) {
187                             throw new InternalError("Currency data is possibly corrupted");
188                         }
189                         formatVersion = dis.readInt();
190                         if (formatVersion != VALID_FORMAT_VERSION) {
191                             throw new InternalError("Currency data format is incorrect");
192                         }
193                         dataVersion = dis.readInt();
194                         mainTable = readIntArray(dis, A_TO_Z * A_TO_Z);
195                         int scCount = dis.readInt();
196                         scCutOverTimes = readLongArray(dis, scCount);
197                         scOldCurrencies = readStringArray(dis, scCount);
198                         scNewCurrencies = readStringArray(dis, scCount);
199                         scOldCurrenciesDFD = readIntArray(dis, scCount);
200                         scNewCurrenciesDFD = readIntArray(dis, scCount);
201                         scOldCurrenciesNumericCode = readIntArray(dis, scCount);
202                         scNewCurrenciesNumericCode = readIntArray(dis, scCount);
203                         int ocCount = dis.readInt();
204                         otherCurrencies = dis.readUTF();
205                         otherCurrenciesDFD = readIntArray(dis, ocCount);
206                         otherCurrenciesNumericCode = readIntArray(dis, ocCount);
207                     }
208                 } catch (IOException e) {
209                     throw new InternalError(e);
210                 }
211 
212                 // look for the properties file for overrides
213                 String propsFile = System.getProperty("java.util.currency.data");
214                 if (propsFile == null) {
215                     propsFile = homeDir + File.separator + "lib" +
216                         File.separator + "currency.properties";
217                 }
218                 try {
219                     File propFile = new File(propsFile);
220                     if (propFile.exists()) {
221                         Properties props = new Properties();
222                         try (FileReader fr = new FileReader(propFile)) {
223                             props.load(fr);
224                         }
225                         Set<String> keys = props.stringPropertyNames();
226                         Pattern propertiesPattern =
227                             Pattern.compile("([A-Z]{3})\\s*,\\s*(\\d{3})\\s*,\\s*" +
228                                 "(\\d+)\\s*,?\\s*(\\d{4}-\\d{2}-\\d{2}T\\d{2}:" +
229                                 "\\d{2}:\\d{2})?");
230                         for (String key : keys) {
231                            replaceCurrencyData(propertiesPattern,
232                                key.toUpperCase(Locale.ROOT),
233                                props.getProperty(key).toUpperCase(Locale.ROOT));
234                         }
235                     }
236                 } catch (IOException e) {
237                     info("currency.properties is ignored because of an IOException", e);
238                 }
239                 return null;
240             }
241         });
242     }
243 
244     /**
245      * Constants for retrieving localized names from the name providers.
246      *
247     private static final int SYMBOL = 0;
248     private static final int DISPLAYNAME = 1;
249     */
250     // END Android-removed: Use ICU.
251 
252     /**
253      * Constructs a <code>Currency</code> instance. The constructor is private
254      * so that we can insure that there's never more than one instance for a
255      * given currency.
256      */
257     // BEGIN Android-changed: Use ICU.
258     // We do not keep track of defaultFractionDigits and numericCode separately.
259     /*
260     private Currency(String currencyCode, int defaultFractionDigits, int numericCode) {
261         this.currencyCode = currencyCode;
262         this.defaultFractionDigits = defaultFractionDigits;
263         this.numericCode = numericCode;
264     }
265     */
Currency(android.icu.util.Currency icuCurrency)266     private Currency(android.icu.util.Currency icuCurrency) {
267         this.icuCurrency = icuCurrency;
268         this.currencyCode = icuCurrency.getCurrencyCode();
269     }
270     // END Android-changed: Use ICU.
271 
272     /**
273      * Returns the <code>Currency</code> instance for the given currency code.
274      *
275      * @param currencyCode the ISO 4217 code of the currency
276      * @return the <code>Currency</code> instance for the given currency code
277      * @exception NullPointerException if <code>currencyCode</code> is null
278      * @exception IllegalArgumentException if <code>currencyCode</code> is not
279      * a supported ISO 4217 code.
280      */
getInstance(String currencyCode)281     public static Currency getInstance(String currencyCode) {
282         // BEGIN Android-changed: Use ICU.
283         // Upstream uses a private static helper method, implemented differently.
284         Currency instance = instances.get(currencyCode);
285         if (instance != null) {
286             return instance;
287         }
288         android.icu.util.Currency icuInstance =
289                   android.icu.util.Currency.getInstance(currencyCode);
290         if (icuInstance == null) {
291             return null;
292         }
293         Currency currencyVal = new Currency(icuInstance);
294         // END Android-changed: Use ICU.
295         instance = instances.putIfAbsent(currencyCode, currencyVal);
296         return (instance != null ? instance : currencyVal);
297     }
298 
299     /**
300      * Returns the <code>Currency</code> instance for the country of the
301      * given locale. The language and variant components of the locale
302      * are ignored. The result may vary over time, as countries change their
303      * currencies. For example, for the original member countries of the
304      * European Monetary Union, the method returns the old national currencies
305      * until December 31, 2001, and the Euro from January 1, 2002, local time
306      * of the respective countries.
307      * <p>
308      * The method returns <code>null</code> for territories that don't
309      * have a currency, such as Antarctica.
310      *
311      * @param locale the locale for whose country a <code>Currency</code>
312      * instance is needed
313      * @return the <code>Currency</code> instance for the country of the given
314      * locale, or {@code null}
315      * @exception NullPointerException if <code>locale</code> or its country
316      * code is {@code null}
317      * @exception IllegalArgumentException if the country of the given {@code locale}
318      * is not a supported ISO 3166 country code.
319      */
getInstance(Locale locale)320     public static Currency getInstance(Locale locale) {
321         String country = locale.getCountry();
322         if (country == null) {
323             throw new NullPointerException();
324         }
325 
326         // BEGIN Android-changed: Use ICU.
327         /*
328         if (country.length() != 2) {
329             throw new IllegalArgumentException();
330         }
331 
332         char char1 = country.charAt(0);
333         char char2 = country.charAt(1);
334         int tableEntry = getMainTableEntry(char1, char2);
335         if ((tableEntry & COUNTRY_TYPE_MASK) == SIMPLE_CASE_COUNTRY_MASK
336                     && tableEntry != INVALID_COUNTRY_ENTRY) {
337             char finalChar = (char) ((tableEntry & SIMPLE_CASE_COUNTRY_FINAL_CHAR_MASK) + 'A');
338             int defaultFractionDigits = (tableEntry & SIMPLE_CASE_COUNTRY_DEFAULT_DIGITS_MASK) >> SIMPLE_CASE_COUNTRY_DEFAULT_DIGITS_SHIFT;
339             int numericCode = (tableEntry & NUMERIC_CODE_MASK) >> NUMERIC_CODE_SHIFT;
340             StringBuilder sb = new StringBuilder(country);
341             sb.append(finalChar);
342             return getInstance(sb.toString(), defaultFractionDigits, numericCode);
343         } else {
344             // special cases
345             if (tableEntry == INVALID_COUNTRY_ENTRY) {
346                 throw new IllegalArgumentException();
347             }
348             if (tableEntry == COUNTRY_WITHOUT_CURRENCY_ENTRY) {
349                 return null;
350             } else {
351                 int index = (tableEntry & SPECIAL_CASE_COUNTRY_INDEX_MASK) - SPECIAL_CASE_COUNTRY_INDEX_DELTA;
352                 if (scCutOverTimes[index] == Long.MAX_VALUE || System.currentTimeMillis() < scCutOverTimes[index]) {
353                     return getInstance(scOldCurrencies[index], scOldCurrenciesDFD[index],
354                         scOldCurrenciesNumericCode[index]);
355                 } else {
356                     return getInstance(scNewCurrencies[index], scNewCurrenciesDFD[index],
357                         scNewCurrenciesNumericCode[index]);
358                 }
359             }
360         }
361         */
362         android.icu.util.Currency icuInstance =
363                 android.icu.util.Currency.getInstance(locale);
364         // Unknown historical reason to append variant to country code. The API documentation
365         // does not mention the effect of locale variant. The actual effect here is throwing
366         // IllegalArgumentException because the code like FR_EURO is not a valid country code.
367         String variant = locale.getVariant();
368         if (!variant.isEmpty() && (variant.equals("EURO") || variant.equals("HK") ||
369                 variant.equals("PREEURO"))) {
370             country = country + "_" + variant;
371         }
372         if (!ICU.isIsoCountry(country)) {
373             // Throws IllegalArgumentException as required by the API documentation.
374             throw new IllegalArgumentException("Unsupported ISO 3166 country: " + locale);
375         }
376         String currencyCode = ICU.getCurrencyCode(country);
377         if (currencyCode == null || icuInstance == null ||
378                 icuInstance.getCurrencyCode().equals("XXX")) { // XXX is not a real currency.
379             return null;
380         }
381         return getInstance(currencyCode);
382         // END Android-changed: Use ICU.
383     }
384 
385     /**
386      * Gets the set of available currencies.  The returned set of currencies
387      * contains all of the available currencies, which may include currencies
388      * that represent obsolete ISO 4217 codes.  The set can be modified
389      * without affecting the available currencies in the runtime.
390      *
391      * @return the set of available currencies.  If there is no currency
392      *    available in the runtime, the returned set is empty.
393      * @since 1.7
394      */
getAvailableCurrencies()395     public static Set<Currency> getAvailableCurrencies() {
396         synchronized(Currency.class) {
397             if (available == null) {
398                 // BEGIN Android-changed: Use ICU.
399                 /*
400                 available = new HashSet<>(256);
401 
402                 // Add simple currencies first
403                 for (char c1 = 'A'; c1 <= 'Z'; c1 ++) {
404                     for (char c2 = 'A'; c2 <= 'Z'; c2 ++) {
405                         int tableEntry = getMainTableEntry(c1, c2);
406                         if ((tableEntry & COUNTRY_TYPE_MASK) == SIMPLE_CASE_COUNTRY_MASK
407                              && tableEntry != INVALID_COUNTRY_ENTRY) {
408                             char finalChar = (char) ((tableEntry & SIMPLE_CASE_COUNTRY_FINAL_CHAR_MASK) + 'A');
409                             int defaultFractionDigits = (tableEntry & SIMPLE_CASE_COUNTRY_DEFAULT_DIGITS_MASK) >> SIMPLE_CASE_COUNTRY_DEFAULT_DIGITS_SHIFT;
410                             int numericCode = (tableEntry & NUMERIC_CODE_MASK) >> NUMERIC_CODE_SHIFT;
411                             StringBuilder sb = new StringBuilder();
412                             sb.append(c1);
413                             sb.append(c2);
414                             sb.append(finalChar);
415                             available.add(getInstance(sb.toString(), defaultFractionDigits, numericCode));
416                         }
417                     }
418                 }
419 
420                 // Now add other currencies
421                 StringTokenizer st = new StringTokenizer(otherCurrencies, "-");
422                 while (st.hasMoreElements()) {
423                     available.add(getInstance((String)st.nextElement()));
424                 }
425                 */
426                 available = new HashSet<>();
427                 Set<android.icu.util.Currency> icuAvailableCurrencies
428                         = android.icu.util.Currency.getAvailableCurrencies();
429                 for (android.icu.util.Currency icuCurrency : icuAvailableCurrencies) {
430                     Currency currency = getInstance(icuCurrency.getCurrencyCode());
431                     if (currency == null) {
432                         currency = new Currency(icuCurrency);
433                         instances.put(currency.currencyCode, currency);
434                     }
435                     available.add(currency);
436                 }
437                 // END Android-changed: Use ICU.
438             }
439         }
440 
441         @SuppressWarnings("unchecked")
442         Set<Currency> result = (Set<Currency>) available.clone();
443         return result;
444     }
445 
446     /**
447      * Gets the ISO 4217 currency code of this currency.
448      *
449      * @return the ISO 4217 currency code of this currency.
450      */
getCurrencyCode()451     public String getCurrencyCode() {
452         return currencyCode;
453     }
454 
455     /**
456      * Gets the symbol of this currency for the default
457      * {@link Locale.Category#DISPLAY DISPLAY} locale.
458      * For example, for the US Dollar, the symbol is "$" if the default
459      * locale is the US, while for other locales it may be "US$". If no
460      * symbol can be determined, the ISO 4217 currency code is returned.
461      * <p>
462      * This is equivalent to calling
463      * {@link #getSymbol(Locale)
464      *     getSymbol(Locale.getDefault(Locale.Category.DISPLAY))}.
465      *
466      * @return the symbol of this currency for the default
467      *     {@link Locale.Category#DISPLAY DISPLAY} locale
468      */
getSymbol()469     public String getSymbol() {
470         return getSymbol(Locale.getDefault(Locale.Category.DISPLAY));
471     }
472 
473     /**
474      * Gets the symbol of this currency for the specified locale.
475      * For example, for the US Dollar, the symbol is "$" if the specified
476      * locale is the US, while for other locales it may be "US$". If no
477      * symbol can be determined, the ISO 4217 currency code is returned.
478      *
479      * @param locale the locale for which a display name for this currency is
480      * needed
481      * @return the symbol of this currency for the specified locale
482      * @exception NullPointerException if <code>locale</code> is null
483      */
getSymbol(Locale locale)484     public String getSymbol(Locale locale) {
485         // BEGIN Android-changed: Use ICU.
486         /*
487         LocaleServiceProviderPool pool =
488             LocaleServiceProviderPool.getPool(CurrencyNameProvider.class);
489         String symbol = pool.getLocalizedObject(
490                                 CurrencyNameGetter.INSTANCE,
491                                 locale, currencyCode, SYMBOL);
492         if (symbol != null) {
493             return symbol;
494         }
495 
496         // use currency code as symbol of last resort
497         return currencyCode;
498         */
499         if (locale == null) {
500             throw new NullPointerException("locale == null");
501         }
502         return icuCurrency.getSymbol(locale);
503         // END Android-changed: Use ICU.
504     }
505 
506     /**
507      * Gets the default number of fraction digits used with this currency.
508      * For example, the default number of fraction digits for the Euro is 2,
509      * while for the Japanese Yen it's 0.
510      * In the case of pseudo-currencies, such as IMF Special Drawing Rights,
511      * -1 is returned.
512      *
513      * @return the default number of fraction digits used with this currency
514      */
getDefaultFractionDigits()515     public int getDefaultFractionDigits() {
516         // BEGIN Android-changed: Use ICU.
517         // return defaultFractionDigits;
518         if (icuCurrency.getCurrencyCode().equals("XXX")) {
519             return -1;
520         }
521         return icuCurrency.getDefaultFractionDigits();
522         // END Android-changed: Use ICU.
523     }
524 
525     /**
526      * Returns the ISO 4217 numeric code of this currency.
527      *
528      * @return the ISO 4217 numeric code of this currency
529      * @since 1.7
530      */
getNumericCode()531     public int getNumericCode() {
532         // Android-changed: Use ICU.
533         // return numericCode;
534         return icuCurrency.getNumericCode();
535     }
536 
537     /**
538      * Gets the name that is suitable for displaying this currency for
539      * the default {@link Locale.Category#DISPLAY DISPLAY} locale.
540      * If there is no suitable display name found
541      * for the default locale, the ISO 4217 currency code is returned.
542      * <p>
543      * This is equivalent to calling
544      * {@link #getDisplayName(Locale)
545      *     getDisplayName(Locale.getDefault(Locale.Category.DISPLAY))}.
546      *
547      * @return the display name of this currency for the default
548      *     {@link Locale.Category#DISPLAY DISPLAY} locale
549      * @since 1.7
550      */
getDisplayName()551     public String getDisplayName() {
552         return getDisplayName(Locale.getDefault(Locale.Category.DISPLAY));
553     }
554 
555     /**
556      * Gets the name that is suitable for displaying this currency for
557      * the specified locale.  If there is no suitable display name found
558      * for the specified locale, the ISO 4217 currency code is returned.
559      *
560      * @param locale the locale for which a display name for this currency is
561      * needed
562      * @return the display name of this currency for the specified locale
563      * @exception NullPointerException if <code>locale</code> is null
564      * @since 1.7
565      */
getDisplayName(Locale locale)566     public String getDisplayName(Locale locale) {
567         // Android-changed: Use ICU.
568         /*
569         LocaleServiceProviderPool pool =
570             LocaleServiceProviderPool.getPool(CurrencyNameProvider.class);
571         String result = pool.getLocalizedObject(
572                                 CurrencyNameGetter.INSTANCE,
573                                 locale, currencyCode, DISPLAYNAME);
574         if (result != null) {
575             return result;
576         }
577 
578         // use currency code as symbol of last resort
579         return currencyCode;
580         */
581         return icuCurrency.getDisplayName(Objects.requireNonNull(locale));
582     }
583 
584     /**
585      * Returns the ISO 4217 currency code of this currency.
586      *
587      * @return the ISO 4217 currency code of this currency
588      */
589     @Override
toString()590     public String toString() {
591         // Android-changed: Use ICU.
592         // return currencyCode;
593         return icuCurrency.toString();
594     }
595 
596     /**
597      * Resolves instances being deserialized to a single instance per currency.
598      */
readResolve()599     private Object readResolve() {
600         return getInstance(currencyCode);
601     }
602 
603     // Android-removed: Use ICU.
604     // Removed a bunch of private helper methods that are unused on Android.
605 }
606