src/java.base/share/classes/java/util/Currency.java
author rriggs
Wed, 27 Jun 2018 09:36:34 -0400
changeset 50817 fa1e04811ff6
parent 48929 28d8fc8cd3cd
child 53120 de9fd809bb47
permissions -rw-r--r--
8066709: Make some JDK system properties read only Reviewed-by: lancea, sundar, bchristi, weijun, mchung, alanb, mullan
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
48929
28d8fc8cd3cd 8190904: Incorrect currency instance returned by java.util.Currency.getInstance()
nishjain
parents: 48251
diff changeset
     2
 * Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3861
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3861
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3861
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3861
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3861
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
package java.util;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import java.io.BufferedInputStream;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.io.DataInputStream;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import java.io.File;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import java.io.FileReader;
27565
729f9700483a 8049367: Modular Run-Time Images
chegar
parents: 25859
diff changeset
    32
import java.io.InputStream;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import java.io.IOException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import java.io.Serializable;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
import java.security.AccessController;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
import java.security.PrivilegedAction;
13790
5b29e3921008 7180362: RFE: Implement date cutover functionality for currency.properties file
coffeys
parents: 13583
diff changeset
    37
import java.text.ParseException;
5b29e3921008 7180362: RFE: Implement date cutover functionality for currency.properties file
coffeys
parents: 13583
diff changeset
    38
import java.text.SimpleDateFormat;
12202
2a63f5718d33 7145454: JVM wide monitor lock in Currency.getInstance(String)
naoto
parents: 11138
diff changeset
    39
import java.util.concurrent.ConcurrentHashMap;
2a63f5718d33 7145454: JVM wide monitor lock in Currency.getInstance(String)
naoto
parents: 11138
diff changeset
    40
import java.util.concurrent.ConcurrentMap;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
import java.util.regex.Pattern;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
import java.util.regex.Matcher;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
import java.util.spi.CurrencyNameProvider;
48929
28d8fc8cd3cd 8190904: Incorrect currency instance returned by java.util.Currency.getInstance()
nishjain
parents: 48251
diff changeset
    44
import java.util.stream.Collectors;
50817
fa1e04811ff6 8066709: Make some JDK system properties read only
rriggs
parents: 48929
diff changeset
    45
fa1e04811ff6 8066709: Make some JDK system properties read only
rriggs
parents: 48929
diff changeset
    46
import jdk.internal.util.StaticProperty;
48251
57148c79bd75 8176841: Additional Unicode Language-Tag Extensions
naoto
parents: 47216
diff changeset
    47
import sun.util.locale.provider.CalendarDataUtility;
13583
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 12448
diff changeset
    48
import sun.util.locale.provider.LocaleServiceProviderPool;
3861
a98a057ec335 6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents: 2
diff changeset
    49
import sun.util.logging.PlatformLogger;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
 * Represents a currency. Currencies are identified by their ISO 4217 currency
17156
c42df24102c1 8011946: java.util.Currency javadoc has broken link to iso.org
dxu
parents: 16010
diff changeset
    54
 * codes. Visit the <a href="http://www.iso.org/iso/home/standards/currency_codes.htm">
c42df24102c1 8011946: java.util.Currency javadoc has broken link to iso.org
dxu
parents: 16010
diff changeset
    55
 * ISO web site</a> for more information.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
 * The class is designed so that there's never more than one
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
 * <code>Currency</code> instance for any given currency. Therefore, there's
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
 * no public constructor. You obtain a <code>Currency</code> instance using
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
 * the <code>getInstance</code> methods.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
 * <p>
14697
6ed46ffc2d33 8003846: Override mechanism for currency data should not require creating currency.properties in java.home
alanb
parents: 14014
diff changeset
    62
 * Users can supersede the Java runtime currency data by means of the system
6ed46ffc2d33 8003846: Override mechanism for currency data should not require creating currency.properties in java.home
alanb
parents: 14014
diff changeset
    63
 * property {@code java.util.currency.data}. If this system property is
6ed46ffc2d33 8003846: Override mechanism for currency data should not require creating currency.properties in java.home
alanb
parents: 14014
diff changeset
    64
 * defined then its value is the location of a properties file, the contents of
6ed46ffc2d33 8003846: Override mechanism for currency data should not require creating currency.properties in java.home
alanb
parents: 14014
diff changeset
    65
 * which are key/value pairs of the ISO 3166 country codes and the ISO 4217
6ed46ffc2d33 8003846: Override mechanism for currency data should not require creating currency.properties in java.home
alanb
parents: 14014
diff changeset
    66
 * currency data respectively.  The value part consists of three ISO 4217 values
6ed46ffc2d33 8003846: Override mechanism for currency data should not require creating currency.properties in java.home
alanb
parents: 14014
diff changeset
    67
 * of a currency, i.e., an alphabetic code, a numeric code, and a minor unit.
6ed46ffc2d33 8003846: Override mechanism for currency data should not require creating currency.properties in java.home
alanb
parents: 14014
diff changeset
    68
 * Those three ISO 4217 values are separated by commas.
13790
5b29e3921008 7180362: RFE: Implement date cutover functionality for currency.properties file
coffeys
parents: 13583
diff changeset
    69
 * The lines which start with '#'s are considered comment lines. An optional UTC
5b29e3921008 7180362: RFE: Implement date cutover functionality for currency.properties file
coffeys
parents: 13583
diff changeset
    70
 * timestamp may be specified per currency entry if users need to specify a
5b29e3921008 7180362: RFE: Implement date cutover functionality for currency.properties file
coffeys
parents: 13583
diff changeset
    71
 * cutover date indicating when the new data comes into effect. The timestamp is
5b29e3921008 7180362: RFE: Implement date cutover functionality for currency.properties file
coffeys
parents: 13583
diff changeset
    72
 * appended to the end of the currency properties and uses a comma as a separator.
5b29e3921008 7180362: RFE: Implement date cutover functionality for currency.properties file
coffeys
parents: 13583
diff changeset
    73
 * If a UTC datestamp is present and valid, the JRE will only use the new currency
5b29e3921008 7180362: RFE: Implement date cutover functionality for currency.properties file
coffeys
parents: 13583
diff changeset
    74
 * properties if the current UTC date is later than the date specified at class
5b29e3921008 7180362: RFE: Implement date cutover functionality for currency.properties file
coffeys
parents: 13583
diff changeset
    75
 * loading time. The format of the timestamp must be of ISO 8601 format :
5b29e3921008 7180362: RFE: Implement date cutover functionality for currency.properties file
coffeys
parents: 13583
diff changeset
    76
 * {@code 'yyyy-MM-dd'T'HH:mm:ss'}. For example,
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
 * <code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
 * #Sample currency properties<br>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
 * JP=JPZ,999,0
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
 * </code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
 * <p>
48929
28d8fc8cd3cd 8190904: Incorrect currency instance returned by java.util.Currency.getInstance()
nishjain
parents: 48251
diff changeset
    83
 * will supersede the currency data for Japan. If JPZ is one of the existing
28d8fc8cd3cd 8190904: Incorrect currency instance returned by java.util.Currency.getInstance()
nishjain
parents: 48251
diff changeset
    84
 * ISO 4217 currency code referred by other countries, the existing
28d8fc8cd3cd 8190904: Incorrect currency instance returned by java.util.Currency.getInstance()
nishjain
parents: 48251
diff changeset
    85
 * JPZ currency data is updated with the given numeric code and minor
28d8fc8cd3cd 8190904: Incorrect currency instance returned by java.util.Currency.getInstance()
nishjain
parents: 48251
diff changeset
    86
 * unit value.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
 *
13790
5b29e3921008 7180362: RFE: Implement date cutover functionality for currency.properties file
coffeys
parents: 13583
diff changeset
    88
 * <p>
5b29e3921008 7180362: RFE: Implement date cutover functionality for currency.properties file
coffeys
parents: 13583
diff changeset
    89
 * <code>
5b29e3921008 7180362: RFE: Implement date cutover functionality for currency.properties file
coffeys
parents: 13583
diff changeset
    90
 * #Sample currency properties with cutover date<br>
5b29e3921008 7180362: RFE: Implement date cutover functionality for currency.properties file
coffeys
parents: 13583
diff changeset
    91
 * JP=JPZ,999,0,2014-01-01T00:00:00
5b29e3921008 7180362: RFE: Implement date cutover functionality for currency.properties file
coffeys
parents: 13583
diff changeset
    92
 * </code>
5b29e3921008 7180362: RFE: Implement date cutover functionality for currency.properties file
coffeys
parents: 13583
diff changeset
    93
 * <p>
5b29e3921008 7180362: RFE: Implement date cutover functionality for currency.properties file
coffeys
parents: 13583
diff changeset
    94
 * will supersede the currency data for Japan if {@code Currency} class is loaded after
5b29e3921008 7180362: RFE: Implement date cutover functionality for currency.properties file
coffeys
parents: 13583
diff changeset
    95
 * 1st January 2014 00:00:00 GMT.
5b29e3921008 7180362: RFE: Implement date cutover functionality for currency.properties file
coffeys
parents: 13583
diff changeset
    96
 * <p>
5b29e3921008 7180362: RFE: Implement date cutover functionality for currency.properties file
coffeys
parents: 13583
diff changeset
    97
 * Where syntactically malformed entries are encountered, the entry is ignored
5b29e3921008 7180362: RFE: Implement date cutover functionality for currency.properties file
coffeys
parents: 13583
diff changeset
    98
 * and the remainder of entries in file are processed. For instances where duplicate
5b29e3921008 7180362: RFE: Implement date cutover functionality for currency.properties file
coffeys
parents: 13583
diff changeset
    99
 * country code entries exist, the behavior of the Currency information for that
5b29e3921008 7180362: RFE: Implement date cutover functionality for currency.properties file
coffeys
parents: 13583
diff changeset
   100
 * {@code Currency} is undefined and the remainder of entries in file are processed.
36113
cd5af2894aee 8074411: Describe "minor unit" and/or "default fraction digits" in Currency class' javadoc clearly
peytoia
parents: 32930
diff changeset
   101
 * <p>
48929
28d8fc8cd3cd 8190904: Incorrect currency instance returned by java.util.Currency.getInstance()
nishjain
parents: 48251
diff changeset
   102
 * If multiple property entries with same currency code but different numeric code
28d8fc8cd3cd 8190904: Incorrect currency instance returned by java.util.Currency.getInstance()
nishjain
parents: 48251
diff changeset
   103
 * and/or minor unit are encountered, those entries are ignored and the remainder
28d8fc8cd3cd 8190904: Incorrect currency instance returned by java.util.Currency.getInstance()
nishjain
parents: 48251
diff changeset
   104
 * of entries in file are processed.
28d8fc8cd3cd 8190904: Incorrect currency instance returned by java.util.Currency.getInstance()
nishjain
parents: 48251
diff changeset
   105
 *
28d8fc8cd3cd 8190904: Incorrect currency instance returned by java.util.Currency.getInstance()
nishjain
parents: 48251
diff changeset
   106
 * <p>
36113
cd5af2894aee 8074411: Describe "minor unit" and/or "default fraction digits" in Currency class' javadoc clearly
peytoia
parents: 32930
diff changeset
   107
 * It is recommended to use {@link java.math.BigDecimal} class while dealing
cd5af2894aee 8074411: Describe "minor unit" and/or "default fraction digits" in Currency class' javadoc clearly
peytoia
parents: 32930
diff changeset
   108
 * with {@code Currency} or monetary values as it provides better handling of floating
cd5af2894aee 8074411: Describe "minor unit" and/or "default fraction digits" in Currency class' javadoc clearly
peytoia
parents: 32930
diff changeset
   109
 * point numbers and their operations.
13790
5b29e3921008 7180362: RFE: Implement date cutover functionality for currency.properties file
coffeys
parents: 13583
diff changeset
   110
 *
36113
cd5af2894aee 8074411: Describe "minor unit" and/or "default fraction digits" in Currency class' javadoc clearly
peytoia
parents: 32930
diff changeset
   111
 * @see java.math.BigDecimal
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
 * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
public final class Currency implements Serializable {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
    private static final long serialVersionUID = -158308464356906721L;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
     * ISO 4217 currency code for this currency.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
     * @serial
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
    private final String currencyCode;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
     * Default fraction digits for this currency.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
     * Set from currency data tables.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
     */
32649
2ee9017c7597 8136583: Core libraries should use blessed modifier order
martin
parents: 29986
diff changeset
   129
    private final transient int defaultFractionDigits;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
     * ISO 4217 numeric code for this currency.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
     * Set from currency data tables.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
     */
32649
2ee9017c7597 8136583: Core libraries should use blessed modifier order
martin
parents: 29986
diff changeset
   135
    private final transient int numericCode;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
    // class data: instance map
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
12202
2a63f5718d33 7145454: JVM wide monitor lock in Currency.getInstance(String)
naoto
parents: 11138
diff changeset
   140
    private static ConcurrentMap<String, Currency> instances = new ConcurrentHashMap<>(7);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
    private static HashSet<Currency> available;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
    // Class data: currency data obtained from currency.data file.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
    // Purpose:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
    // - determine valid country codes
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
    // - determine valid currency codes
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
    // - map country codes to currency codes
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
    // - obtain default fraction digits for currency codes
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
    // sc = special case; dfd = default fraction digits
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
    // Simple countries are those where the country code is a prefix of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
    // currency code, and there are no known plans to change the currency.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
    // table formats:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
    // - mainTable:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
    //   - maps country code to 32-bit int
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
    //   - 26*26 entries, corresponding to [A-Z]*[A-Z]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
    //   - \u007F -> not valid country
29524
2dbceeab4b8b 8074350: Support ISO 4217 "Current funds codes" table (A.2)
naoto
parents: 27565
diff changeset
   159
    //   - bits 20-31: unused
2dbceeab4b8b 8074350: Support ISO 4217 "Current funds codes" table (A.2)
naoto
parents: 27565
diff changeset
   160
    //   - bits 10-19: numeric code (0 to 1023)
2dbceeab4b8b 8074350: Support ISO 4217 "Current funds codes" table (A.2)
naoto
parents: 27565
diff changeset
   161
    //   - bit 9: 1 - special case, bits 0-4 indicate which one
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
    //            0 - simple country, bits 0-4 indicate final char of currency code
29524
2dbceeab4b8b 8074350: Support ISO 4217 "Current funds codes" table (A.2)
naoto
parents: 27565
diff changeset
   163
    //   - bits 5-8: fraction digits for simple countries, 0 for special cases
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
    //   - bits 0-4: final char for currency code for simple country, or ID of special case
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
    // - special case IDs:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
    //   - 0: country has no currency
38440
9e77c5b81def 7102969: currency.properties supercede not working correctly
nishjain
parents: 37815
diff changeset
   167
    //   - other: index into specialCasesList
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
    static int formatVersion;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
    static int dataVersion;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
    static int[] mainTable;
38440
9e77c5b81def 7102969: currency.properties supercede not working correctly
nishjain
parents: 37815
diff changeset
   172
    static List<SpecialCaseEntry> specialCasesList;
9e77c5b81def 7102969: currency.properties supercede not working correctly
nishjain
parents: 37815
diff changeset
   173
    static List<OtherCurrencyEntry> otherCurrenciesList;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
    // handy constants - must match definitions in GenerateCurrencyData
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
    // magic number
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
    private static final int MAGIC_NUMBER = 0x43757244;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
    // number of characters from A to Z
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
    private static final int A_TO_Z = ('Z' - 'A') + 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
    // entry for invalid country codes
29524
2dbceeab4b8b 8074350: Support ISO 4217 "Current funds codes" table (A.2)
naoto
parents: 27565
diff changeset
   181
    private static final int INVALID_COUNTRY_ENTRY = 0x0000007F;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
    // entry for countries without currency
29524
2dbceeab4b8b 8074350: Support ISO 4217 "Current funds codes" table (A.2)
naoto
parents: 27565
diff changeset
   183
    private static final int COUNTRY_WITHOUT_CURRENCY_ENTRY = 0x00000200;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
    // mask for simple case country entries
29524
2dbceeab4b8b 8074350: Support ISO 4217 "Current funds codes" table (A.2)
naoto
parents: 27565
diff changeset
   185
    private static final int SIMPLE_CASE_COUNTRY_MASK = 0x00000000;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
    // mask for simple case country entry final character
29524
2dbceeab4b8b 8074350: Support ISO 4217 "Current funds codes" table (A.2)
naoto
parents: 27565
diff changeset
   187
    private static final int SIMPLE_CASE_COUNTRY_FINAL_CHAR_MASK = 0x0000001F;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
    // mask for simple case country entry default currency digits
29524
2dbceeab4b8b 8074350: Support ISO 4217 "Current funds codes" table (A.2)
naoto
parents: 27565
diff changeset
   189
    private static final int SIMPLE_CASE_COUNTRY_DEFAULT_DIGITS_MASK = 0x000001E0;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
    // shift count for simple case country entry default currency digits
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
    private static final int SIMPLE_CASE_COUNTRY_DEFAULT_DIGITS_SHIFT = 5;
29524
2dbceeab4b8b 8074350: Support ISO 4217 "Current funds codes" table (A.2)
naoto
parents: 27565
diff changeset
   192
    // maximum number for simple case country entry default currency digits
2dbceeab4b8b 8074350: Support ISO 4217 "Current funds codes" table (A.2)
naoto
parents: 27565
diff changeset
   193
    private static final int SIMPLE_CASE_COUNTRY_MAX_DEFAULT_DIGITS = 9;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
    // mask for special case country entries
29524
2dbceeab4b8b 8074350: Support ISO 4217 "Current funds codes" table (A.2)
naoto
parents: 27565
diff changeset
   195
    private static final int SPECIAL_CASE_COUNTRY_MASK = 0x00000200;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
    // mask for special case country index
29524
2dbceeab4b8b 8074350: Support ISO 4217 "Current funds codes" table (A.2)
naoto
parents: 27565
diff changeset
   197
    private static final int SPECIAL_CASE_COUNTRY_INDEX_MASK = 0x0000001F;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
    // delta from entry index component in main table to index into special case tables
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
    private static final int SPECIAL_CASE_COUNTRY_INDEX_DELTA = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
    // mask for distinguishing simple and special case countries
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
    private static final int COUNTRY_TYPE_MASK = SIMPLE_CASE_COUNTRY_MASK | SPECIAL_CASE_COUNTRY_MASK;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
    // mask for the numeric code of the currency
29524
2dbceeab4b8b 8074350: Support ISO 4217 "Current funds codes" table (A.2)
naoto
parents: 27565
diff changeset
   203
    private static final int NUMERIC_CODE_MASK = 0x000FFC00;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
    // shift count for the numeric code of the currency
29524
2dbceeab4b8b 8074350: Support ISO 4217 "Current funds codes" table (A.2)
naoto
parents: 27565
diff changeset
   205
    private static final int NUMERIC_CODE_SHIFT = 10;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
    // Currency data format version
38440
9e77c5b81def 7102969: currency.properties supercede not working correctly
nishjain
parents: 37815
diff changeset
   208
    private static final int VALID_FORMAT_VERSION = 3;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
    static {
29986
97167d851fc4 8078467: Update core libraries to use diamond with anonymous classes
darcy
parents: 29524
diff changeset
   211
        AccessController.doPrivileged(new PrivilegedAction<>() {
13583
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 12448
diff changeset
   212
            @Override
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 12448
diff changeset
   213
            public Void run() {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
                try {
27565
729f9700483a 8049367: Modular Run-Time Images
chegar
parents: 25859
diff changeset
   215
                    try (InputStream in = getClass().getResourceAsStream("/java/util/currency.data")) {
729f9700483a 8049367: Modular Run-Time Images
chegar
parents: 25859
diff changeset
   216
                        if (in == null) {
729f9700483a 8049367: Modular Run-Time Images
chegar
parents: 25859
diff changeset
   217
                            throw new InternalError("Currency data not found");
729f9700483a 8049367: Modular Run-Time Images
chegar
parents: 25859
diff changeset
   218
                        }
729f9700483a 8049367: Modular Run-Time Images
chegar
parents: 25859
diff changeset
   219
                        DataInputStream dis = new DataInputStream(new BufferedInputStream(in));
13583
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 12448
diff changeset
   220
                        if (dis.readInt() != MAGIC_NUMBER) {
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 12448
diff changeset
   221
                            throw new InternalError("Currency data is possibly corrupted");
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 12448
diff changeset
   222
                        }
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 12448
diff changeset
   223
                        formatVersion = dis.readInt();
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 12448
diff changeset
   224
                        if (formatVersion != VALID_FORMAT_VERSION) {
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 12448
diff changeset
   225
                            throw new InternalError("Currency data format is incorrect");
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 12448
diff changeset
   226
                        }
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 12448
diff changeset
   227
                        dataVersion = dis.readInt();
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 12448
diff changeset
   228
                        mainTable = readIntArray(dis, A_TO_Z * A_TO_Z);
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 12448
diff changeset
   229
                        int scCount = dis.readInt();
38440
9e77c5b81def 7102969: currency.properties supercede not working correctly
nishjain
parents: 37815
diff changeset
   230
                        specialCasesList = readSpecialCases(dis, scCount);
13583
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 12448
diff changeset
   231
                        int ocCount = dis.readInt();
38440
9e77c5b81def 7102969: currency.properties supercede not working correctly
nishjain
parents: 37815
diff changeset
   232
                        otherCurrenciesList = readOtherCurrencies(dis, ocCount);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
                } catch (IOException e) {
10419
12c063b39232 7084245: Update usages of InternalError to use exception chaining
sherman
parents: 9035
diff changeset
   235
                    throw new InternalError(e);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
                // look for the properties file for overrides
14697
6ed46ffc2d33 8003846: Override mechanism for currency data should not require creating currency.properties in java.home
alanb
parents: 14014
diff changeset
   239
                String propsFile = System.getProperty("java.util.currency.data");
6ed46ffc2d33 8003846: Override mechanism for currency data should not require creating currency.properties in java.home
alanb
parents: 14014
diff changeset
   240
                if (propsFile == null) {
50817
fa1e04811ff6 8066709: Make some JDK system properties read only
rriggs
parents: 48929
diff changeset
   241
                    propsFile = StaticProperty.javaHome() + File.separator + "lib" +
14697
6ed46ffc2d33 8003846: Override mechanism for currency data should not require creating currency.properties in java.home
alanb
parents: 14014
diff changeset
   242
                        File.separator + "currency.properties";
6ed46ffc2d33 8003846: Override mechanism for currency data should not require creating currency.properties in java.home
alanb
parents: 14014
diff changeset
   243
                }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
                try {
14697
6ed46ffc2d33 8003846: Override mechanism for currency data should not require creating currency.properties in java.home
alanb
parents: 14014
diff changeset
   245
                    File propFile = new File(propsFile);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
                    if (propFile.exists()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
                        Properties props = new Properties();
8543
e5ec12a932da 7021209: convert lang, math, util to use try-with-resources
smarks
parents: 7668
diff changeset
   248
                        try (FileReader fr = new FileReader(propFile)) {
e5ec12a932da 7021209: convert lang, math, util to use try-with-resources
smarks
parents: 7668
diff changeset
   249
                            props.load(fr);
e5ec12a932da 7021209: convert lang, math, util to use try-with-resources
smarks
parents: 7668
diff changeset
   250
                        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
                        Pattern propertiesPattern =
48929
28d8fc8cd3cd 8190904: Incorrect currency instance returned by java.util.Currency.getInstance()
nishjain
parents: 48251
diff changeset
   252
                                Pattern.compile("([A-Z]{3})\\s*,\\s*(\\d{3})\\s*,\\s*" +
28d8fc8cd3cd 8190904: Incorrect currency instance returned by java.util.Currency.getInstance()
nishjain
parents: 48251
diff changeset
   253
                                        "(\\d+)\\s*,?\\s*(\\d{4}-\\d{2}-\\d{2}T\\d{2}:" +
28d8fc8cd3cd 8190904: Incorrect currency instance returned by java.util.Currency.getInstance()
nishjain
parents: 48251
diff changeset
   254
                                        "\\d{2}:\\d{2})?");
28d8fc8cd3cd 8190904: Incorrect currency instance returned by java.util.Currency.getInstance()
nishjain
parents: 48251
diff changeset
   255
                        List<CurrencyProperty> currencyEntries
28d8fc8cd3cd 8190904: Incorrect currency instance returned by java.util.Currency.getInstance()
nishjain
parents: 48251
diff changeset
   256
                                = getValidCurrencyData(props, propertiesPattern);
28d8fc8cd3cd 8190904: Incorrect currency instance returned by java.util.Currency.getInstance()
nishjain
parents: 48251
diff changeset
   257
                        currencyEntries.forEach(Currency::replaceCurrencyData);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
                } catch (IOException e) {
48929
28d8fc8cd3cd 8190904: Incorrect currency instance returned by java.util.Currency.getInstance()
nishjain
parents: 48251
diff changeset
   260
                    CurrencyProperty.info("currency.properties is ignored"
28d8fc8cd3cd 8190904: Incorrect currency instance returned by java.util.Currency.getInstance()
nishjain
parents: 48251
diff changeset
   261
                            + " because of an IOException", e);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
                return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
        });
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
     * Constants for retrieving localized names from the name providers.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
    private static final int SYMBOL = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
    private static final int DISPLAYNAME = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
     * Constructs a <code>Currency</code> instance. The constructor is private
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
     * so that we can insure that there's never more than one instance for a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
     * given currency.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
    private Currency(String currencyCode, int defaultFractionDigits, int numericCode) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
        this.currencyCode = currencyCode;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
        this.defaultFractionDigits = defaultFractionDigits;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
        this.numericCode = numericCode;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
     * Returns the <code>Currency</code> instance for the given currency code.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
     * @param currencyCode the ISO 4217 code of the currency
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
     * @return the <code>Currency</code> instance for the given currency code
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
     * @exception NullPointerException if <code>currencyCode</code> is null
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
     * @exception IllegalArgumentException if <code>currencyCode</code> is not
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
     * a supported ISO 4217 code.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
    public static Currency getInstance(String currencyCode) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
        return getInstance(currencyCode, Integer.MIN_VALUE, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
    private static Currency getInstance(String currencyCode, int defaultFractionDigits,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
        int numericCode) {
12297
d12a3f2860eb 7156459: Remove unnecessary get() from Currency.getInstance()
naoto
parents: 12202
diff changeset
   301
        // Try to look up the currency code in the instances table.
d12a3f2860eb 7156459: Remove unnecessary get() from Currency.getInstance()
naoto
parents: 12202
diff changeset
   302
        // This does the null pointer check as a side effect.
d12a3f2860eb 7156459: Remove unnecessary get() from Currency.getInstance()
naoto
parents: 12202
diff changeset
   303
        // Also, if there already is an entry, the currencyCode must be valid.
d12a3f2860eb 7156459: Remove unnecessary get() from Currency.getInstance()
naoto
parents: 12202
diff changeset
   304
        Currency instance = instances.get(currencyCode);
d12a3f2860eb 7156459: Remove unnecessary get() from Currency.getInstance()
naoto
parents: 12202
diff changeset
   305
        if (instance != null) {
d12a3f2860eb 7156459: Remove unnecessary get() from Currency.getInstance()
naoto
parents: 12202
diff changeset
   306
            return instance;
d12a3f2860eb 7156459: Remove unnecessary get() from Currency.getInstance()
naoto
parents: 12202
diff changeset
   307
        }
d12a3f2860eb 7156459: Remove unnecessary get() from Currency.getInstance()
naoto
parents: 12202
diff changeset
   308
d12a3f2860eb 7156459: Remove unnecessary get() from Currency.getInstance()
naoto
parents: 12202
diff changeset
   309
        if (defaultFractionDigits == Integer.MIN_VALUE) {
d12a3f2860eb 7156459: Remove unnecessary get() from Currency.getInstance()
naoto
parents: 12202
diff changeset
   310
            // Currency code not internally generated, need to verify first
d12a3f2860eb 7156459: Remove unnecessary get() from Currency.getInstance()
naoto
parents: 12202
diff changeset
   311
            // A currency code must have 3 characters and exist in the main table
d12a3f2860eb 7156459: Remove unnecessary get() from Currency.getInstance()
naoto
parents: 12202
diff changeset
   312
            // or in the list of other currencies.
38440
9e77c5b81def 7102969: currency.properties supercede not working correctly
nishjain
parents: 37815
diff changeset
   313
            boolean found = false;
12297
d12a3f2860eb 7156459: Remove unnecessary get() from Currency.getInstance()
naoto
parents: 12202
diff changeset
   314
            if (currencyCode.length() != 3) {
d12a3f2860eb 7156459: Remove unnecessary get() from Currency.getInstance()
naoto
parents: 12202
diff changeset
   315
                throw new IllegalArgumentException();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
            }
12297
d12a3f2860eb 7156459: Remove unnecessary get() from Currency.getInstance()
naoto
parents: 12202
diff changeset
   317
            char char1 = currencyCode.charAt(0);
d12a3f2860eb 7156459: Remove unnecessary get() from Currency.getInstance()
naoto
parents: 12202
diff changeset
   318
            char char2 = currencyCode.charAt(1);
d12a3f2860eb 7156459: Remove unnecessary get() from Currency.getInstance()
naoto
parents: 12202
diff changeset
   319
            int tableEntry = getMainTableEntry(char1, char2);
d12a3f2860eb 7156459: Remove unnecessary get() from Currency.getInstance()
naoto
parents: 12202
diff changeset
   320
            if ((tableEntry & COUNTRY_TYPE_MASK) == SIMPLE_CASE_COUNTRY_MASK
d12a3f2860eb 7156459: Remove unnecessary get() from Currency.getInstance()
naoto
parents: 12202
diff changeset
   321
                    && tableEntry != INVALID_COUNTRY_ENTRY
d12a3f2860eb 7156459: Remove unnecessary get() from Currency.getInstance()
naoto
parents: 12202
diff changeset
   322
                    && currencyCode.charAt(2) - 'A' == (tableEntry & SIMPLE_CASE_COUNTRY_FINAL_CHAR_MASK)) {
d12a3f2860eb 7156459: Remove unnecessary get() from Currency.getInstance()
naoto
parents: 12202
diff changeset
   323
                defaultFractionDigits = (tableEntry & SIMPLE_CASE_COUNTRY_DEFAULT_DIGITS_MASK) >> SIMPLE_CASE_COUNTRY_DEFAULT_DIGITS_SHIFT;
d12a3f2860eb 7156459: Remove unnecessary get() from Currency.getInstance()
naoto
parents: 12202
diff changeset
   324
                numericCode = (tableEntry & NUMERIC_CODE_MASK) >> NUMERIC_CODE_SHIFT;
38440
9e77c5b81def 7102969: currency.properties supercede not working correctly
nishjain
parents: 37815
diff changeset
   325
                found = true;
9e77c5b81def 7102969: currency.properties supercede not working correctly
nishjain
parents: 37815
diff changeset
   326
            } else { //special case
9e77c5b81def 7102969: currency.properties supercede not working correctly
nishjain
parents: 37815
diff changeset
   327
                int[] fractionAndNumericCode = SpecialCaseEntry.findEntry(currencyCode);
9e77c5b81def 7102969: currency.properties supercede not working correctly
nishjain
parents: 37815
diff changeset
   328
                if (fractionAndNumericCode != null) {
9e77c5b81def 7102969: currency.properties supercede not working correctly
nishjain
parents: 37815
diff changeset
   329
                    defaultFractionDigits = fractionAndNumericCode[0];
9e77c5b81def 7102969: currency.properties supercede not working correctly
nishjain
parents: 37815
diff changeset
   330
                    numericCode = fractionAndNumericCode[1];
9e77c5b81def 7102969: currency.properties supercede not working correctly
nishjain
parents: 37815
diff changeset
   331
                    found = true;
9e77c5b81def 7102969: currency.properties supercede not working correctly
nishjain
parents: 37815
diff changeset
   332
                }
9e77c5b81def 7102969: currency.properties supercede not working correctly
nishjain
parents: 37815
diff changeset
   333
            }
9e77c5b81def 7102969: currency.properties supercede not working correctly
nishjain
parents: 37815
diff changeset
   334
9e77c5b81def 7102969: currency.properties supercede not working correctly
nishjain
parents: 37815
diff changeset
   335
            if (!found) {
9e77c5b81def 7102969: currency.properties supercede not working correctly
nishjain
parents: 37815
diff changeset
   336
                OtherCurrencyEntry ocEntry = OtherCurrencyEntry.findEntry(currencyCode);
9e77c5b81def 7102969: currency.properties supercede not working correctly
nishjain
parents: 37815
diff changeset
   337
                if (ocEntry == null) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
                    throw new IllegalArgumentException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
                }
38440
9e77c5b81def 7102969: currency.properties supercede not working correctly
nishjain
parents: 37815
diff changeset
   340
                defaultFractionDigits = ocEntry.fraction;
9e77c5b81def 7102969: currency.properties supercede not working correctly
nishjain
parents: 37815
diff changeset
   341
                numericCode = ocEntry.numericCode;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
            }
12297
d12a3f2860eb 7156459: Remove unnecessary get() from Currency.getInstance()
naoto
parents: 12202
diff changeset
   343
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
12297
d12a3f2860eb 7156459: Remove unnecessary get() from Currency.getInstance()
naoto
parents: 12202
diff changeset
   345
        Currency currencyVal =
d12a3f2860eb 7156459: Remove unnecessary get() from Currency.getInstance()
naoto
parents: 12202
diff changeset
   346
            new Currency(currencyCode, defaultFractionDigits, numericCode);
d12a3f2860eb 7156459: Remove unnecessary get() from Currency.getInstance()
naoto
parents: 12202
diff changeset
   347
        instance = instances.putIfAbsent(currencyCode, currencyVal);
d12a3f2860eb 7156459: Remove unnecessary get() from Currency.getInstance()
naoto
parents: 12202
diff changeset
   348
        return (instance != null ? instance : currencyVal);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
     * Returns the <code>Currency</code> instance for the country of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
     * given locale. The language and variant components of the locale
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
     * are ignored. The result may vary over time, as countries change their
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
     * currencies. For example, for the original member countries of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
     * European Monetary Union, the method returns the old national currencies
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
     * until December 31, 2001, and the Euro from January 1, 2002, local time
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
     * of the respective countries.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
     * <p>
48251
57148c79bd75 8176841: Additional Unicode Language-Tag Extensions
naoto
parents: 47216
diff changeset
   360
     * If the specified {@code locale} contains "cu" and/or "rg"
57148c79bd75 8176841: Additional Unicode Language-Tag Extensions
naoto
parents: 47216
diff changeset
   361
     * <a href="./Locale.html#def_locale_extension">Unicode extensions</a>,
57148c79bd75 8176841: Additional Unicode Language-Tag Extensions
naoto
parents: 47216
diff changeset
   362
     * the instance returned from this method reflects
57148c79bd75 8176841: Additional Unicode Language-Tag Extensions
naoto
parents: 47216
diff changeset
   363
     * the values specified with those extensions. If both "cu" and "rg" are
57148c79bd75 8176841: Additional Unicode Language-Tag Extensions
naoto
parents: 47216
diff changeset
   364
     * specified, the currency from the "cu" extension supersedes the implicit one
57148c79bd75 8176841: Additional Unicode Language-Tag Extensions
naoto
parents: 47216
diff changeset
   365
     * from the "rg" extension.
57148c79bd75 8176841: Additional Unicode Language-Tag Extensions
naoto
parents: 47216
diff changeset
   366
     * <p>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
     * The method returns <code>null</code> for territories that don't
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
     * have a currency, such as Antarctica.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
     * @param locale the locale for whose country a <code>Currency</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
     * instance is needed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
     * @return the <code>Currency</code> instance for the country of the given
13583
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 12448
diff changeset
   373
     * locale, or {@code null}
32930
7616af8ec145 8075315: API doc of Currency.getInstance(Locale) method is incorrect.
naoto
parents: 32649
diff changeset
   374
     * @exception NullPointerException if <code>locale</code>
7616af8ec145 8075315: API doc of Currency.getInstance(Locale) method is incorrect.
naoto
parents: 32649
diff changeset
   375
     * is {@code null}
13583
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 12448
diff changeset
   376
     * @exception IllegalArgumentException if the country of the given {@code locale}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
     * is not a supported ISO 3166 country code.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
    public static Currency getInstance(Locale locale) {
48251
57148c79bd75 8176841: Additional Unicode Language-Tag Extensions
naoto
parents: 47216
diff changeset
   380
        // check for locale overrides
57148c79bd75 8176841: Additional Unicode Language-Tag Extensions
naoto
parents: 47216
diff changeset
   381
        String override = locale.getUnicodeLocaleType("cu");
57148c79bd75 8176841: Additional Unicode Language-Tag Extensions
naoto
parents: 47216
diff changeset
   382
        if (override != null) {
57148c79bd75 8176841: Additional Unicode Language-Tag Extensions
naoto
parents: 47216
diff changeset
   383
            try {
57148c79bd75 8176841: Additional Unicode Language-Tag Extensions
naoto
parents: 47216
diff changeset
   384
                return getInstance(override.toUpperCase(Locale.ROOT));
57148c79bd75 8176841: Additional Unicode Language-Tag Extensions
naoto
parents: 47216
diff changeset
   385
            } catch (IllegalArgumentException iae) {
57148c79bd75 8176841: Additional Unicode Language-Tag Extensions
naoto
parents: 47216
diff changeset
   386
                // override currency is invalid. Fall through.
57148c79bd75 8176841: Additional Unicode Language-Tag Extensions
naoto
parents: 47216
diff changeset
   387
            }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
48251
57148c79bd75 8176841: Additional Unicode Language-Tag Extensions
naoto
parents: 47216
diff changeset
   390
        String country = CalendarDataUtility.findRegionOverride(locale).getCountry();
57148c79bd75 8176841: Additional Unicode Language-Tag Extensions
naoto
parents: 47216
diff changeset
   391
57148c79bd75 8176841: Additional Unicode Language-Tag Extensions
naoto
parents: 47216
diff changeset
   392
        if (country == null || !country.matches("^[a-zA-Z]{2}$")) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
            throw new IllegalArgumentException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
        char char1 = country.charAt(0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
        char char2 = country.charAt(1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
        int tableEntry = getMainTableEntry(char1, char2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
        if ((tableEntry & COUNTRY_TYPE_MASK) == SIMPLE_CASE_COUNTRY_MASK
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
                    && tableEntry != INVALID_COUNTRY_ENTRY) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
            char finalChar = (char) ((tableEntry & SIMPLE_CASE_COUNTRY_FINAL_CHAR_MASK) + 'A');
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
            int defaultFractionDigits = (tableEntry & SIMPLE_CASE_COUNTRY_DEFAULT_DIGITS_MASK) >> SIMPLE_CASE_COUNTRY_DEFAULT_DIGITS_SHIFT;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
            int numericCode = (tableEntry & NUMERIC_CODE_MASK) >> NUMERIC_CODE_SHIFT;
13583
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 12448
diff changeset
   404
            StringBuilder sb = new StringBuilder(country);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
            sb.append(finalChar);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
            return getInstance(sb.toString(), defaultFractionDigits, numericCode);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
            // special cases
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
            if (tableEntry == INVALID_COUNTRY_ENTRY) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
                throw new IllegalArgumentException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
            if (tableEntry == COUNTRY_WITHOUT_CURRENCY_ENTRY) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
                return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
            } else {
38440
9e77c5b81def 7102969: currency.properties supercede not working correctly
nishjain
parents: 37815
diff changeset
   415
                int index = SpecialCaseEntry.toIndex(tableEntry);
9e77c5b81def 7102969: currency.properties supercede not working correctly
nishjain
parents: 37815
diff changeset
   416
                SpecialCaseEntry scEntry = specialCasesList.get(index);
9e77c5b81def 7102969: currency.properties supercede not working correctly
nishjain
parents: 37815
diff changeset
   417
                if (scEntry.cutOverTime == Long.MAX_VALUE
9e77c5b81def 7102969: currency.properties supercede not working correctly
nishjain
parents: 37815
diff changeset
   418
                        || System.currentTimeMillis() < scEntry.cutOverTime) {
9e77c5b81def 7102969: currency.properties supercede not working correctly
nishjain
parents: 37815
diff changeset
   419
                    return getInstance(scEntry.oldCurrency,
9e77c5b81def 7102969: currency.properties supercede not working correctly
nishjain
parents: 37815
diff changeset
   420
                            scEntry.oldCurrencyFraction,
9e77c5b81def 7102969: currency.properties supercede not working correctly
nishjain
parents: 37815
diff changeset
   421
                            scEntry.oldCurrencyNumericCode);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
                } else {
38440
9e77c5b81def 7102969: currency.properties supercede not working correctly
nishjain
parents: 37815
diff changeset
   423
                    return getInstance(scEntry.newCurrency,
9e77c5b81def 7102969: currency.properties supercede not working correctly
nishjain
parents: 37815
diff changeset
   424
                            scEntry.newCurrencyFraction,
9e77c5b81def 7102969: currency.properties supercede not working correctly
nishjain
parents: 37815
diff changeset
   425
                            scEntry.newCurrencyNumericCode);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
     * Gets the set of available currencies.  The returned set of currencies
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
     * contains all of the available currencies, which may include currencies
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
     * that represent obsolete ISO 4217 codes.  The set can be modified
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
     * without affecting the available currencies in the runtime.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
     * @return the set of available currencies.  If there is no currency
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
     *    available in the runtime, the returned set is empty.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
     * @since 1.7
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
    public static Set<Currency> getAvailableCurrencies() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
        synchronized(Currency.class) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
            if (available == null) {
12448
b95438b17098 7157893: Warnings Cleanup in java.util.*
khazra
parents: 12297
diff changeset
   444
                available = new HashSet<>(256);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
                // Add simple currencies first
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
                for (char c1 = 'A'; c1 <= 'Z'; c1 ++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
                    for (char c2 = 'A'; c2 <= 'Z'; c2 ++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
                        int tableEntry = getMainTableEntry(c1, c2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
                        if ((tableEntry & COUNTRY_TYPE_MASK) == SIMPLE_CASE_COUNTRY_MASK
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
                             && tableEntry != INVALID_COUNTRY_ENTRY) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
                            char finalChar = (char) ((tableEntry & SIMPLE_CASE_COUNTRY_FINAL_CHAR_MASK) + 'A');
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
                            int defaultFractionDigits = (tableEntry & SIMPLE_CASE_COUNTRY_DEFAULT_DIGITS_MASK) >> SIMPLE_CASE_COUNTRY_DEFAULT_DIGITS_SHIFT;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
                            int numericCode = (tableEntry & NUMERIC_CODE_MASK) >> NUMERIC_CODE_SHIFT;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
                            StringBuilder sb = new StringBuilder();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
                            sb.append(c1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
                            sb.append(c2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
                            sb.append(finalChar);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
                            available.add(getInstance(sb.toString(), defaultFractionDigits, numericCode));
38440
9e77c5b81def 7102969: currency.properties supercede not working correctly
nishjain
parents: 37815
diff changeset
   460
                        } else if ((tableEntry & COUNTRY_TYPE_MASK) == SPECIAL_CASE_COUNTRY_MASK
9e77c5b81def 7102969: currency.properties supercede not working correctly
nishjain
parents: 37815
diff changeset
   461
                                && tableEntry != INVALID_COUNTRY_ENTRY
9e77c5b81def 7102969: currency.properties supercede not working correctly
nishjain
parents: 37815
diff changeset
   462
                                && tableEntry != COUNTRY_WITHOUT_CURRENCY_ENTRY) {
9e77c5b81def 7102969: currency.properties supercede not working correctly
nishjain
parents: 37815
diff changeset
   463
                            int index = SpecialCaseEntry.toIndex(tableEntry);
9e77c5b81def 7102969: currency.properties supercede not working correctly
nishjain
parents: 37815
diff changeset
   464
                            SpecialCaseEntry scEntry = specialCasesList.get(index);
9e77c5b81def 7102969: currency.properties supercede not working correctly
nishjain
parents: 37815
diff changeset
   465
9e77c5b81def 7102969: currency.properties supercede not working correctly
nishjain
parents: 37815
diff changeset
   466
                            if (scEntry.cutOverTime == Long.MAX_VALUE
9e77c5b81def 7102969: currency.properties supercede not working correctly
nishjain
parents: 37815
diff changeset
   467
                                    || System.currentTimeMillis() < scEntry.cutOverTime) {
9e77c5b81def 7102969: currency.properties supercede not working correctly
nishjain
parents: 37815
diff changeset
   468
                                available.add(getInstance(scEntry.oldCurrency,
9e77c5b81def 7102969: currency.properties supercede not working correctly
nishjain
parents: 37815
diff changeset
   469
                                        scEntry.oldCurrencyFraction,
9e77c5b81def 7102969: currency.properties supercede not working correctly
nishjain
parents: 37815
diff changeset
   470
                                        scEntry.oldCurrencyNumericCode));
9e77c5b81def 7102969: currency.properties supercede not working correctly
nishjain
parents: 37815
diff changeset
   471
                            } else {
9e77c5b81def 7102969: currency.properties supercede not working correctly
nishjain
parents: 37815
diff changeset
   472
                                available.add(getInstance(scEntry.newCurrency,
9e77c5b81def 7102969: currency.properties supercede not working correctly
nishjain
parents: 37815
diff changeset
   473
                                        scEntry.newCurrencyFraction,
9e77c5b81def 7102969: currency.properties supercede not working correctly
nishjain
parents: 37815
diff changeset
   474
                                        scEntry.newCurrencyNumericCode));
9e77c5b81def 7102969: currency.properties supercede not working correctly
nishjain
parents: 37815
diff changeset
   475
                            }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
                // Now add other currencies
38440
9e77c5b81def 7102969: currency.properties supercede not working correctly
nishjain
parents: 37815
diff changeset
   481
                for (OtherCurrencyEntry entry : otherCurrenciesList) {
9e77c5b81def 7102969: currency.properties supercede not working correctly
nishjain
parents: 37815
diff changeset
   482
                    available.add(getInstance(entry.currencyCode));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
11138
9121a1a92512 7117469: Warning cleanup for j.u.Currency and j.u.Locale related classes
naoto
parents: 10419
diff changeset
   487
        @SuppressWarnings("unchecked")
9121a1a92512 7117469: Warning cleanup for j.u.Currency and j.u.Locale related classes
naoto
parents: 10419
diff changeset
   488
        Set<Currency> result = (Set<Currency>) available.clone();
9121a1a92512 7117469: Warning cleanup for j.u.Currency and j.u.Locale related classes
naoto
parents: 10419
diff changeset
   489
        return result;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
     * Gets the ISO 4217 currency code of this currency.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
     * @return the ISO 4217 currency code of this currency.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
    public String getCurrencyCode() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
        return currencyCode;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
    /**
16010
2727163b5df5 7092447: Clarify the default locale used in each locale sensitive operation
naoto
parents: 16006
diff changeset
   502
     * Gets the symbol of this currency for the default
2727163b5df5 7092447: Clarify the default locale used in each locale sensitive operation
naoto
parents: 16006
diff changeset
   503
     * {@link Locale.Category#DISPLAY DISPLAY} locale.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
     * For example, for the US Dollar, the symbol is "$" if the default
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
     * locale is the US, while for other locales it may be "US$". If no
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
     * symbol can be determined, the ISO 4217 currency code is returned.
16010
2727163b5df5 7092447: Clarify the default locale used in each locale sensitive operation
naoto
parents: 16006
diff changeset
   507
     * <p>
48251
57148c79bd75 8176841: Additional Unicode Language-Tag Extensions
naoto
parents: 47216
diff changeset
   508
     * If the default {@link Locale.Category#DISPLAY DISPLAY} locale
57148c79bd75 8176841: Additional Unicode Language-Tag Extensions
naoto
parents: 47216
diff changeset
   509
     * contains "rg" (region override)
57148c79bd75 8176841: Additional Unicode Language-Tag Extensions
naoto
parents: 47216
diff changeset
   510
     * <a href="./Locale.html#def_locale_extension">Unicode extension</a>,
57148c79bd75 8176841: Additional Unicode Language-Tag Extensions
naoto
parents: 47216
diff changeset
   511
     * the symbol returned from this method reflects
57148c79bd75 8176841: Additional Unicode Language-Tag Extensions
naoto
parents: 47216
diff changeset
   512
     * the value specified with that extension.
57148c79bd75 8176841: Additional Unicode Language-Tag Extensions
naoto
parents: 47216
diff changeset
   513
     * <p>
16010
2727163b5df5 7092447: Clarify the default locale used in each locale sensitive operation
naoto
parents: 16006
diff changeset
   514
     * This is equivalent to calling
2727163b5df5 7092447: Clarify the default locale used in each locale sensitive operation
naoto
parents: 16006
diff changeset
   515
     * {@link #getSymbol(Locale)
2727163b5df5 7092447: Clarify the default locale used in each locale sensitive operation
naoto
parents: 16006
diff changeset
   516
     *     getSymbol(Locale.getDefault(Locale.Category.DISPLAY))}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
     *
16010
2727163b5df5 7092447: Clarify the default locale used in each locale sensitive operation
naoto
parents: 16006
diff changeset
   518
     * @return the symbol of this currency for the default
2727163b5df5 7092447: Clarify the default locale used in each locale sensitive operation
naoto
parents: 16006
diff changeset
   519
     *     {@link Locale.Category#DISPLAY DISPLAY} locale
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
    public String getSymbol() {
6489
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
   522
        return getSymbol(Locale.getDefault(Locale.Category.DISPLAY));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
     * Gets the symbol of this currency for the specified locale.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
     * For example, for the US Dollar, the symbol is "$" if the specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
     * locale is the US, while for other locales it may be "US$". If no
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
     * symbol can be determined, the ISO 4217 currency code is returned.
48251
57148c79bd75 8176841: Additional Unicode Language-Tag Extensions
naoto
parents: 47216
diff changeset
   530
     * <p>
57148c79bd75 8176841: Additional Unicode Language-Tag Extensions
naoto
parents: 47216
diff changeset
   531
     * If the specified {@code locale} contains "rg" (region override)
57148c79bd75 8176841: Additional Unicode Language-Tag Extensions
naoto
parents: 47216
diff changeset
   532
     * <a href="./Locale.html#def_locale_extension">Unicode extension</a>,
57148c79bd75 8176841: Additional Unicode Language-Tag Extensions
naoto
parents: 47216
diff changeset
   533
     * the symbol returned from this method reflects
57148c79bd75 8176841: Additional Unicode Language-Tag Extensions
naoto
parents: 47216
diff changeset
   534
     * the value specified with that extension.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
     * @param locale the locale for which a display name for this currency is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
     * needed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
     * @return the symbol of this currency for the specified locale
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
     * @exception NullPointerException if <code>locale</code> is null
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
    public String getSymbol(Locale locale) {
13583
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 12448
diff changeset
   542
        LocaleServiceProviderPool pool =
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 12448
diff changeset
   543
            LocaleServiceProviderPool.getPool(CurrencyNameProvider.class);
48251
57148c79bd75 8176841: Additional Unicode Language-Tag Extensions
naoto
parents: 47216
diff changeset
   544
        locale = CalendarDataUtility.findRegionOverride(locale);
13583
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 12448
diff changeset
   545
        String symbol = pool.getLocalizedObject(
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 12448
diff changeset
   546
                                CurrencyNameGetter.INSTANCE,
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 12448
diff changeset
   547
                                locale, currencyCode, SYMBOL);
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 12448
diff changeset
   548
        if (symbol != null) {
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 12448
diff changeset
   549
            return symbol;
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 12448
diff changeset
   550
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   551
13583
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 12448
diff changeset
   552
        // use currency code as symbol of last resort
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 12448
diff changeset
   553
        return currencyCode;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   554
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   555
90ce3da70b43 Initial load
duke
parents:
diff changeset
   556
    /**
38440
9e77c5b81def 7102969: currency.properties supercede not working correctly
nishjain
parents: 37815
diff changeset
   557
     * Gets the default number of fraction digits used with this currency.
9e77c5b81def 7102969: currency.properties supercede not working correctly
nishjain
parents: 37815
diff changeset
   558
     * Note that the number of fraction digits is the same as ISO 4217's
9e77c5b81def 7102969: currency.properties supercede not working correctly
nishjain
parents: 37815
diff changeset
   559
     * minor unit for the currency.
9e77c5b81def 7102969: currency.properties supercede not working correctly
nishjain
parents: 37815
diff changeset
   560
     * For example, the default number of fraction digits for the Euro is 2,
9e77c5b81def 7102969: currency.properties supercede not working correctly
nishjain
parents: 37815
diff changeset
   561
     * while for the Japanese Yen it's 0.
9e77c5b81def 7102969: currency.properties supercede not working correctly
nishjain
parents: 37815
diff changeset
   562
     * In the case of pseudo-currencies, such as IMF Special Drawing Rights,
9e77c5b81def 7102969: currency.properties supercede not working correctly
nishjain
parents: 37815
diff changeset
   563
     * -1 is returned.
9e77c5b81def 7102969: currency.properties supercede not working correctly
nishjain
parents: 37815
diff changeset
   564
     *
9e77c5b81def 7102969: currency.properties supercede not working correctly
nishjain
parents: 37815
diff changeset
   565
     * @return the default number of fraction digits used with this currency
36113
cd5af2894aee 8074411: Describe "minor unit" and/or "default fraction digits" in Currency class' javadoc clearly
peytoia
parents: 32930
diff changeset
   566
    */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   567
    public int getDefaultFractionDigits() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   568
        return defaultFractionDigits;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   569
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   570
90ce3da70b43 Initial load
duke
parents:
diff changeset
   571
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   572
     * Returns the ISO 4217 numeric code of this currency.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   573
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   574
     * @return the ISO 4217 numeric code of this currency
90ce3da70b43 Initial load
duke
parents:
diff changeset
   575
     * @since 1.7
90ce3da70b43 Initial load
duke
parents:
diff changeset
   576
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   577
    public int getNumericCode() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   578
        return numericCode;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   579
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   580
90ce3da70b43 Initial load
duke
parents:
diff changeset
   581
    /**
37815
0ecfe8f6500e 8154295: Currency iso code is int and hence looses the preceeding zero.
peytoia
parents: 36113
diff changeset
   582
     * Returns the 3 digit ISO 4217 numeric code of this currency as a {@code String}.
50817
fa1e04811ff6 8066709: Make some JDK system properties read only
rriggs
parents: 48929
diff changeset
   583
     * Unlike {@link #getNumericCode()}, which returns the numeric code as {@code int},
37815
0ecfe8f6500e 8154295: Currency iso code is int and hence looses the preceeding zero.
peytoia
parents: 36113
diff changeset
   584
     * this method always returns the numeric code as a 3 digit string.
0ecfe8f6500e 8154295: Currency iso code is int and hence looses the preceeding zero.
peytoia
parents: 36113
diff changeset
   585
     * e.g. a numeric value of 32 would be returned as "032",
0ecfe8f6500e 8154295: Currency iso code is int and hence looses the preceeding zero.
peytoia
parents: 36113
diff changeset
   586
     * and a numeric value of 6 would be returned as "006".
0ecfe8f6500e 8154295: Currency iso code is int and hence looses the preceeding zero.
peytoia
parents: 36113
diff changeset
   587
     *
0ecfe8f6500e 8154295: Currency iso code is int and hence looses the preceeding zero.
peytoia
parents: 36113
diff changeset
   588
     * @return the 3 digit ISO 4217 numeric code of this currency as a {@code String}
0ecfe8f6500e 8154295: Currency iso code is int and hence looses the preceeding zero.
peytoia
parents: 36113
diff changeset
   589
     * @since 9
0ecfe8f6500e 8154295: Currency iso code is int and hence looses the preceeding zero.
peytoia
parents: 36113
diff changeset
   590
     */
0ecfe8f6500e 8154295: Currency iso code is int and hence looses the preceeding zero.
peytoia
parents: 36113
diff changeset
   591
    public String getNumericCodeAsString() {
0ecfe8f6500e 8154295: Currency iso code is int and hence looses the preceeding zero.
peytoia
parents: 36113
diff changeset
   592
        /* numeric code could be returned as a 3 digit string simply by using
0ecfe8f6500e 8154295: Currency iso code is int and hence looses the preceeding zero.
peytoia
parents: 36113
diff changeset
   593
           String.format("%03d",numericCode); which uses regex to parse the format,
0ecfe8f6500e 8154295: Currency iso code is int and hence looses the preceeding zero.
peytoia
parents: 36113
diff changeset
   594
           "%03d" in this case. Parsing a regex gives an extra performance overhead,
0ecfe8f6500e 8154295: Currency iso code is int and hence looses the preceeding zero.
peytoia
parents: 36113
diff changeset
   595
           so String.format() approach is avoided in this scenario.
0ecfe8f6500e 8154295: Currency iso code is int and hence looses the preceeding zero.
peytoia
parents: 36113
diff changeset
   596
        */
0ecfe8f6500e 8154295: Currency iso code is int and hence looses the preceeding zero.
peytoia
parents: 36113
diff changeset
   597
        if (numericCode < 100) {
0ecfe8f6500e 8154295: Currency iso code is int and hence looses the preceeding zero.
peytoia
parents: 36113
diff changeset
   598
            StringBuilder sb = new StringBuilder();
0ecfe8f6500e 8154295: Currency iso code is int and hence looses the preceeding zero.
peytoia
parents: 36113
diff changeset
   599
            sb.append('0');
0ecfe8f6500e 8154295: Currency iso code is int and hence looses the preceeding zero.
peytoia
parents: 36113
diff changeset
   600
            if (numericCode < 10) {
0ecfe8f6500e 8154295: Currency iso code is int and hence looses the preceeding zero.
peytoia
parents: 36113
diff changeset
   601
                sb.append('0');
0ecfe8f6500e 8154295: Currency iso code is int and hence looses the preceeding zero.
peytoia
parents: 36113
diff changeset
   602
            }
0ecfe8f6500e 8154295: Currency iso code is int and hence looses the preceeding zero.
peytoia
parents: 36113
diff changeset
   603
            return sb.append(numericCode).toString();
0ecfe8f6500e 8154295: Currency iso code is int and hence looses the preceeding zero.
peytoia
parents: 36113
diff changeset
   604
        }
0ecfe8f6500e 8154295: Currency iso code is int and hence looses the preceeding zero.
peytoia
parents: 36113
diff changeset
   605
        return String.valueOf(numericCode);
0ecfe8f6500e 8154295: Currency iso code is int and hence looses the preceeding zero.
peytoia
parents: 36113
diff changeset
   606
    }
0ecfe8f6500e 8154295: Currency iso code is int and hence looses the preceeding zero.
peytoia
parents: 36113
diff changeset
   607
0ecfe8f6500e 8154295: Currency iso code is int and hence looses the preceeding zero.
peytoia
parents: 36113
diff changeset
   608
    /**
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   609
     * Gets the name that is suitable for displaying this currency for
16010
2727163b5df5 7092447: Clarify the default locale used in each locale sensitive operation
naoto
parents: 16006
diff changeset
   610
     * the default {@link Locale.Category#DISPLAY DISPLAY} locale.
2727163b5df5 7092447: Clarify the default locale used in each locale sensitive operation
naoto
parents: 16006
diff changeset
   611
     * If there is no suitable display name found
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   612
     * for the default locale, the ISO 4217 currency code is returned.
16010
2727163b5df5 7092447: Clarify the default locale used in each locale sensitive operation
naoto
parents: 16006
diff changeset
   613
     * <p>
2727163b5df5 7092447: Clarify the default locale used in each locale sensitive operation
naoto
parents: 16006
diff changeset
   614
     * This is equivalent to calling
2727163b5df5 7092447: Clarify the default locale used in each locale sensitive operation
naoto
parents: 16006
diff changeset
   615
     * {@link #getDisplayName(Locale)
2727163b5df5 7092447: Clarify the default locale used in each locale sensitive operation
naoto
parents: 16006
diff changeset
   616
     *     getDisplayName(Locale.getDefault(Locale.Category.DISPLAY))}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   617
     *
16010
2727163b5df5 7092447: Clarify the default locale used in each locale sensitive operation
naoto
parents: 16006
diff changeset
   618
     * @return the display name of this currency for the default
2727163b5df5 7092447: Clarify the default locale used in each locale sensitive operation
naoto
parents: 16006
diff changeset
   619
     *     {@link Locale.Category#DISPLAY DISPLAY} locale
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   620
     * @since 1.7
90ce3da70b43 Initial load
duke
parents:
diff changeset
   621
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   622
    public String getDisplayName() {
6489
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
   623
        return getDisplayName(Locale.getDefault(Locale.Category.DISPLAY));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   624
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   625
90ce3da70b43 Initial load
duke
parents:
diff changeset
   626
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   627
     * Gets the name that is suitable for displaying this currency for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   628
     * the specified locale.  If there is no suitable display name found
90ce3da70b43 Initial load
duke
parents:
diff changeset
   629
     * for the specified locale, the ISO 4217 currency code is returned.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   630
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   631
     * @param locale the locale for which a display name for this currency is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   632
     * needed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   633
     * @return the display name of this currency for the specified locale
90ce3da70b43 Initial load
duke
parents:
diff changeset
   634
     * @exception NullPointerException if <code>locale</code> is null
90ce3da70b43 Initial load
duke
parents:
diff changeset
   635
     * @since 1.7
90ce3da70b43 Initial load
duke
parents:
diff changeset
   636
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   637
    public String getDisplayName(Locale locale) {
13583
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 12448
diff changeset
   638
        LocaleServiceProviderPool pool =
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 12448
diff changeset
   639
            LocaleServiceProviderPool.getPool(CurrencyNameProvider.class);
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 12448
diff changeset
   640
        String result = pool.getLocalizedObject(
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 12448
diff changeset
   641
                                CurrencyNameGetter.INSTANCE,
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 12448
diff changeset
   642
                                locale, currencyCode, DISPLAYNAME);
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 12448
diff changeset
   643
        if (result != null) {
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 12448
diff changeset
   644
            return result;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   645
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   646
90ce3da70b43 Initial load
duke
parents:
diff changeset
   647
        // use currency code as symbol of last resort
90ce3da70b43 Initial load
duke
parents:
diff changeset
   648
        return currencyCode;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   649
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   650
90ce3da70b43 Initial load
duke
parents:
diff changeset
   651
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   652
     * Returns the ISO 4217 currency code of this currency.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   653
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   654
     * @return the ISO 4217 currency code of this currency
90ce3da70b43 Initial load
duke
parents:
diff changeset
   655
     */
13583
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 12448
diff changeset
   656
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   657
    public String toString() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   658
        return currencyCode;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   659
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   660
90ce3da70b43 Initial load
duke
parents:
diff changeset
   661
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   662
     * Resolves instances being deserialized to a single instance per currency.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   663
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   664
    private Object readResolve() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   665
        return getInstance(currencyCode);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   666
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   667
90ce3da70b43 Initial load
duke
parents:
diff changeset
   668
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   669
     * Gets the main table entry for the country whose country code consists
90ce3da70b43 Initial load
duke
parents:
diff changeset
   670
     * of char1 and char2.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   671
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   672
    private static int getMainTableEntry(char char1, char char2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   673
        if (char1 < 'A' || char1 > 'Z' || char2 < 'A' || char2 > 'Z') {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   674
            throw new IllegalArgumentException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   675
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   676
        return mainTable[(char1 - 'A') * A_TO_Z + (char2 - 'A')];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   677
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   678
90ce3da70b43 Initial load
duke
parents:
diff changeset
   679
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   680
     * Sets the main table entry for the country whose country code consists
90ce3da70b43 Initial load
duke
parents:
diff changeset
   681
     * of char1 and char2.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   682
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   683
    private static void setMainTableEntry(char char1, char char2, int entry) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   684
        if (char1 < 'A' || char1 > 'Z' || char2 < 'A' || char2 > 'Z') {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   685
            throw new IllegalArgumentException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   686
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   687
        mainTable[(char1 - 'A') * A_TO_Z + (char2 - 'A')] = entry;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   688
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   689
90ce3da70b43 Initial load
duke
parents:
diff changeset
   690
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   691
     * Obtains a localized currency names from a CurrencyNameProvider
90ce3da70b43 Initial load
duke
parents:
diff changeset
   692
     * implementation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   693
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   694
    private static class CurrencyNameGetter
90ce3da70b43 Initial load
duke
parents:
diff changeset
   695
        implements LocaleServiceProviderPool.LocalizedObjectGetter<CurrencyNameProvider,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   696
                                                                   String> {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   697
        private static final CurrencyNameGetter INSTANCE = new CurrencyNameGetter();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   698
13583
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 12448
diff changeset
   699
        @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   700
        public String getObject(CurrencyNameProvider currencyNameProvider,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   701
                                Locale locale,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   702
                                String key,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   703
                                Object... params) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   704
            assert params.length == 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   705
            int type = (Integer)params[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   706
90ce3da70b43 Initial load
duke
parents:
diff changeset
   707
            switch(type) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   708
            case SYMBOL:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   709
                return currencyNameProvider.getSymbol(key, locale);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   710
            case DISPLAYNAME:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   711
                return currencyNameProvider.getDisplayName(key, locale);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   712
            default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   713
                assert false; // shouldn't happen
90ce3da70b43 Initial load
duke
parents:
diff changeset
   714
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   715
90ce3da70b43 Initial load
duke
parents:
diff changeset
   716
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   717
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   718
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   719
90ce3da70b43 Initial load
duke
parents:
diff changeset
   720
    private static int[] readIntArray(DataInputStream dis, int count) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   721
        int[] ret = new int[count];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   722
        for (int i = 0; i < count; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   723
            ret[i] = dis.readInt();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   724
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   725
90ce3da70b43 Initial load
duke
parents:
diff changeset
   726
        return ret;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   727
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   728
38440
9e77c5b81def 7102969: currency.properties supercede not working correctly
nishjain
parents: 37815
diff changeset
   729
    private static List<SpecialCaseEntry> readSpecialCases(DataInputStream dis,
9e77c5b81def 7102969: currency.properties supercede not working correctly
nishjain
parents: 37815
diff changeset
   730
            int count)
9e77c5b81def 7102969: currency.properties supercede not working correctly
nishjain
parents: 37815
diff changeset
   731
            throws IOException {
9e77c5b81def 7102969: currency.properties supercede not working correctly
nishjain
parents: 37815
diff changeset
   732
9e77c5b81def 7102969: currency.properties supercede not working correctly
nishjain
parents: 37815
diff changeset
   733
        List<SpecialCaseEntry> list = new ArrayList<>(count);
9e77c5b81def 7102969: currency.properties supercede not working correctly
nishjain
parents: 37815
diff changeset
   734
        long cutOverTime;
9e77c5b81def 7102969: currency.properties supercede not working correctly
nishjain
parents: 37815
diff changeset
   735
        String oldCurrency;
9e77c5b81def 7102969: currency.properties supercede not working correctly
nishjain
parents: 37815
diff changeset
   736
        String newCurrency;
9e77c5b81def 7102969: currency.properties supercede not working correctly
nishjain
parents: 37815
diff changeset
   737
        int oldCurrencyFraction;
9e77c5b81def 7102969: currency.properties supercede not working correctly
nishjain
parents: 37815
diff changeset
   738
        int newCurrencyFraction;
9e77c5b81def 7102969: currency.properties supercede not working correctly
nishjain
parents: 37815
diff changeset
   739
        int oldCurrencyNumericCode;
9e77c5b81def 7102969: currency.properties supercede not working correctly
nishjain
parents: 37815
diff changeset
   740
        int newCurrencyNumericCode;
9e77c5b81def 7102969: currency.properties supercede not working correctly
nishjain
parents: 37815
diff changeset
   741
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   742
        for (int i = 0; i < count; i++) {
38440
9e77c5b81def 7102969: currency.properties supercede not working correctly
nishjain
parents: 37815
diff changeset
   743
            cutOverTime = dis.readLong();
9e77c5b81def 7102969: currency.properties supercede not working correctly
nishjain
parents: 37815
diff changeset
   744
            oldCurrency = dis.readUTF();
9e77c5b81def 7102969: currency.properties supercede not working correctly
nishjain
parents: 37815
diff changeset
   745
            newCurrency = dis.readUTF();
9e77c5b81def 7102969: currency.properties supercede not working correctly
nishjain
parents: 37815
diff changeset
   746
            oldCurrencyFraction = dis.readInt();
9e77c5b81def 7102969: currency.properties supercede not working correctly
nishjain
parents: 37815
diff changeset
   747
            newCurrencyFraction = dis.readInt();
9e77c5b81def 7102969: currency.properties supercede not working correctly
nishjain
parents: 37815
diff changeset
   748
            oldCurrencyNumericCode = dis.readInt();
9e77c5b81def 7102969: currency.properties supercede not working correctly
nishjain
parents: 37815
diff changeset
   749
            newCurrencyNumericCode = dis.readInt();
9e77c5b81def 7102969: currency.properties supercede not working correctly
nishjain
parents: 37815
diff changeset
   750
            SpecialCaseEntry sc = new SpecialCaseEntry(cutOverTime,
9e77c5b81def 7102969: currency.properties supercede not working correctly
nishjain
parents: 37815
diff changeset
   751
                    oldCurrency, newCurrency,
9e77c5b81def 7102969: currency.properties supercede not working correctly
nishjain
parents: 37815
diff changeset
   752
                    oldCurrencyFraction, newCurrencyFraction,
9e77c5b81def 7102969: currency.properties supercede not working correctly
nishjain
parents: 37815
diff changeset
   753
                    oldCurrencyNumericCode, newCurrencyNumericCode);
9e77c5b81def 7102969: currency.properties supercede not working correctly
nishjain
parents: 37815
diff changeset
   754
            list.add(sc);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   755
        }
38440
9e77c5b81def 7102969: currency.properties supercede not working correctly
nishjain
parents: 37815
diff changeset
   756
        return list;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   757
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   758
38440
9e77c5b81def 7102969: currency.properties supercede not working correctly
nishjain
parents: 37815
diff changeset
   759
    private static List<OtherCurrencyEntry> readOtherCurrencies(DataInputStream dis,
9e77c5b81def 7102969: currency.properties supercede not working correctly
nishjain
parents: 37815
diff changeset
   760
            int count)
9e77c5b81def 7102969: currency.properties supercede not working correctly
nishjain
parents: 37815
diff changeset
   761
            throws IOException {
9e77c5b81def 7102969: currency.properties supercede not working correctly
nishjain
parents: 37815
diff changeset
   762
9e77c5b81def 7102969: currency.properties supercede not working correctly
nishjain
parents: 37815
diff changeset
   763
        List<OtherCurrencyEntry> list = new ArrayList<>(count);
9e77c5b81def 7102969: currency.properties supercede not working correctly
nishjain
parents: 37815
diff changeset
   764
        String currencyCode;
9e77c5b81def 7102969: currency.properties supercede not working correctly
nishjain
parents: 37815
diff changeset
   765
        int fraction;
9e77c5b81def 7102969: currency.properties supercede not working correctly
nishjain
parents: 37815
diff changeset
   766
        int numericCode;
9e77c5b81def 7102969: currency.properties supercede not working correctly
nishjain
parents: 37815
diff changeset
   767
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   768
        for (int i = 0; i < count; i++) {
38440
9e77c5b81def 7102969: currency.properties supercede not working correctly
nishjain
parents: 37815
diff changeset
   769
            currencyCode = dis.readUTF();
9e77c5b81def 7102969: currency.properties supercede not working correctly
nishjain
parents: 37815
diff changeset
   770
            fraction = dis.readInt();
9e77c5b81def 7102969: currency.properties supercede not working correctly
nishjain
parents: 37815
diff changeset
   771
            numericCode = dis.readInt();
9e77c5b81def 7102969: currency.properties supercede not working correctly
nishjain
parents: 37815
diff changeset
   772
            OtherCurrencyEntry oc = new OtherCurrencyEntry(currencyCode,
9e77c5b81def 7102969: currency.properties supercede not working correctly
nishjain
parents: 37815
diff changeset
   773
                    fraction,
9e77c5b81def 7102969: currency.properties supercede not working correctly
nishjain
parents: 37815
diff changeset
   774
                    numericCode);
9e77c5b81def 7102969: currency.properties supercede not working correctly
nishjain
parents: 37815
diff changeset
   775
            list.add(oc);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   776
        }
38440
9e77c5b81def 7102969: currency.properties supercede not working correctly
nishjain
parents: 37815
diff changeset
   777
        return list;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   778
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   779
90ce3da70b43 Initial load
duke
parents:
diff changeset
   780
    /**
48929
28d8fc8cd3cd 8190904: Incorrect currency instance returned by java.util.Currency.getInstance()
nishjain
parents: 48251
diff changeset
   781
     * Parse currency data found in the properties file (that
28d8fc8cd3cd 8190904: Incorrect currency instance returned by java.util.Currency.getInstance()
nishjain
parents: 48251
diff changeset
   782
     * java.util.currency.data designates) to a List of CurrencyProperty
28d8fc8cd3cd 8190904: Incorrect currency instance returned by java.util.Currency.getInstance()
nishjain
parents: 48251
diff changeset
   783
     * instances. Also, remove invalid entries and the multiple currency
28d8fc8cd3cd 8190904: Incorrect currency instance returned by java.util.Currency.getInstance()
nishjain
parents: 48251
diff changeset
   784
     * code inconsistencies.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   785
     *
48929
28d8fc8cd3cd 8190904: Incorrect currency instance returned by java.util.Currency.getInstance()
nishjain
parents: 48251
diff changeset
   786
     * @param props properties containing currency data
28d8fc8cd3cd 8190904: Incorrect currency instance returned by java.util.Currency.getInstance()
nishjain
parents: 48251
diff changeset
   787
     * @param pattern regex pattern for the properties entry
28d8fc8cd3cd 8190904: Incorrect currency instance returned by java.util.Currency.getInstance()
nishjain
parents: 48251
diff changeset
   788
     * @return list of parsed property entries
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   789
     */
48929
28d8fc8cd3cd 8190904: Incorrect currency instance returned by java.util.Currency.getInstance()
nishjain
parents: 48251
diff changeset
   790
    private static List<CurrencyProperty> getValidCurrencyData(Properties props,
28d8fc8cd3cd 8190904: Incorrect currency instance returned by java.util.Currency.getInstance()
nishjain
parents: 48251
diff changeset
   791
            Pattern pattern) {
28d8fc8cd3cd 8190904: Incorrect currency instance returned by java.util.Currency.getInstance()
nishjain
parents: 48251
diff changeset
   792
28d8fc8cd3cd 8190904: Incorrect currency instance returned by java.util.Currency.getInstance()
nishjain
parents: 48251
diff changeset
   793
        Set<String> keys = props.stringPropertyNames();
28d8fc8cd3cd 8190904: Incorrect currency instance returned by java.util.Currency.getInstance()
nishjain
parents: 48251
diff changeset
   794
        List<CurrencyProperty> propertyEntries = new ArrayList<>();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   795
48929
28d8fc8cd3cd 8190904: Incorrect currency instance returned by java.util.Currency.getInstance()
nishjain
parents: 48251
diff changeset
   796
        // remove all invalid entries and parse all valid currency properties
28d8fc8cd3cd 8190904: Incorrect currency instance returned by java.util.Currency.getInstance()
nishjain
parents: 48251
diff changeset
   797
        // entries to a group of CurrencyProperty, classified by currency code
28d8fc8cd3cd 8190904: Incorrect currency instance returned by java.util.Currency.getInstance()
nishjain
parents: 48251
diff changeset
   798
        Map<String, List<CurrencyProperty>> currencyCodeGroup = keys.stream()
28d8fc8cd3cd 8190904: Incorrect currency instance returned by java.util.Currency.getInstance()
nishjain
parents: 48251
diff changeset
   799
                .map(k -> CurrencyProperty
28d8fc8cd3cd 8190904: Incorrect currency instance returned by java.util.Currency.getInstance()
nishjain
parents: 48251
diff changeset
   800
                .getValidEntry(k.toUpperCase(Locale.ROOT),
28d8fc8cd3cd 8190904: Incorrect currency instance returned by java.util.Currency.getInstance()
nishjain
parents: 48251
diff changeset
   801
                        props.getProperty(k).toUpperCase(Locale.ROOT),
28d8fc8cd3cd 8190904: Incorrect currency instance returned by java.util.Currency.getInstance()
nishjain
parents: 48251
diff changeset
   802
                        pattern)).flatMap(o -> o.stream())
28d8fc8cd3cd 8190904: Incorrect currency instance returned by java.util.Currency.getInstance()
nishjain
parents: 48251
diff changeset
   803
                .collect(Collectors.groupingBy(entry -> entry.currencyCode));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   804
48929
28d8fc8cd3cd 8190904: Incorrect currency instance returned by java.util.Currency.getInstance()
nishjain
parents: 48251
diff changeset
   805
        // check each group for inconsistencies
28d8fc8cd3cd 8190904: Incorrect currency instance returned by java.util.Currency.getInstance()
nishjain
parents: 48251
diff changeset
   806
        currencyCodeGroup.forEach((curCode, list) -> {
28d8fc8cd3cd 8190904: Incorrect currency instance returned by java.util.Currency.getInstance()
nishjain
parents: 48251
diff changeset
   807
            boolean inconsistent = CurrencyProperty
28d8fc8cd3cd 8190904: Incorrect currency instance returned by java.util.Currency.getInstance()
nishjain
parents: 48251
diff changeset
   808
                    .containsInconsistentInstances(list);
28d8fc8cd3cd 8190904: Incorrect currency instance returned by java.util.Currency.getInstance()
nishjain
parents: 48251
diff changeset
   809
            if (inconsistent) {
28d8fc8cd3cd 8190904: Incorrect currency instance returned by java.util.Currency.getInstance()
nishjain
parents: 48251
diff changeset
   810
                list.forEach(prop -> CurrencyProperty.info("The property"
28d8fc8cd3cd 8190904: Incorrect currency instance returned by java.util.Currency.getInstance()
nishjain
parents: 48251
diff changeset
   811
                        + " entry for " + prop.country + " is inconsistent."
28d8fc8cd3cd 8190904: Incorrect currency instance returned by java.util.Currency.getInstance()
nishjain
parents: 48251
diff changeset
   812
                        + " Ignored.", null));
28d8fc8cd3cd 8190904: Incorrect currency instance returned by java.util.Currency.getInstance()
nishjain
parents: 48251
diff changeset
   813
            } else {
28d8fc8cd3cd 8190904: Incorrect currency instance returned by java.util.Currency.getInstance()
nishjain
parents: 48251
diff changeset
   814
                propertyEntries.addAll(list);
13790
5b29e3921008 7180362: RFE: Implement date cutover functionality for currency.properties file
coffeys
parents: 13583
diff changeset
   815
            }
48929
28d8fc8cd3cd 8190904: Incorrect currency instance returned by java.util.Currency.getInstance()
nishjain
parents: 48251
diff changeset
   816
        });
28d8fc8cd3cd 8190904: Incorrect currency instance returned by java.util.Currency.getInstance()
nishjain
parents: 48251
diff changeset
   817
28d8fc8cd3cd 8190904: Incorrect currency instance returned by java.util.Currency.getInstance()
nishjain
parents: 48251
diff changeset
   818
        return propertyEntries;
28d8fc8cd3cd 8190904: Incorrect currency instance returned by java.util.Currency.getInstance()
nishjain
parents: 48251
diff changeset
   819
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   820
48929
28d8fc8cd3cd 8190904: Incorrect currency instance returned by java.util.Currency.getInstance()
nishjain
parents: 48251
diff changeset
   821
    /**
28d8fc8cd3cd 8190904: Incorrect currency instance returned by java.util.Currency.getInstance()
nishjain
parents: 48251
diff changeset
   822
     * Replaces currency data found in the properties file that
28d8fc8cd3cd 8190904: Incorrect currency instance returned by java.util.Currency.getInstance()
nishjain
parents: 48251
diff changeset
   823
     * java.util.currency.data designates. This method is invoked for
28d8fc8cd3cd 8190904: Incorrect currency instance returned by java.util.Currency.getInstance()
nishjain
parents: 48251
diff changeset
   824
     * each valid currency entry.
28d8fc8cd3cd 8190904: Incorrect currency instance returned by java.util.Currency.getInstance()
nishjain
parents: 48251
diff changeset
   825
     *
28d8fc8cd3cd 8190904: Incorrect currency instance returned by java.util.Currency.getInstance()
nishjain
parents: 48251
diff changeset
   826
     * @param prop CurrencyProperty instance of the valid property entry
28d8fc8cd3cd 8190904: Incorrect currency instance returned by java.util.Currency.getInstance()
nishjain
parents: 48251
diff changeset
   827
     */
28d8fc8cd3cd 8190904: Incorrect currency instance returned by java.util.Currency.getInstance()
nishjain
parents: 48251
diff changeset
   828
    private static void replaceCurrencyData(CurrencyProperty prop) {
28d8fc8cd3cd 8190904: Incorrect currency instance returned by java.util.Currency.getInstance()
nishjain
parents: 48251
diff changeset
   829
28d8fc8cd3cd 8190904: Incorrect currency instance returned by java.util.Currency.getInstance()
nishjain
parents: 48251
diff changeset
   830
28d8fc8cd3cd 8190904: Incorrect currency instance returned by java.util.Currency.getInstance()
nishjain
parents: 48251
diff changeset
   831
        String ctry = prop.country;
28d8fc8cd3cd 8190904: Incorrect currency instance returned by java.util.Currency.getInstance()
nishjain
parents: 48251
diff changeset
   832
        String code = prop.currencyCode;
28d8fc8cd3cd 8190904: Incorrect currency instance returned by java.util.Currency.getInstance()
nishjain
parents: 48251
diff changeset
   833
        int numeric = prop.numericCode;
28d8fc8cd3cd 8190904: Incorrect currency instance returned by java.util.Currency.getInstance()
nishjain
parents: 48251
diff changeset
   834
        int fraction = prop.fraction;
29524
2dbceeab4b8b 8074350: Support ISO 4217 "Current funds codes" table (A.2)
naoto
parents: 27565
diff changeset
   835
        int entry = numeric << NUMERIC_CODE_SHIFT;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   836
38440
9e77c5b81def 7102969: currency.properties supercede not working correctly
nishjain
parents: 37815
diff changeset
   837
        int index = SpecialCaseEntry.indexOf(code, fraction, numeric);
9e77c5b81def 7102969: currency.properties supercede not working correctly
nishjain
parents: 37815
diff changeset
   838
48929
28d8fc8cd3cd 8190904: Incorrect currency instance returned by java.util.Currency.getInstance()
nishjain
parents: 48251
diff changeset
   839
28d8fc8cd3cd 8190904: Incorrect currency instance returned by java.util.Currency.getInstance()
nishjain
parents: 48251
diff changeset
   840
        // If a new entry changes the numeric code/dfd of an existing
28d8fc8cd3cd 8190904: Incorrect currency instance returned by java.util.Currency.getInstance()
nishjain
parents: 48251
diff changeset
   841
        // currency code, update it in the sc list at the respective
28d8fc8cd3cd 8190904: Incorrect currency instance returned by java.util.Currency.getInstance()
nishjain
parents: 48251
diff changeset
   842
        // index and also change it in the other currencies list and
28d8fc8cd3cd 8190904: Incorrect currency instance returned by java.util.Currency.getInstance()
nishjain
parents: 48251
diff changeset
   843
        // main table (if that currency code is also used as a
28d8fc8cd3cd 8190904: Incorrect currency instance returned by java.util.Currency.getInstance()
nishjain
parents: 48251
diff changeset
   844
        // simple case).
28d8fc8cd3cd 8190904: Incorrect currency instance returned by java.util.Currency.getInstance()
nishjain
parents: 48251
diff changeset
   845
28d8fc8cd3cd 8190904: Incorrect currency instance returned by java.util.Currency.getInstance()
nishjain
parents: 48251
diff changeset
   846
        // If all three components do not match with the new entry,
28d8fc8cd3cd 8190904: Incorrect currency instance returned by java.util.Currency.getInstance()
nishjain
parents: 48251
diff changeset
   847
        // but the currency code exists in the special case list
28d8fc8cd3cd 8190904: Incorrect currency instance returned by java.util.Currency.getInstance()
nishjain
parents: 48251
diff changeset
   848
        // update the sc entry with the new entry
28d8fc8cd3cd 8190904: Incorrect currency instance returned by java.util.Currency.getInstance()
nishjain
parents: 48251
diff changeset
   849
        int scCurrencyCodeIndex = -1;
28d8fc8cd3cd 8190904: Incorrect currency instance returned by java.util.Currency.getInstance()
nishjain
parents: 48251
diff changeset
   850
        if (index == -1) {
28d8fc8cd3cd 8190904: Incorrect currency instance returned by java.util.Currency.getInstance()
nishjain
parents: 48251
diff changeset
   851
            scCurrencyCodeIndex = SpecialCaseEntry.currencyCodeIndex(code);
28d8fc8cd3cd 8190904: Incorrect currency instance returned by java.util.Currency.getInstance()
nishjain
parents: 48251
diff changeset
   852
            if (scCurrencyCodeIndex != -1) {
28d8fc8cd3cd 8190904: Incorrect currency instance returned by java.util.Currency.getInstance()
nishjain
parents: 48251
diff changeset
   853
                //currency code exists in sc list, then update the old entry
28d8fc8cd3cd 8190904: Incorrect currency instance returned by java.util.Currency.getInstance()
nishjain
parents: 48251
diff changeset
   854
                specialCasesList.set(scCurrencyCodeIndex,
28d8fc8cd3cd 8190904: Incorrect currency instance returned by java.util.Currency.getInstance()
nishjain
parents: 48251
diff changeset
   855
                        new SpecialCaseEntry(code, fraction, numeric));
28d8fc8cd3cd 8190904: Incorrect currency instance returned by java.util.Currency.getInstance()
nishjain
parents: 48251
diff changeset
   856
28d8fc8cd3cd 8190904: Incorrect currency instance returned by java.util.Currency.getInstance()
nishjain
parents: 48251
diff changeset
   857
                // also update the entry in other currencies list
28d8fc8cd3cd 8190904: Incorrect currency instance returned by java.util.Currency.getInstance()
nishjain
parents: 48251
diff changeset
   858
                OtherCurrencyEntry oe = OtherCurrencyEntry.findEntry(code);
28d8fc8cd3cd 8190904: Incorrect currency instance returned by java.util.Currency.getInstance()
nishjain
parents: 48251
diff changeset
   859
                if (oe != null) {
28d8fc8cd3cd 8190904: Incorrect currency instance returned by java.util.Currency.getInstance()
nishjain
parents: 48251
diff changeset
   860
                    int oIndex = otherCurrenciesList.indexOf(oe);
28d8fc8cd3cd 8190904: Incorrect currency instance returned by java.util.Currency.getInstance()
nishjain
parents: 48251
diff changeset
   861
                    otherCurrenciesList.set(oIndex, new OtherCurrencyEntry(
28d8fc8cd3cd 8190904: Incorrect currency instance returned by java.util.Currency.getInstance()
nishjain
parents: 48251
diff changeset
   862
                            code, fraction, numeric));
28d8fc8cd3cd 8190904: Incorrect currency instance returned by java.util.Currency.getInstance()
nishjain
parents: 48251
diff changeset
   863
                }
28d8fc8cd3cd 8190904: Incorrect currency instance returned by java.util.Currency.getInstance()
nishjain
parents: 48251
diff changeset
   864
            }
28d8fc8cd3cd 8190904: Incorrect currency instance returned by java.util.Currency.getInstance()
nishjain
parents: 48251
diff changeset
   865
        }
28d8fc8cd3cd 8190904: Incorrect currency instance returned by java.util.Currency.getInstance()
nishjain
parents: 48251
diff changeset
   866
28d8fc8cd3cd 8190904: Incorrect currency instance returned by java.util.Currency.getInstance()
nishjain
parents: 48251
diff changeset
   867
        /* If a country switches from simple case to special case or
38440
9e77c5b81def 7102969: currency.properties supercede not working correctly
nishjain
parents: 37815
diff changeset
   868
         * one special case to other special case which is not present
48929
28d8fc8cd3cd 8190904: Incorrect currency instance returned by java.util.Currency.getInstance()
nishjain
parents: 48251
diff changeset
   869
         * in the sc arrays then insert the new entry in special case arrays.
28d8fc8cd3cd 8190904: Incorrect currency instance returned by java.util.Currency.getInstance()
nishjain
parents: 48251
diff changeset
   870
         * If an entry with given currency code exists, update with the new
28d8fc8cd3cd 8190904: Incorrect currency instance returned by java.util.Currency.getInstance()
nishjain
parents: 48251
diff changeset
   871
         * entry.
38440
9e77c5b81def 7102969: currency.properties supercede not working correctly
nishjain
parents: 37815
diff changeset
   872
         */
9e77c5b81def 7102969: currency.properties supercede not working correctly
nishjain
parents: 37815
diff changeset
   873
        if (index == -1 && (ctry.charAt(0) != code.charAt(0)
9e77c5b81def 7102969: currency.properties supercede not working correctly
nishjain
parents: 37815
diff changeset
   874
                || ctry.charAt(1) != code.charAt(1))) {
9e77c5b81def 7102969: currency.properties supercede not working correctly
nishjain
parents: 37815
diff changeset
   875
48929
28d8fc8cd3cd 8190904: Incorrect currency instance returned by java.util.Currency.getInstance()
nishjain
parents: 48251
diff changeset
   876
            if(scCurrencyCodeIndex == -1) {
28d8fc8cd3cd 8190904: Incorrect currency instance returned by java.util.Currency.getInstance()
nishjain
parents: 48251
diff changeset
   877
                specialCasesList.add(new SpecialCaseEntry(code, fraction,
28d8fc8cd3cd 8190904: Incorrect currency instance returned by java.util.Currency.getInstance()
nishjain
parents: 48251
diff changeset
   878
                        numeric));
28d8fc8cd3cd 8190904: Incorrect currency instance returned by java.util.Currency.getInstance()
nishjain
parents: 48251
diff changeset
   879
                index = specialCasesList.size() - 1;
28d8fc8cd3cd 8190904: Incorrect currency instance returned by java.util.Currency.getInstance()
nishjain
parents: 48251
diff changeset
   880
            } else {
28d8fc8cd3cd 8190904: Incorrect currency instance returned by java.util.Currency.getInstance()
nishjain
parents: 48251
diff changeset
   881
                index = scCurrencyCodeIndex;
28d8fc8cd3cd 8190904: Incorrect currency instance returned by java.util.Currency.getInstance()
nishjain
parents: 48251
diff changeset
   882
            }
28d8fc8cd3cd 8190904: Incorrect currency instance returned by java.util.Currency.getInstance()
nishjain
parents: 48251
diff changeset
   883
28d8fc8cd3cd 8190904: Incorrect currency instance returned by java.util.Currency.getInstance()
nishjain
parents: 48251
diff changeset
   884
            // update the entry in main table if it exists as a simple case
28d8fc8cd3cd 8190904: Incorrect currency instance returned by java.util.Currency.getInstance()
nishjain
parents: 48251
diff changeset
   885
            updateMainTableEntry(code, fraction, numeric);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   886
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   887
38440
9e77c5b81def 7102969: currency.properties supercede not working correctly
nishjain
parents: 37815
diff changeset
   888
        if (index == -1) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   889
            // simple case
38440
9e77c5b81def 7102969: currency.properties supercede not working correctly
nishjain
parents: 37815
diff changeset
   890
            entry |= (fraction << SIMPLE_CASE_COUNTRY_DEFAULT_DIGITS_SHIFT)
9e77c5b81def 7102969: currency.properties supercede not working correctly
nishjain
parents: 37815
diff changeset
   891
                    | (code.charAt(2) - 'A');
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   892
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   893
            // special case
38440
9e77c5b81def 7102969: currency.properties supercede not working correctly
nishjain
parents: 37815
diff changeset
   894
            entry = SPECIAL_CASE_COUNTRY_MASK
9e77c5b81def 7102969: currency.properties supercede not working correctly
nishjain
parents: 37815
diff changeset
   895
                    | (index + SPECIAL_CASE_COUNTRY_INDEX_DELTA);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   896
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   897
        setMainTableEntry(ctry.charAt(0), ctry.charAt(1), entry);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   898
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   899
48929
28d8fc8cd3cd 8190904: Incorrect currency instance returned by java.util.Currency.getInstance()
nishjain
parents: 48251
diff changeset
   900
    // update the entry in maintable for any simple case found, if a new
28d8fc8cd3cd 8190904: Incorrect currency instance returned by java.util.Currency.getInstance()
nishjain
parents: 48251
diff changeset
   901
    // entry as a special case updates the entry in sc list with
28d8fc8cd3cd 8190904: Incorrect currency instance returned by java.util.Currency.getInstance()
nishjain
parents: 48251
diff changeset
   902
    // existing currency code
28d8fc8cd3cd 8190904: Incorrect currency instance returned by java.util.Currency.getInstance()
nishjain
parents: 48251
diff changeset
   903
    private static void updateMainTableEntry(String code, int fraction,
28d8fc8cd3cd 8190904: Incorrect currency instance returned by java.util.Currency.getInstance()
nishjain
parents: 48251
diff changeset
   904
            int numeric) {
28d8fc8cd3cd 8190904: Incorrect currency instance returned by java.util.Currency.getInstance()
nishjain
parents: 48251
diff changeset
   905
        // checking the existence of currency code in mainTable
28d8fc8cd3cd 8190904: Incorrect currency instance returned by java.util.Currency.getInstance()
nishjain
parents: 48251
diff changeset
   906
        int tableEntry = getMainTableEntry(code.charAt(0), code.charAt(1));
28d8fc8cd3cd 8190904: Incorrect currency instance returned by java.util.Currency.getInstance()
nishjain
parents: 48251
diff changeset
   907
        int entry = numeric << NUMERIC_CODE_SHIFT;
28d8fc8cd3cd 8190904: Incorrect currency instance returned by java.util.Currency.getInstance()
nishjain
parents: 48251
diff changeset
   908
        if ((tableEntry & COUNTRY_TYPE_MASK) == SIMPLE_CASE_COUNTRY_MASK
28d8fc8cd3cd 8190904: Incorrect currency instance returned by java.util.Currency.getInstance()
nishjain
parents: 48251
diff changeset
   909
                && tableEntry != INVALID_COUNTRY_ENTRY
28d8fc8cd3cd 8190904: Incorrect currency instance returned by java.util.Currency.getInstance()
nishjain
parents: 48251
diff changeset
   910
                && code.charAt(2) - 'A' == (tableEntry
28d8fc8cd3cd 8190904: Incorrect currency instance returned by java.util.Currency.getInstance()
nishjain
parents: 48251
diff changeset
   911
                & SIMPLE_CASE_COUNTRY_FINAL_CHAR_MASK)) {
13790
5b29e3921008 7180362: RFE: Implement date cutover functionality for currency.properties file
coffeys
parents: 13583
diff changeset
   912
48929
28d8fc8cd3cd 8190904: Incorrect currency instance returned by java.util.Currency.getInstance()
nishjain
parents: 48251
diff changeset
   913
            int numericCode = (tableEntry & NUMERIC_CODE_MASK)
28d8fc8cd3cd 8190904: Incorrect currency instance returned by java.util.Currency.getInstance()
nishjain
parents: 48251
diff changeset
   914
                    >> NUMERIC_CODE_SHIFT;
28d8fc8cd3cd 8190904: Incorrect currency instance returned by java.util.Currency.getInstance()
nishjain
parents: 48251
diff changeset
   915
            int defaultFractionDigits = (tableEntry
28d8fc8cd3cd 8190904: Incorrect currency instance returned by java.util.Currency.getInstance()
nishjain
parents: 48251
diff changeset
   916
                    & SIMPLE_CASE_COUNTRY_DEFAULT_DIGITS_MASK)
28d8fc8cd3cd 8190904: Incorrect currency instance returned by java.util.Currency.getInstance()
nishjain
parents: 48251
diff changeset
   917
                    >> SIMPLE_CASE_COUNTRY_DEFAULT_DIGITS_SHIFT;
28d8fc8cd3cd 8190904: Incorrect currency instance returned by java.util.Currency.getInstance()
nishjain
parents: 48251
diff changeset
   918
            if (numeric != numericCode || fraction != defaultFractionDigits) {
28d8fc8cd3cd 8190904: Incorrect currency instance returned by java.util.Currency.getInstance()
nishjain
parents: 48251
diff changeset
   919
                // update the entry in main table
28d8fc8cd3cd 8190904: Incorrect currency instance returned by java.util.Currency.getInstance()
nishjain
parents: 48251
diff changeset
   920
                entry |= (fraction << SIMPLE_CASE_COUNTRY_DEFAULT_DIGITS_SHIFT)
28d8fc8cd3cd 8190904: Incorrect currency instance returned by java.util.Currency.getInstance()
nishjain
parents: 48251
diff changeset
   921
                        | (code.charAt(2) - 'A');
28d8fc8cd3cd 8190904: Incorrect currency instance returned by java.util.Currency.getInstance()
nishjain
parents: 48251
diff changeset
   922
                setMainTableEntry(code.charAt(0), code.charAt(1), entry);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   923
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   924
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   925
    }
38440
9e77c5b81def 7102969: currency.properties supercede not working correctly
nishjain
parents: 37815
diff changeset
   926
9e77c5b81def 7102969: currency.properties supercede not working correctly
nishjain
parents: 37815
diff changeset
   927
    /* Used to represent a special case currency entry
9e77c5b81def 7102969: currency.properties supercede not working correctly
nishjain
parents: 37815
diff changeset
   928
     * - cutOverTime: cut-over time in millis as returned by
9e77c5b81def 7102969: currency.properties supercede not working correctly
nishjain
parents: 37815
diff changeset
   929
     *   System.currentTimeMillis for special case countries that are changing
9e77c5b81def 7102969: currency.properties supercede not working correctly
nishjain
parents: 37815
diff changeset
   930
     *   currencies; Long.MAX_VALUE for countries that are not changing currencies
9e77c5b81def 7102969: currency.properties supercede not working correctly
nishjain
parents: 37815
diff changeset
   931
     * - oldCurrency: old currencies for special case countries
9e77c5b81def 7102969: currency.properties supercede not working correctly
nishjain
parents: 37815
diff changeset
   932
     * - newCurrency: new currencies for special case countries that are
9e77c5b81def 7102969: currency.properties supercede not working correctly
nishjain
parents: 37815
diff changeset
   933
     *   changing currencies; null for others
9e77c5b81def 7102969: currency.properties supercede not working correctly
nishjain
parents: 37815
diff changeset
   934
     * - oldCurrencyFraction: default fraction digits for old currencies
9e77c5b81def 7102969: currency.properties supercede not working correctly
nishjain
parents: 37815
diff changeset
   935
     * - newCurrencyFraction: default fraction digits for new currencies, 0 for
9e77c5b81def 7102969: currency.properties supercede not working correctly
nishjain
parents: 37815
diff changeset
   936
     *   countries that are not changing currencies
9e77c5b81def 7102969: currency.properties supercede not working correctly
nishjain
parents: 37815
diff changeset
   937
     * - oldCurrencyNumericCode: numeric code for old currencies
9e77c5b81def 7102969: currency.properties supercede not working correctly
nishjain
parents: 37815
diff changeset
   938
     * - newCurrencyNumericCode: numeric code for new currencies, 0 for countries
9e77c5b81def 7102969: currency.properties supercede not working correctly
nishjain
parents: 37815
diff changeset
   939
     *   that are not changing currencies
9e77c5b81def 7102969: currency.properties supercede not working correctly
nishjain
parents: 37815
diff changeset
   940
    */
9e77c5b81def 7102969: currency.properties supercede not working correctly
nishjain
parents: 37815
diff changeset
   941
    private static class SpecialCaseEntry {
9e77c5b81def 7102969: currency.properties supercede not working correctly
nishjain
parents: 37815
diff changeset
   942
9e77c5b81def 7102969: currency.properties supercede not working correctly
nishjain
parents: 37815
diff changeset
   943
        final private long cutOverTime;
9e77c5b81def 7102969: currency.properties supercede not working correctly
nishjain
parents: 37815
diff changeset
   944
        final private String oldCurrency;
9e77c5b81def 7102969: currency.properties supercede not working correctly
nishjain
parents: 37815
diff changeset
   945
        final private String newCurrency;
9e77c5b81def 7102969: currency.properties supercede not working correctly
nishjain
parents: 37815
diff changeset
   946
        final private int oldCurrencyFraction;
9e77c5b81def 7102969: currency.properties supercede not working correctly
nishjain
parents: 37815
diff changeset
   947
        final private int newCurrencyFraction;
9e77c5b81def 7102969: currency.properties supercede not working correctly
nishjain
parents: 37815
diff changeset
   948
        final private int oldCurrencyNumericCode;
9e77c5b81def 7102969: currency.properties supercede not working correctly
nishjain
parents: 37815
diff changeset
   949
        final private int newCurrencyNumericCode;
9e77c5b81def 7102969: currency.properties supercede not working correctly
nishjain
parents: 37815
diff changeset
   950
9e77c5b81def 7102969: currency.properties supercede not working correctly
nishjain
parents: 37815
diff changeset
   951
        private SpecialCaseEntry(long cutOverTime, String oldCurrency, String newCurrency,
9e77c5b81def 7102969: currency.properties supercede not working correctly
nishjain
parents: 37815
diff changeset
   952
                int oldCurrencyFraction, int newCurrencyFraction,
9e77c5b81def 7102969: currency.properties supercede not working correctly
nishjain
parents: 37815
diff changeset
   953
                int oldCurrencyNumericCode, int newCurrencyNumericCode) {
9e77c5b81def 7102969: currency.properties supercede not working correctly
nishjain
parents: 37815
diff changeset
   954
            this.cutOverTime = cutOverTime;
9e77c5b81def 7102969: currency.properties supercede not working correctly
nishjain
parents: 37815
diff changeset
   955
            this.oldCurrency = oldCurrency;
9e77c5b81def 7102969: currency.properties supercede not working correctly
nishjain
parents: 37815
diff changeset
   956
            this.newCurrency = newCurrency;
9e77c5b81def 7102969: currency.properties supercede not working correctly
nishjain
parents: 37815
diff changeset
   957
            this.oldCurrencyFraction = oldCurrencyFraction;
9e77c5b81def 7102969: currency.properties supercede not working correctly
nishjain
parents: 37815
diff changeset
   958
            this.newCurrencyFraction = newCurrencyFraction;
9e77c5b81def 7102969: currency.properties supercede not working correctly
nishjain
parents: 37815
diff changeset
   959
            this.oldCurrencyNumericCode = oldCurrencyNumericCode;
9e77c5b81def 7102969: currency.properties supercede not working correctly
nishjain
parents: 37815
diff changeset
   960
            this.newCurrencyNumericCode = newCurrencyNumericCode;
9e77c5b81def 7102969: currency.properties supercede not working correctly
nishjain
parents: 37815
diff changeset
   961
        }
9e77c5b81def 7102969: currency.properties supercede not working correctly
nishjain
parents: 37815
diff changeset
   962
9e77c5b81def 7102969: currency.properties supercede not working correctly
nishjain
parents: 37815
diff changeset
   963
        private SpecialCaseEntry(String currencyCode, int fraction,
9e77c5b81def 7102969: currency.properties supercede not working correctly
nishjain
parents: 37815
diff changeset
   964
                int numericCode) {
9e77c5b81def 7102969: currency.properties supercede not working correctly
nishjain
parents: 37815
diff changeset
   965
            this(Long.MAX_VALUE, currencyCode, "", fraction, 0, numericCode, 0);
9e77c5b81def 7102969: currency.properties supercede not working correctly
nishjain
parents: 37815
diff changeset
   966
        }
9e77c5b81def 7102969: currency.properties supercede not working correctly
nishjain
parents: 37815
diff changeset
   967
9e77c5b81def 7102969: currency.properties supercede not working correctly
nishjain
parents: 37815
diff changeset
   968
        //get the index of the special case entry
9e77c5b81def 7102969: currency.properties supercede not working correctly
nishjain
parents: 37815
diff changeset
   969
        private static int indexOf(String code, int fraction, int numeric) {
9e77c5b81def 7102969: currency.properties supercede not working correctly
nishjain
parents: 37815
diff changeset
   970
            int size = specialCasesList.size();
9e77c5b81def 7102969: currency.properties supercede not working correctly
nishjain
parents: 37815
diff changeset
   971
            for (int index = 0; index < size; index++) {
9e77c5b81def 7102969: currency.properties supercede not working correctly
nishjain
parents: 37815
diff changeset
   972
                SpecialCaseEntry scEntry = specialCasesList.get(index);
9e77c5b81def 7102969: currency.properties supercede not working correctly
nishjain
parents: 37815
diff changeset
   973
                if (scEntry.oldCurrency.equals(code)
9e77c5b81def 7102969: currency.properties supercede not working correctly
nishjain
parents: 37815
diff changeset
   974
                        && scEntry.oldCurrencyFraction == fraction
9e77c5b81def 7102969: currency.properties supercede not working correctly
nishjain
parents: 37815
diff changeset
   975
                        && scEntry.oldCurrencyNumericCode == numeric
9e77c5b81def 7102969: currency.properties supercede not working correctly
nishjain
parents: 37815
diff changeset
   976
                        && scEntry.cutOverTime == Long.MAX_VALUE) {
9e77c5b81def 7102969: currency.properties supercede not working correctly
nishjain
parents: 37815
diff changeset
   977
                    return index;
9e77c5b81def 7102969: currency.properties supercede not working correctly
nishjain
parents: 37815
diff changeset
   978
                }
9e77c5b81def 7102969: currency.properties supercede not working correctly
nishjain
parents: 37815
diff changeset
   979
            }
9e77c5b81def 7102969: currency.properties supercede not working correctly
nishjain
parents: 37815
diff changeset
   980
            return -1;
9e77c5b81def 7102969: currency.properties supercede not working correctly
nishjain
parents: 37815
diff changeset
   981
        }
9e77c5b81def 7102969: currency.properties supercede not working correctly
nishjain
parents: 37815
diff changeset
   982
9e77c5b81def 7102969: currency.properties supercede not working correctly
nishjain
parents: 37815
diff changeset
   983
        // get the fraction and numericCode of the sc currencycode
9e77c5b81def 7102969: currency.properties supercede not working correctly
nishjain
parents: 37815
diff changeset
   984
        private static int[] findEntry(String code) {
9e77c5b81def 7102969: currency.properties supercede not working correctly
nishjain
parents: 37815
diff changeset
   985
            int[] fractionAndNumericCode = null;
9e77c5b81def 7102969: currency.properties supercede not working correctly
nishjain
parents: 37815
diff changeset
   986
            int size = specialCasesList.size();
9e77c5b81def 7102969: currency.properties supercede not working correctly
nishjain
parents: 37815
diff changeset
   987
            for (int index = 0; index < size; index++) {
9e77c5b81def 7102969: currency.properties supercede not working correctly
nishjain
parents: 37815
diff changeset
   988
                SpecialCaseEntry scEntry = specialCasesList.get(index);
9e77c5b81def 7102969: currency.properties supercede not working correctly
nishjain
parents: 37815
diff changeset
   989
                if (scEntry.oldCurrency.equals(code) && (scEntry.cutOverTime == Long.MAX_VALUE
9e77c5b81def 7102969: currency.properties supercede not working correctly
nishjain
parents: 37815
diff changeset
   990
                        || System.currentTimeMillis() < scEntry.cutOverTime)) {
9e77c5b81def 7102969: currency.properties supercede not working correctly
nishjain
parents: 37815
diff changeset
   991
                    //consider only when there is no new currency or cutover time is not passed
9e77c5b81def 7102969: currency.properties supercede not working correctly
nishjain
parents: 37815
diff changeset
   992
                    fractionAndNumericCode = new int[2];
9e77c5b81def 7102969: currency.properties supercede not working correctly
nishjain
parents: 37815
diff changeset
   993
                    fractionAndNumericCode[0] = scEntry.oldCurrencyFraction;
9e77c5b81def 7102969: currency.properties supercede not working correctly
nishjain
parents: 37815
diff changeset
   994
                    fractionAndNumericCode[1] = scEntry.oldCurrencyNumericCode;
9e77c5b81def 7102969: currency.properties supercede not working correctly
nishjain
parents: 37815
diff changeset
   995
                    break;
9e77c5b81def 7102969: currency.properties supercede not working correctly
nishjain
parents: 37815
diff changeset
   996
                } else if (scEntry.newCurrency.equals(code)
9e77c5b81def 7102969: currency.properties supercede not working correctly
nishjain
parents: 37815
diff changeset
   997
                        && System.currentTimeMillis() >= scEntry.cutOverTime) {
9e77c5b81def 7102969: currency.properties supercede not working correctly
nishjain
parents: 37815
diff changeset
   998
                    //consider only if the cutover time is passed
9e77c5b81def 7102969: currency.properties supercede not working correctly
nishjain
parents: 37815
diff changeset
   999
                    fractionAndNumericCode = new int[2];
9e77c5b81def 7102969: currency.properties supercede not working correctly
nishjain
parents: 37815
diff changeset
  1000
                    fractionAndNumericCode[0] = scEntry.newCurrencyFraction;
9e77c5b81def 7102969: currency.properties supercede not working correctly
nishjain
parents: 37815
diff changeset
  1001
                    fractionAndNumericCode[1] = scEntry.newCurrencyNumericCode;
9e77c5b81def 7102969: currency.properties supercede not working correctly
nishjain
parents: 37815
diff changeset
  1002
                    break;
9e77c5b81def 7102969: currency.properties supercede not working correctly
nishjain
parents: 37815
diff changeset
  1003
                }
9e77c5b81def 7102969: currency.properties supercede not working correctly
nishjain
parents: 37815
diff changeset
  1004
            }
9e77c5b81def 7102969: currency.properties supercede not working correctly
nishjain
parents: 37815
diff changeset
  1005
            return fractionAndNumericCode;
9e77c5b81def 7102969: currency.properties supercede not working correctly
nishjain
parents: 37815
diff changeset
  1006
        }
9e77c5b81def 7102969: currency.properties supercede not working correctly
nishjain
parents: 37815
diff changeset
  1007
48929
28d8fc8cd3cd 8190904: Incorrect currency instance returned by java.util.Currency.getInstance()
nishjain
parents: 48251
diff changeset
  1008
        // get the index based on currency code
28d8fc8cd3cd 8190904: Incorrect currency instance returned by java.util.Currency.getInstance()
nishjain
parents: 48251
diff changeset
  1009
        private static int currencyCodeIndex(String code) {
28d8fc8cd3cd 8190904: Incorrect currency instance returned by java.util.Currency.getInstance()
nishjain
parents: 48251
diff changeset
  1010
            int size = specialCasesList.size();
28d8fc8cd3cd 8190904: Incorrect currency instance returned by java.util.Currency.getInstance()
nishjain
parents: 48251
diff changeset
  1011
            for (int index = 0; index < size; index++) {
28d8fc8cd3cd 8190904: Incorrect currency instance returned by java.util.Currency.getInstance()
nishjain
parents: 48251
diff changeset
  1012
                SpecialCaseEntry scEntry = specialCasesList.get(index);
28d8fc8cd3cd 8190904: Incorrect currency instance returned by java.util.Currency.getInstance()
nishjain
parents: 48251
diff changeset
  1013
                if (scEntry.oldCurrency.equals(code) && (scEntry.cutOverTime == Long.MAX_VALUE
28d8fc8cd3cd 8190904: Incorrect currency instance returned by java.util.Currency.getInstance()
nishjain
parents: 48251
diff changeset
  1014
                        || System.currentTimeMillis() < scEntry.cutOverTime)) {
28d8fc8cd3cd 8190904: Incorrect currency instance returned by java.util.Currency.getInstance()
nishjain
parents: 48251
diff changeset
  1015
                    //consider only when there is no new currency or cutover time is not passed
28d8fc8cd3cd 8190904: Incorrect currency instance returned by java.util.Currency.getInstance()
nishjain
parents: 48251
diff changeset
  1016
                    return index;
28d8fc8cd3cd 8190904: Incorrect currency instance returned by java.util.Currency.getInstance()
nishjain
parents: 48251
diff changeset
  1017
                } else if (scEntry.newCurrency.equals(code)
28d8fc8cd3cd 8190904: Incorrect currency instance returned by java.util.Currency.getInstance()
nishjain
parents: 48251
diff changeset
  1018
                        && System.currentTimeMillis() >= scEntry.cutOverTime) {
28d8fc8cd3cd 8190904: Incorrect currency instance returned by java.util.Currency.getInstance()
nishjain
parents: 48251
diff changeset
  1019
                    //consider only if the cutover time is passed
28d8fc8cd3cd 8190904: Incorrect currency instance returned by java.util.Currency.getInstance()
nishjain
parents: 48251
diff changeset
  1020
                    return index;
28d8fc8cd3cd 8190904: Incorrect currency instance returned by java.util.Currency.getInstance()
nishjain
parents: 48251
diff changeset
  1021
                }
28d8fc8cd3cd 8190904: Incorrect currency instance returned by java.util.Currency.getInstance()
nishjain
parents: 48251
diff changeset
  1022
            }
28d8fc8cd3cd 8190904: Incorrect currency instance returned by java.util.Currency.getInstance()
nishjain
parents: 48251
diff changeset
  1023
            return -1;
28d8fc8cd3cd 8190904: Incorrect currency instance returned by java.util.Currency.getInstance()
nishjain
parents: 48251
diff changeset
  1024
        }
28d8fc8cd3cd 8190904: Incorrect currency instance returned by java.util.Currency.getInstance()
nishjain
parents: 48251
diff changeset
  1025
28d8fc8cd3cd 8190904: Incorrect currency instance returned by java.util.Currency.getInstance()
nishjain
parents: 48251
diff changeset
  1026
38440
9e77c5b81def 7102969: currency.properties supercede not working correctly
nishjain
parents: 37815
diff changeset
  1027
        // convert the special case entry to sc arrays index
9e77c5b81def 7102969: currency.properties supercede not working correctly
nishjain
parents: 37815
diff changeset
  1028
        private static int toIndex(int tableEntry) {
9e77c5b81def 7102969: currency.properties supercede not working correctly
nishjain
parents: 37815
diff changeset
  1029
            return (tableEntry & SPECIAL_CASE_COUNTRY_INDEX_MASK) - SPECIAL_CASE_COUNTRY_INDEX_DELTA;
9e77c5b81def 7102969: currency.properties supercede not working correctly
nishjain
parents: 37815
diff changeset
  1030
        }
9e77c5b81def 7102969: currency.properties supercede not working correctly
nishjain
parents: 37815
diff changeset
  1031
9e77c5b81def 7102969: currency.properties supercede not working correctly
nishjain
parents: 37815
diff changeset
  1032
    }
9e77c5b81def 7102969: currency.properties supercede not working correctly
nishjain
parents: 37815
diff changeset
  1033
9e77c5b81def 7102969: currency.properties supercede not working correctly
nishjain
parents: 37815
diff changeset
  1034
    /* Used to represent Other currencies
9e77c5b81def 7102969: currency.properties supercede not working correctly
nishjain
parents: 37815
diff changeset
  1035
     * - currencyCode: currency codes that are not the main currency
9e77c5b81def 7102969: currency.properties supercede not working correctly
nishjain
parents: 37815
diff changeset
  1036
     *   of a simple country
9e77c5b81def 7102969: currency.properties supercede not working correctly
nishjain
parents: 37815
diff changeset
  1037
     * - otherCurrenciesDFD: decimal format digits for other currencies
9e77c5b81def 7102969: currency.properties supercede not working correctly
nishjain
parents: 37815
diff changeset
  1038
     * - otherCurrenciesNumericCode: numeric code for other currencies
9e77c5b81def 7102969: currency.properties supercede not working correctly
nishjain
parents: 37815
diff changeset
  1039
     */
9e77c5b81def 7102969: currency.properties supercede not working correctly
nishjain
parents: 37815
diff changeset
  1040
    private static class OtherCurrencyEntry {
9e77c5b81def 7102969: currency.properties supercede not working correctly
nishjain
parents: 37815
diff changeset
  1041
9e77c5b81def 7102969: currency.properties supercede not working correctly
nishjain
parents: 37815
diff changeset
  1042
        final private String currencyCode;
9e77c5b81def 7102969: currency.properties supercede not working correctly
nishjain
parents: 37815
diff changeset
  1043
        final private int fraction;
9e77c5b81def 7102969: currency.properties supercede not working correctly
nishjain
parents: 37815
diff changeset
  1044
        final private int numericCode;
9e77c5b81def 7102969: currency.properties supercede not working correctly
nishjain
parents: 37815
diff changeset
  1045
9e77c5b81def 7102969: currency.properties supercede not working correctly
nishjain
parents: 37815
diff changeset
  1046
        private OtherCurrencyEntry(String currencyCode, int fraction,
9e77c5b81def 7102969: currency.properties supercede not working correctly
nishjain
parents: 37815
diff changeset
  1047
                int numericCode) {
9e77c5b81def 7102969: currency.properties supercede not working correctly
nishjain
parents: 37815
diff changeset
  1048
            this.currencyCode = currencyCode;
9e77c5b81def 7102969: currency.properties supercede not working correctly
nishjain
parents: 37815
diff changeset
  1049
            this.fraction = fraction;
9e77c5b81def 7102969: currency.properties supercede not working correctly
nishjain
parents: 37815
diff changeset
  1050
            this.numericCode = numericCode;
9e77c5b81def 7102969: currency.properties supercede not working correctly
nishjain
parents: 37815
diff changeset
  1051
        }
9e77c5b81def 7102969: currency.properties supercede not working correctly
nishjain
parents: 37815
diff changeset
  1052
9e77c5b81def 7102969: currency.properties supercede not working correctly
nishjain
parents: 37815
diff changeset
  1053
        //get the instance of the other currency code
9e77c5b81def 7102969: currency.properties supercede not working correctly
nishjain
parents: 37815
diff changeset
  1054
        private static OtherCurrencyEntry findEntry(String code) {
9e77c5b81def 7102969: currency.properties supercede not working correctly
nishjain
parents: 37815
diff changeset
  1055
            int size = otherCurrenciesList.size();
9e77c5b81def 7102969: currency.properties supercede not working correctly
nishjain
parents: 37815
diff changeset
  1056
            for (int index = 0; index < size; index++) {
9e77c5b81def 7102969: currency.properties supercede not working correctly
nishjain
parents: 37815
diff changeset
  1057
                OtherCurrencyEntry ocEntry = otherCurrenciesList.get(index);
9e77c5b81def 7102969: currency.properties supercede not working correctly
nishjain
parents: 37815
diff changeset
  1058
                if (ocEntry.currencyCode.equalsIgnoreCase(code)) {
9e77c5b81def 7102969: currency.properties supercede not working correctly
nishjain
parents: 37815
diff changeset
  1059
                    return ocEntry;
9e77c5b81def 7102969: currency.properties supercede not working correctly
nishjain
parents: 37815
diff changeset
  1060
                }
9e77c5b81def 7102969: currency.properties supercede not working correctly
nishjain
parents: 37815
diff changeset
  1061
            }
9e77c5b81def 7102969: currency.properties supercede not working correctly
nishjain
parents: 37815
diff changeset
  1062
            return null;
9e77c5b81def 7102969: currency.properties supercede not working correctly
nishjain
parents: 37815
diff changeset
  1063
        }
9e77c5b81def 7102969: currency.properties supercede not working correctly
nishjain
parents: 37815
diff changeset
  1064
9e77c5b81def 7102969: currency.properties supercede not working correctly
nishjain
parents: 37815
diff changeset
  1065
    }
9e77c5b81def 7102969: currency.properties supercede not working correctly
nishjain
parents: 37815
diff changeset
  1066
48929
28d8fc8cd3cd 8190904: Incorrect currency instance returned by java.util.Currency.getInstance()
nishjain
parents: 48251
diff changeset
  1067
28d8fc8cd3cd 8190904: Incorrect currency instance returned by java.util.Currency.getInstance()
nishjain
parents: 48251
diff changeset
  1068
    /*
28d8fc8cd3cd 8190904: Incorrect currency instance returned by java.util.Currency.getInstance()
nishjain
parents: 48251
diff changeset
  1069
     * Used to represent an entry of the properties file that
28d8fc8cd3cd 8190904: Incorrect currency instance returned by java.util.Currency.getInstance()
nishjain
parents: 48251
diff changeset
  1070
     * java.util.currency.data designates
28d8fc8cd3cd 8190904: Incorrect currency instance returned by java.util.Currency.getInstance()
nishjain
parents: 48251
diff changeset
  1071
     *
28d8fc8cd3cd 8190904: Incorrect currency instance returned by java.util.Currency.getInstance()
nishjain
parents: 48251
diff changeset
  1072
     * - country: country representing the currency entry
28d8fc8cd3cd 8190904: Incorrect currency instance returned by java.util.Currency.getInstance()
nishjain
parents: 48251
diff changeset
  1073
     * - currencyCode: currency code
28d8fc8cd3cd 8190904: Incorrect currency instance returned by java.util.Currency.getInstance()
nishjain
parents: 48251
diff changeset
  1074
     * - fraction: default fraction digit
28d8fc8cd3cd 8190904: Incorrect currency instance returned by java.util.Currency.getInstance()
nishjain
parents: 48251
diff changeset
  1075
     * - numericCode: numeric code
28d8fc8cd3cd 8190904: Incorrect currency instance returned by java.util.Currency.getInstance()
nishjain
parents: 48251
diff changeset
  1076
     * - date: cutover date
28d8fc8cd3cd 8190904: Incorrect currency instance returned by java.util.Currency.getInstance()
nishjain
parents: 48251
diff changeset
  1077
     */
28d8fc8cd3cd 8190904: Incorrect currency instance returned by java.util.Currency.getInstance()
nishjain
parents: 48251
diff changeset
  1078
    private static class CurrencyProperty {
28d8fc8cd3cd 8190904: Incorrect currency instance returned by java.util.Currency.getInstance()
nishjain
parents: 48251
diff changeset
  1079
        final private String country;
28d8fc8cd3cd 8190904: Incorrect currency instance returned by java.util.Currency.getInstance()
nishjain
parents: 48251
diff changeset
  1080
        final private String currencyCode;
28d8fc8cd3cd 8190904: Incorrect currency instance returned by java.util.Currency.getInstance()
nishjain
parents: 48251
diff changeset
  1081
        final private int fraction;
28d8fc8cd3cd 8190904: Incorrect currency instance returned by java.util.Currency.getInstance()
nishjain
parents: 48251
diff changeset
  1082
        final private int numericCode;
28d8fc8cd3cd 8190904: Incorrect currency instance returned by java.util.Currency.getInstance()
nishjain
parents: 48251
diff changeset
  1083
        final private String date;
28d8fc8cd3cd 8190904: Incorrect currency instance returned by java.util.Currency.getInstance()
nishjain
parents: 48251
diff changeset
  1084
28d8fc8cd3cd 8190904: Incorrect currency instance returned by java.util.Currency.getInstance()
nishjain
parents: 48251
diff changeset
  1085
        private CurrencyProperty(String country, String currencyCode,
28d8fc8cd3cd 8190904: Incorrect currency instance returned by java.util.Currency.getInstance()
nishjain
parents: 48251
diff changeset
  1086
                int fraction, int numericCode, String date) {
28d8fc8cd3cd 8190904: Incorrect currency instance returned by java.util.Currency.getInstance()
nishjain
parents: 48251
diff changeset
  1087
            this.country = country;
28d8fc8cd3cd 8190904: Incorrect currency instance returned by java.util.Currency.getInstance()
nishjain
parents: 48251
diff changeset
  1088
            this.currencyCode = currencyCode;
28d8fc8cd3cd 8190904: Incorrect currency instance returned by java.util.Currency.getInstance()
nishjain
parents: 48251
diff changeset
  1089
            this.fraction = fraction;
28d8fc8cd3cd 8190904: Incorrect currency instance returned by java.util.Currency.getInstance()
nishjain
parents: 48251
diff changeset
  1090
            this.numericCode = numericCode;
28d8fc8cd3cd 8190904: Incorrect currency instance returned by java.util.Currency.getInstance()
nishjain
parents: 48251
diff changeset
  1091
            this.date = date;
28d8fc8cd3cd 8190904: Incorrect currency instance returned by java.util.Currency.getInstance()
nishjain
parents: 48251
diff changeset
  1092
        }
28d8fc8cd3cd 8190904: Incorrect currency instance returned by java.util.Currency.getInstance()
nishjain
parents: 48251
diff changeset
  1093
28d8fc8cd3cd 8190904: Incorrect currency instance returned by java.util.Currency.getInstance()
nishjain
parents: 48251
diff changeset
  1094
        /**
28d8fc8cd3cd 8190904: Incorrect currency instance returned by java.util.Currency.getInstance()
nishjain
parents: 48251
diff changeset
  1095
         * Check the valid currency data and create/return an Optional instance
28d8fc8cd3cd 8190904: Incorrect currency instance returned by java.util.Currency.getInstance()
nishjain
parents: 48251
diff changeset
  1096
         * of CurrencyProperty
28d8fc8cd3cd 8190904: Incorrect currency instance returned by java.util.Currency.getInstance()
nishjain
parents: 48251
diff changeset
  1097
         *
28d8fc8cd3cd 8190904: Incorrect currency instance returned by java.util.Currency.getInstance()
nishjain
parents: 48251
diff changeset
  1098
         * @param ctry    country representing the currency data
28d8fc8cd3cd 8190904: Incorrect currency instance returned by java.util.Currency.getInstance()
nishjain
parents: 48251
diff changeset
  1099
         * @param curData currency data of the given {@code ctry}
28d8fc8cd3cd 8190904: Incorrect currency instance returned by java.util.Currency.getInstance()
nishjain
parents: 48251
diff changeset
  1100
         * @param pattern regex pattern for the properties entry
28d8fc8cd3cd 8190904: Incorrect currency instance returned by java.util.Currency.getInstance()
nishjain
parents: 48251
diff changeset
  1101
         * @return Optional containing CurrencyProperty instance, If valid;
28d8fc8cd3cd 8190904: Incorrect currency instance returned by java.util.Currency.getInstance()
nishjain
parents: 48251
diff changeset
  1102
         *         empty otherwise
28d8fc8cd3cd 8190904: Incorrect currency instance returned by java.util.Currency.getInstance()
nishjain
parents: 48251
diff changeset
  1103
         */
28d8fc8cd3cd 8190904: Incorrect currency instance returned by java.util.Currency.getInstance()
nishjain
parents: 48251
diff changeset
  1104
        private static Optional<CurrencyProperty> getValidEntry(String ctry,
28d8fc8cd3cd 8190904: Incorrect currency instance returned by java.util.Currency.getInstance()
nishjain
parents: 48251
diff changeset
  1105
                String curData,
28d8fc8cd3cd 8190904: Incorrect currency instance returned by java.util.Currency.getInstance()
nishjain
parents: 48251
diff changeset
  1106
                Pattern pattern) {
28d8fc8cd3cd 8190904: Incorrect currency instance returned by java.util.Currency.getInstance()
nishjain
parents: 48251
diff changeset
  1107
28d8fc8cd3cd 8190904: Incorrect currency instance returned by java.util.Currency.getInstance()
nishjain
parents: 48251
diff changeset
  1108
            CurrencyProperty prop = null;
28d8fc8cd3cd 8190904: Incorrect currency instance returned by java.util.Currency.getInstance()
nishjain
parents: 48251
diff changeset
  1109
28d8fc8cd3cd 8190904: Incorrect currency instance returned by java.util.Currency.getInstance()
nishjain
parents: 48251
diff changeset
  1110
            if (ctry.length() != 2) {
28d8fc8cd3cd 8190904: Incorrect currency instance returned by java.util.Currency.getInstance()
nishjain
parents: 48251
diff changeset
  1111
                // Invalid country code. Ignore the entry.
28d8fc8cd3cd 8190904: Incorrect currency instance returned by java.util.Currency.getInstance()
nishjain
parents: 48251
diff changeset
  1112
            } else {
28d8fc8cd3cd 8190904: Incorrect currency instance returned by java.util.Currency.getInstance()
nishjain
parents: 48251
diff changeset
  1113
28d8fc8cd3cd 8190904: Incorrect currency instance returned by java.util.Currency.getInstance()
nishjain
parents: 48251
diff changeset
  1114
                prop = parseProperty(ctry, curData, pattern);
28d8fc8cd3cd 8190904: Incorrect currency instance returned by java.util.Currency.getInstance()
nishjain
parents: 48251
diff changeset
  1115
                // if the property entry failed any of the below checked
28d8fc8cd3cd 8190904: Incorrect currency instance returned by java.util.Currency.getInstance()
nishjain
parents: 48251
diff changeset
  1116
                // criteria it is ignored
28d8fc8cd3cd 8190904: Incorrect currency instance returned by java.util.Currency.getInstance()
nishjain
parents: 48251
diff changeset
  1117
                if (prop == null
28d8fc8cd3cd 8190904: Incorrect currency instance returned by java.util.Currency.getInstance()
nishjain
parents: 48251
diff changeset
  1118
                        || (prop.date == null && curData.chars()
28d8fc8cd3cd 8190904: Incorrect currency instance returned by java.util.Currency.getInstance()
nishjain
parents: 48251
diff changeset
  1119
                                .map(c -> c == ',' ? 1 : 0).sum() >= 3)) {
28d8fc8cd3cd 8190904: Incorrect currency instance returned by java.util.Currency.getInstance()
nishjain
parents: 48251
diff changeset
  1120
                    // format is not recognized.  ignore the data if date
28d8fc8cd3cd 8190904: Incorrect currency instance returned by java.util.Currency.getInstance()
nishjain
parents: 48251
diff changeset
  1121
                    // string is null and we've 4 values, bad date value
28d8fc8cd3cd 8190904: Incorrect currency instance returned by java.util.Currency.getInstance()
nishjain
parents: 48251
diff changeset
  1122
                    prop = null;
28d8fc8cd3cd 8190904: Incorrect currency instance returned by java.util.Currency.getInstance()
nishjain
parents: 48251
diff changeset
  1123
                } else if (prop.fraction
28d8fc8cd3cd 8190904: Incorrect currency instance returned by java.util.Currency.getInstance()
nishjain
parents: 48251
diff changeset
  1124
                        > SIMPLE_CASE_COUNTRY_MAX_DEFAULT_DIGITS) {
28d8fc8cd3cd 8190904: Incorrect currency instance returned by java.util.Currency.getInstance()
nishjain
parents: 48251
diff changeset
  1125
                    prop = null;
28d8fc8cd3cd 8190904: Incorrect currency instance returned by java.util.Currency.getInstance()
nishjain
parents: 48251
diff changeset
  1126
                } else {
28d8fc8cd3cd 8190904: Incorrect currency instance returned by java.util.Currency.getInstance()
nishjain
parents: 48251
diff changeset
  1127
                    try {
28d8fc8cd3cd 8190904: Incorrect currency instance returned by java.util.Currency.getInstance()
nishjain
parents: 48251
diff changeset
  1128
                        if (prop.date != null
28d8fc8cd3cd 8190904: Incorrect currency instance returned by java.util.Currency.getInstance()
nishjain
parents: 48251
diff changeset
  1129
                                && !isPastCutoverDate(prop.date)) {
28d8fc8cd3cd 8190904: Incorrect currency instance returned by java.util.Currency.getInstance()
nishjain
parents: 48251
diff changeset
  1130
                            prop = null;
28d8fc8cd3cd 8190904: Incorrect currency instance returned by java.util.Currency.getInstance()
nishjain
parents: 48251
diff changeset
  1131
                        }
28d8fc8cd3cd 8190904: Incorrect currency instance returned by java.util.Currency.getInstance()
nishjain
parents: 48251
diff changeset
  1132
                    } catch (ParseException ex) {
28d8fc8cd3cd 8190904: Incorrect currency instance returned by java.util.Currency.getInstance()
nishjain
parents: 48251
diff changeset
  1133
                        prop = null;
28d8fc8cd3cd 8190904: Incorrect currency instance returned by java.util.Currency.getInstance()
nishjain
parents: 48251
diff changeset
  1134
                    }
28d8fc8cd3cd 8190904: Incorrect currency instance returned by java.util.Currency.getInstance()
nishjain
parents: 48251
diff changeset
  1135
                }
28d8fc8cd3cd 8190904: Incorrect currency instance returned by java.util.Currency.getInstance()
nishjain
parents: 48251
diff changeset
  1136
            }
28d8fc8cd3cd 8190904: Incorrect currency instance returned by java.util.Currency.getInstance()
nishjain
parents: 48251
diff changeset
  1137
28d8fc8cd3cd 8190904: Incorrect currency instance returned by java.util.Currency.getInstance()
nishjain
parents: 48251
diff changeset
  1138
            if (prop == null) {
28d8fc8cd3cd 8190904: Incorrect currency instance returned by java.util.Currency.getInstance()
nishjain
parents: 48251
diff changeset
  1139
                info("The property entry for " + ctry + " is invalid."
28d8fc8cd3cd 8190904: Incorrect currency instance returned by java.util.Currency.getInstance()
nishjain
parents: 48251
diff changeset
  1140
                        + " Ignored.", null);
28d8fc8cd3cd 8190904: Incorrect currency instance returned by java.util.Currency.getInstance()
nishjain
parents: 48251
diff changeset
  1141
            }
28d8fc8cd3cd 8190904: Incorrect currency instance returned by java.util.Currency.getInstance()
nishjain
parents: 48251
diff changeset
  1142
28d8fc8cd3cd 8190904: Incorrect currency instance returned by java.util.Currency.getInstance()
nishjain
parents: 48251
diff changeset
  1143
            return Optional.ofNullable(prop);
28d8fc8cd3cd 8190904: Incorrect currency instance returned by java.util.Currency.getInstance()
nishjain
parents: 48251
diff changeset
  1144
        }
28d8fc8cd3cd 8190904: Incorrect currency instance returned by java.util.Currency.getInstance()
nishjain
parents: 48251
diff changeset
  1145
28d8fc8cd3cd 8190904: Incorrect currency instance returned by java.util.Currency.getInstance()
nishjain
parents: 48251
diff changeset
  1146
        /*
28d8fc8cd3cd 8190904: Incorrect currency instance returned by java.util.Currency.getInstance()
nishjain
parents: 48251
diff changeset
  1147
         * Parse properties entry and return CurrencyProperty instance
28d8fc8cd3cd 8190904: Incorrect currency instance returned by java.util.Currency.getInstance()
nishjain
parents: 48251
diff changeset
  1148
         */
28d8fc8cd3cd 8190904: Incorrect currency instance returned by java.util.Currency.getInstance()
nishjain
parents: 48251
diff changeset
  1149
        private static CurrencyProperty parseProperty(String ctry,
28d8fc8cd3cd 8190904: Incorrect currency instance returned by java.util.Currency.getInstance()
nishjain
parents: 48251
diff changeset
  1150
                String curData, Pattern pattern) {
28d8fc8cd3cd 8190904: Incorrect currency instance returned by java.util.Currency.getInstance()
nishjain
parents: 48251
diff changeset
  1151
            Matcher m = pattern.matcher(curData);
28d8fc8cd3cd 8190904: Incorrect currency instance returned by java.util.Currency.getInstance()
nishjain
parents: 48251
diff changeset
  1152
            if (!m.find()) {
28d8fc8cd3cd 8190904: Incorrect currency instance returned by java.util.Currency.getInstance()
nishjain
parents: 48251
diff changeset
  1153
                return null;
28d8fc8cd3cd 8190904: Incorrect currency instance returned by java.util.Currency.getInstance()
nishjain
parents: 48251
diff changeset
  1154
            } else {
28d8fc8cd3cd 8190904: Incorrect currency instance returned by java.util.Currency.getInstance()
nishjain
parents: 48251
diff changeset
  1155
                return new CurrencyProperty(ctry, m.group(1),
28d8fc8cd3cd 8190904: Incorrect currency instance returned by java.util.Currency.getInstance()
nishjain
parents: 48251
diff changeset
  1156
                        Integer.parseInt(m.group(3)),
28d8fc8cd3cd 8190904: Incorrect currency instance returned by java.util.Currency.getInstance()
nishjain
parents: 48251
diff changeset
  1157
                        Integer.parseInt(m.group(2)), m.group(4));
28d8fc8cd3cd 8190904: Incorrect currency instance returned by java.util.Currency.getInstance()
nishjain
parents: 48251
diff changeset
  1158
            }
28d8fc8cd3cd 8190904: Incorrect currency instance returned by java.util.Currency.getInstance()
nishjain
parents: 48251
diff changeset
  1159
        }
28d8fc8cd3cd 8190904: Incorrect currency instance returned by java.util.Currency.getInstance()
nishjain
parents: 48251
diff changeset
  1160
28d8fc8cd3cd 8190904: Incorrect currency instance returned by java.util.Currency.getInstance()
nishjain
parents: 48251
diff changeset
  1161
        /**
28d8fc8cd3cd 8190904: Incorrect currency instance returned by java.util.Currency.getInstance()
nishjain
parents: 48251
diff changeset
  1162
         * Checks if the given list contains multiple inconsistent currency instances
28d8fc8cd3cd 8190904: Incorrect currency instance returned by java.util.Currency.getInstance()
nishjain
parents: 48251
diff changeset
  1163
         */
28d8fc8cd3cd 8190904: Incorrect currency instance returned by java.util.Currency.getInstance()
nishjain
parents: 48251
diff changeset
  1164
        private static boolean containsInconsistentInstances(
28d8fc8cd3cd 8190904: Incorrect currency instance returned by java.util.Currency.getInstance()
nishjain
parents: 48251
diff changeset
  1165
                List<CurrencyProperty> list) {
28d8fc8cd3cd 8190904: Incorrect currency instance returned by java.util.Currency.getInstance()
nishjain
parents: 48251
diff changeset
  1166
            int numCode = list.get(0).numericCode;
28d8fc8cd3cd 8190904: Incorrect currency instance returned by java.util.Currency.getInstance()
nishjain
parents: 48251
diff changeset
  1167
            int fractionDigit = list.get(0).fraction;
28d8fc8cd3cd 8190904: Incorrect currency instance returned by java.util.Currency.getInstance()
nishjain
parents: 48251
diff changeset
  1168
            return list.stream().anyMatch(prop -> prop.numericCode != numCode
28d8fc8cd3cd 8190904: Incorrect currency instance returned by java.util.Currency.getInstance()
nishjain
parents: 48251
diff changeset
  1169
                    || prop.fraction != fractionDigit);
28d8fc8cd3cd 8190904: Incorrect currency instance returned by java.util.Currency.getInstance()
nishjain
parents: 48251
diff changeset
  1170
        }
28d8fc8cd3cd 8190904: Incorrect currency instance returned by java.util.Currency.getInstance()
nishjain
parents: 48251
diff changeset
  1171
28d8fc8cd3cd 8190904: Incorrect currency instance returned by java.util.Currency.getInstance()
nishjain
parents: 48251
diff changeset
  1172
        private static boolean isPastCutoverDate(String s)
28d8fc8cd3cd 8190904: Incorrect currency instance returned by java.util.Currency.getInstance()
nishjain
parents: 48251
diff changeset
  1173
                throws ParseException {
28d8fc8cd3cd 8190904: Incorrect currency instance returned by java.util.Currency.getInstance()
nishjain
parents: 48251
diff changeset
  1174
            SimpleDateFormat format = new SimpleDateFormat(
28d8fc8cd3cd 8190904: Incorrect currency instance returned by java.util.Currency.getInstance()
nishjain
parents: 48251
diff changeset
  1175
                    "yyyy-MM-dd'T'HH:mm:ss", Locale.ROOT);
28d8fc8cd3cd 8190904: Incorrect currency instance returned by java.util.Currency.getInstance()
nishjain
parents: 48251
diff changeset
  1176
            format.setTimeZone(TimeZone.getTimeZone("UTC"));
28d8fc8cd3cd 8190904: Incorrect currency instance returned by java.util.Currency.getInstance()
nishjain
parents: 48251
diff changeset
  1177
            format.setLenient(false);
28d8fc8cd3cd 8190904: Incorrect currency instance returned by java.util.Currency.getInstance()
nishjain
parents: 48251
diff changeset
  1178
            long time = format.parse(s.trim()).getTime();
28d8fc8cd3cd 8190904: Incorrect currency instance returned by java.util.Currency.getInstance()
nishjain
parents: 48251
diff changeset
  1179
            return System.currentTimeMillis() > time;
28d8fc8cd3cd 8190904: Incorrect currency instance returned by java.util.Currency.getInstance()
nishjain
parents: 48251
diff changeset
  1180
28d8fc8cd3cd 8190904: Incorrect currency instance returned by java.util.Currency.getInstance()
nishjain
parents: 48251
diff changeset
  1181
        }
28d8fc8cd3cd 8190904: Incorrect currency instance returned by java.util.Currency.getInstance()
nishjain
parents: 48251
diff changeset
  1182
28d8fc8cd3cd 8190904: Incorrect currency instance returned by java.util.Currency.getInstance()
nishjain
parents: 48251
diff changeset
  1183
        private static void info(String message, Throwable t) {
28d8fc8cd3cd 8190904: Incorrect currency instance returned by java.util.Currency.getInstance()
nishjain
parents: 48251
diff changeset
  1184
            PlatformLogger logger = PlatformLogger
28d8fc8cd3cd 8190904: Incorrect currency instance returned by java.util.Currency.getInstance()
nishjain
parents: 48251
diff changeset
  1185
                    .getLogger("java.util.Currency");
28d8fc8cd3cd 8190904: Incorrect currency instance returned by java.util.Currency.getInstance()
nishjain
parents: 48251
diff changeset
  1186
            if (logger.isLoggable(PlatformLogger.Level.INFO)) {
28d8fc8cd3cd 8190904: Incorrect currency instance returned by java.util.Currency.getInstance()
nishjain
parents: 48251
diff changeset
  1187
                if (t != null) {
28d8fc8cd3cd 8190904: Incorrect currency instance returned by java.util.Currency.getInstance()
nishjain
parents: 48251
diff changeset
  1188
                    logger.info(message, t);
28d8fc8cd3cd 8190904: Incorrect currency instance returned by java.util.Currency.getInstance()
nishjain
parents: 48251
diff changeset
  1189
                } else {
28d8fc8cd3cd 8190904: Incorrect currency instance returned by java.util.Currency.getInstance()
nishjain
parents: 48251
diff changeset
  1190
                    logger.info(message);
28d8fc8cd3cd 8190904: Incorrect currency instance returned by java.util.Currency.getInstance()
nishjain
parents: 48251
diff changeset
  1191
                }
28d8fc8cd3cd 8190904: Incorrect currency instance returned by java.util.Currency.getInstance()
nishjain
parents: 48251
diff changeset
  1192
            }
28d8fc8cd3cd 8190904: Incorrect currency instance returned by java.util.Currency.getInstance()
nishjain
parents: 48251
diff changeset
  1193
        }
28d8fc8cd3cd 8190904: Incorrect currency instance returned by java.util.Currency.getInstance()
nishjain
parents: 48251
diff changeset
  1194
28d8fc8cd3cd 8190904: Incorrect currency instance returned by java.util.Currency.getInstance()
nishjain
parents: 48251
diff changeset
  1195
    }
28d8fc8cd3cd 8190904: Incorrect currency instance returned by java.util.Currency.getInstance()
nishjain
parents: 48251
diff changeset
  1196
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1197
}
37815
0ecfe8f6500e 8154295: Currency iso code is int and hence looses the preceeding zero.
peytoia
parents: 36113
diff changeset
  1198
38440
9e77c5b81def 7102969: currency.properties supercede not working correctly
nishjain
parents: 37815
diff changeset
  1199