author | nishjain |
Fri, 20 May 2016 13:48:58 +0900 | |
changeset 38440 | 9e77c5b81def |
parent 37815 | 0ecfe8f6500e |
permissions | -rw-r--r-- |
2 | 1 |
/* |
36113
cd5af2894aee
8074411: Describe "minor unit" and/or "default fraction digits" in Currency class' javadoc clearly
peytoia
parents:
32930
diff
changeset
|
2 |
* Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved. |
2 | 3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
5506 | 7 |
* published by the Free Software Foundation. Oracle designates this |
2 | 8 |
* particular file as subject to the "Classpath" exception as provided |
5506 | 9 |
* by Oracle in the LICENSE file that accompanied this code. |
2 | 10 |
* |
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
15 |
* accompanied this code). |
|
16 |
* |
|
17 |
* You should have received a copy of the GNU General Public License version |
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
20 |
* |
|
5506 | 21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
22 |
* or visit www.oracle.com if you need additional information or have any |
|
23 |
* questions. |
|
2 | 24 |
*/ |
25 |
||
26 |
package java.util; |
|
27 |
||
28 |
import java.io.BufferedInputStream; |
|
29 |
import java.io.DataInputStream; |
|
30 |
import java.io.File; |
|
31 |
import java.io.FileInputStream; |
|
32 |
import java.io.FileReader; |
|
27565 | 33 |
import java.io.InputStream; |
2 | 34 |
import java.io.IOException; |
35 |
import java.io.Serializable; |
|
36 |
import java.security.AccessController; |
|
37 |
import java.security.PrivilegedAction; |
|
13790
5b29e3921008
7180362: RFE: Implement date cutover functionality for currency.properties file
coffeys
parents:
13583
diff
changeset
|
38 |
import java.text.ParseException; |
5b29e3921008
7180362: RFE: Implement date cutover functionality for currency.properties file
coffeys
parents:
13583
diff
changeset
|
39 |
import java.text.SimpleDateFormat; |
12202
2a63f5718d33
7145454: JVM wide monitor lock in Currency.getInstance(String)
naoto
parents:
11138
diff
changeset
|
40 |
import java.util.concurrent.ConcurrentHashMap; |
2a63f5718d33
7145454: JVM wide monitor lock in Currency.getInstance(String)
naoto
parents:
11138
diff
changeset
|
41 |
import java.util.concurrent.ConcurrentMap; |
2 | 42 |
import java.util.regex.Pattern; |
43 |
import java.util.regex.Matcher; |
|
44 |
import java.util.spi.CurrencyNameProvider; |
|
13583 | 45 |
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
|
46 |
import sun.util.logging.PlatformLogger; |
2 | 47 |
|
48 |
||
49 |
/** |
|
50 |
* 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
|
51 |
* 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
|
52 |
* ISO web site</a> for more information. |
2 | 53 |
* <p> |
54 |
* The class is designed so that there's never more than one |
|
55 |
* <code>Currency</code> instance for any given currency. Therefore, there's |
|
56 |
* no public constructor. You obtain a <code>Currency</code> instance using |
|
57 |
* the <code>getInstance</code> methods. |
|
58 |
* <p> |
|
14697
6ed46ffc2d33
8003846: Override mechanism for currency data should not require creating currency.properties in java.home
alanb
parents:
14014
diff
changeset
|
59 |
* 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
|
60 |
* 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
|
61 |
* 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
|
62 |
* 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
|
63 |
* 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
|
64 |
* 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
|
65 |
* 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
|
66 |
* 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
|
67 |
* 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
|
68 |
* 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
|
69 |
* 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
|
70 |
* 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
|
71 |
* 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
|
72 |
* 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
|
73 |
* {@code 'yyyy-MM-dd'T'HH:mm:ss'}. For example, |
2 | 74 |
* <p> |
75 |
* <code> |
|
76 |
* #Sample currency properties<br> |
|
77 |
* JP=JPZ,999,0 |
|
78 |
* </code> |
|
79 |
* <p> |
|
80 |
* will supersede the currency data for Japan. |
|
81 |
* |
|
13790
5b29e3921008
7180362: RFE: Implement date cutover functionality for currency.properties file
coffeys
parents:
13583
diff
changeset
|
82 |
* <p> |
5b29e3921008
7180362: RFE: Implement date cutover functionality for currency.properties file
coffeys
parents:
13583
diff
changeset
|
83 |
* <code> |
5b29e3921008
7180362: RFE: Implement date cutover functionality for currency.properties file
coffeys
parents:
13583
diff
changeset
|
84 |
* #Sample currency properties with cutover date<br> |
5b29e3921008
7180362: RFE: Implement date cutover functionality for currency.properties file
coffeys
parents:
13583
diff
changeset
|
85 |
* 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
|
86 |
* </code> |
5b29e3921008
7180362: RFE: Implement date cutover functionality for currency.properties file
coffeys
parents:
13583
diff
changeset
|
87 |
* <p> |
5b29e3921008
7180362: RFE: Implement date cutover functionality for currency.properties file
coffeys
parents:
13583
diff
changeset
|
88 |
* 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
|
89 |
* 1st January 2014 00:00:00 GMT. |
5b29e3921008
7180362: RFE: Implement date cutover functionality for currency.properties file
coffeys
parents:
13583
diff
changeset
|
90 |
* <p> |
5b29e3921008
7180362: RFE: Implement date cutover functionality for currency.properties file
coffeys
parents:
13583
diff
changeset
|
91 |
* 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
|
92 |
* 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
|
93 |
* 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
|
94 |
* {@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
|
95 |
* <p> |
cd5af2894aee
8074411: Describe "minor unit" and/or "default fraction digits" in Currency class' javadoc clearly
peytoia
parents:
32930
diff
changeset
|
96 |
* 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
|
97 |
* 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
|
98 |
* point numbers and their operations. |
13790
5b29e3921008
7180362: RFE: Implement date cutover functionality for currency.properties file
coffeys
parents:
13583
diff
changeset
|
99 |
* |
36113
cd5af2894aee
8074411: Describe "minor unit" and/or "default fraction digits" in Currency class' javadoc clearly
peytoia
parents:
32930
diff
changeset
|
100 |
* @see java.math.BigDecimal |
2 | 101 |
* @since 1.4 |
102 |
*/ |
|
103 |
public final class Currency implements Serializable { |
|
104 |
||
105 |
private static final long serialVersionUID = -158308464356906721L; |
|
106 |
||
107 |
/** |
|
108 |
* ISO 4217 currency code for this currency. |
|
109 |
* |
|
110 |
* @serial |
|
111 |
*/ |
|
112 |
private final String currencyCode; |
|
113 |
||
114 |
/** |
|
115 |
* Default fraction digits for this currency. |
|
116 |
* Set from currency data tables. |
|
117 |
*/ |
|
32649
2ee9017c7597
8136583: Core libraries should use blessed modifier order
martin
parents:
29986
diff
changeset
|
118 |
private final transient int defaultFractionDigits; |
2 | 119 |
|
120 |
/** |
|
121 |
* ISO 4217 numeric code for this currency. |
|
122 |
* Set from currency data tables. |
|
123 |
*/ |
|
32649
2ee9017c7597
8136583: Core libraries should use blessed modifier order
martin
parents:
29986
diff
changeset
|
124 |
private final transient int numericCode; |
2 | 125 |
|
126 |
||
127 |
// class data: instance map |
|
128 |
||
12202
2a63f5718d33
7145454: JVM wide monitor lock in Currency.getInstance(String)
naoto
parents:
11138
diff
changeset
|
129 |
private static ConcurrentMap<String, Currency> instances = new ConcurrentHashMap<>(7); |
2 | 130 |
private static HashSet<Currency> available; |
131 |
||
132 |
// Class data: currency data obtained from currency.data file. |
|
133 |
// Purpose: |
|
134 |
// - determine valid country codes |
|
135 |
// - determine valid currency codes |
|
136 |
// - map country codes to currency codes |
|
137 |
// - obtain default fraction digits for currency codes |
|
138 |
// |
|
139 |
// sc = special case; dfd = default fraction digits |
|
140 |
// Simple countries are those where the country code is a prefix of the |
|
141 |
// currency code, and there are no known plans to change the currency. |
|
142 |
// |
|
143 |
// table formats: |
|
144 |
// - mainTable: |
|
145 |
// - maps country code to 32-bit int |
|
146 |
// - 26*26 entries, corresponding to [A-Z]*[A-Z] |
|
147 |
// - \u007F -> not valid country |
|
29524
2dbceeab4b8b
8074350: Support ISO 4217 "Current funds codes" table (A.2)
naoto
parents:
27565
diff
changeset
|
148 |
// - bits 20-31: unused |
2dbceeab4b8b
8074350: Support ISO 4217 "Current funds codes" table (A.2)
naoto
parents:
27565
diff
changeset
|
149 |
// - bits 10-19: numeric code (0 to 1023) |
2dbceeab4b8b
8074350: Support ISO 4217 "Current funds codes" table (A.2)
naoto
parents:
27565
diff
changeset
|
150 |
// - bit 9: 1 - special case, bits 0-4 indicate which one |
2 | 151 |
// 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
|
152 |
// - bits 5-8: fraction digits for simple countries, 0 for special cases |
2 | 153 |
// - bits 0-4: final char for currency code for simple country, or ID of special case |
154 |
// - special case IDs: |
|
155 |
// - 0: country has no currency |
|
38440
9e77c5b81def
7102969: currency.properties supercede not working correctly
nishjain
parents:
37815
diff
changeset
|
156 |
// - other: index into specialCasesList |
2 | 157 |
|
158 |
static int formatVersion; |
|
159 |
static int dataVersion; |
|
160 |
static int[] mainTable; |
|
38440
9e77c5b81def
7102969: currency.properties supercede not working correctly
nishjain
parents:
37815
diff
changeset
|
161 |
static List<SpecialCaseEntry> specialCasesList; |
9e77c5b81def
7102969: currency.properties supercede not working correctly
nishjain
parents:
37815
diff
changeset
|
162 |
static List<OtherCurrencyEntry> otherCurrenciesList; |
2 | 163 |
|
164 |
// handy constants - must match definitions in GenerateCurrencyData |
|
165 |
// magic number |
|
166 |
private static final int MAGIC_NUMBER = 0x43757244; |
|
167 |
// number of characters from A to Z |
|
168 |
private static final int A_TO_Z = ('Z' - 'A') + 1; |
|
169 |
// entry for invalid country codes |
|
29524
2dbceeab4b8b
8074350: Support ISO 4217 "Current funds codes" table (A.2)
naoto
parents:
27565
diff
changeset
|
170 |
private static final int INVALID_COUNTRY_ENTRY = 0x0000007F; |
2 | 171 |
// entry for countries without currency |
29524
2dbceeab4b8b
8074350: Support ISO 4217 "Current funds codes" table (A.2)
naoto
parents:
27565
diff
changeset
|
172 |
private static final int COUNTRY_WITHOUT_CURRENCY_ENTRY = 0x00000200; |
2 | 173 |
// mask for simple case country entries |
29524
2dbceeab4b8b
8074350: Support ISO 4217 "Current funds codes" table (A.2)
naoto
parents:
27565
diff
changeset
|
174 |
private static final int SIMPLE_CASE_COUNTRY_MASK = 0x00000000; |
2 | 175 |
// 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
|
176 |
private static final int SIMPLE_CASE_COUNTRY_FINAL_CHAR_MASK = 0x0000001F; |
2 | 177 |
// 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
|
178 |
private static final int SIMPLE_CASE_COUNTRY_DEFAULT_DIGITS_MASK = 0x000001E0; |
2 | 179 |
// shift count for simple case country entry default currency digits |
180 |
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
|
181 |
// 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
|
182 |
private static final int SIMPLE_CASE_COUNTRY_MAX_DEFAULT_DIGITS = 9; |
2 | 183 |
// mask for special case country entries |
29524
2dbceeab4b8b
8074350: Support ISO 4217 "Current funds codes" table (A.2)
naoto
parents:
27565
diff
changeset
|
184 |
private static final int SPECIAL_CASE_COUNTRY_MASK = 0x00000200; |
2 | 185 |
// mask for special case country index |
29524
2dbceeab4b8b
8074350: Support ISO 4217 "Current funds codes" table (A.2)
naoto
parents:
27565
diff
changeset
|
186 |
private static final int SPECIAL_CASE_COUNTRY_INDEX_MASK = 0x0000001F; |
2 | 187 |
// delta from entry index component in main table to index into special case tables |
188 |
private static final int SPECIAL_CASE_COUNTRY_INDEX_DELTA = 1; |
|
189 |
// mask for distinguishing simple and special case countries |
|
190 |
private static final int COUNTRY_TYPE_MASK = SIMPLE_CASE_COUNTRY_MASK | SPECIAL_CASE_COUNTRY_MASK; |
|
191 |
// 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
|
192 |
private static final int NUMERIC_CODE_MASK = 0x000FFC00; |
2 | 193 |
// 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
|
194 |
private static final int NUMERIC_CODE_SHIFT = 10; |
2 | 195 |
|
196 |
// Currency data format version |
|
38440
9e77c5b81def
7102969: currency.properties supercede not working correctly
nishjain
parents:
37815
diff
changeset
|
197 |
private static final int VALID_FORMAT_VERSION = 3; |
2 | 198 |
|
199 |
static { |
|
29986
97167d851fc4
8078467: Update core libraries to use diamond with anonymous classes
darcy
parents:
29524
diff
changeset
|
200 |
AccessController.doPrivileged(new PrivilegedAction<>() { |
13583 | 201 |
@Override |
202 |
public Void run() { |
|
2 | 203 |
try { |
27565 | 204 |
try (InputStream in = getClass().getResourceAsStream("/java/util/currency.data")) { |
205 |
if (in == null) { |
|
206 |
throw new InternalError("Currency data not found"); |
|
207 |
} |
|
208 |
DataInputStream dis = new DataInputStream(new BufferedInputStream(in)); |
|
13583 | 209 |
if (dis.readInt() != MAGIC_NUMBER) { |
210 |
throw new InternalError("Currency data is possibly corrupted"); |
|
211 |
} |
|
212 |
formatVersion = dis.readInt(); |
|
213 |
if (formatVersion != VALID_FORMAT_VERSION) { |
|
214 |
throw new InternalError("Currency data format is incorrect"); |
|
215 |
} |
|
216 |
dataVersion = dis.readInt(); |
|
217 |
mainTable = readIntArray(dis, A_TO_Z * A_TO_Z); |
|
218 |
int scCount = dis.readInt(); |
|
38440
9e77c5b81def
7102969: currency.properties supercede not working correctly
nishjain
parents:
37815
diff
changeset
|
219 |
specialCasesList = readSpecialCases(dis, scCount); |
13583 | 220 |
int ocCount = dis.readInt(); |
38440
9e77c5b81def
7102969: currency.properties supercede not working correctly
nishjain
parents:
37815
diff
changeset
|
221 |
otherCurrenciesList = readOtherCurrencies(dis, ocCount); |
2 | 222 |
} |
223 |
} catch (IOException e) { |
|
10419
12c063b39232
7084245: Update usages of InternalError to use exception chaining
sherman
parents:
9035
diff
changeset
|
224 |
throw new InternalError(e); |
2 | 225 |
} |
226 |
||
227 |
// 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
|
228 |
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
|
229 |
if (propsFile == null) { |
25174 | 230 |
propsFile = System.getProperty("java.home") + 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
|
231 |
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
|
232 |
} |
2 | 233 |
try { |
14697
6ed46ffc2d33
8003846: Override mechanism for currency data should not require creating currency.properties in java.home
alanb
parents:
14014
diff
changeset
|
234 |
File propFile = new File(propsFile); |
2 | 235 |
if (propFile.exists()) { |
236 |
Properties props = new Properties(); |
|
8543
e5ec12a932da
7021209: convert lang, math, util to use try-with-resources
smarks
parents:
7668
diff
changeset
|
237 |
try (FileReader fr = new FileReader(propFile)) { |
e5ec12a932da
7021209: convert lang, math, util to use try-with-resources
smarks
parents:
7668
diff
changeset
|
238 |
props.load(fr); |
e5ec12a932da
7021209: convert lang, math, util to use try-with-resources
smarks
parents:
7668
diff
changeset
|
239 |
} |
2 | 240 |
Set<String> keys = props.stringPropertyNames(); |
241 |
Pattern propertiesPattern = |
|
13790
5b29e3921008
7180362: RFE: Implement date cutover functionality for currency.properties file
coffeys
parents:
13583
diff
changeset
|
242 |
Pattern.compile("([A-Z]{3})\\s*,\\s*(\\d{3})\\s*,\\s*" + |
29524
2dbceeab4b8b
8074350: Support ISO 4217 "Current funds codes" table (A.2)
naoto
parents:
27565
diff
changeset
|
243 |
"(\\d+)\\s*,?\\s*(\\d{4}-\\d{2}-\\d{2}T\\d{2}:" + |
13790
5b29e3921008
7180362: RFE: Implement date cutover functionality for currency.properties file
coffeys
parents:
13583
diff
changeset
|
244 |
"\\d{2}:\\d{2})?"); |
2 | 245 |
for (String key : keys) { |
246 |
replaceCurrencyData(propertiesPattern, |
|
247 |
key.toUpperCase(Locale.ROOT), |
|
248 |
props.getProperty(key).toUpperCase(Locale.ROOT)); |
|
249 |
} |
|
250 |
} |
|
251 |
} catch (IOException e) { |
|
3861
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
2
diff
changeset
|
252 |
info("currency.properties is ignored because of an IOException", e); |
2 | 253 |
} |
254 |
return null; |
|
255 |
} |
|
256 |
}); |
|
257 |
} |
|
258 |
||
259 |
/** |
|
260 |
* Constants for retrieving localized names from the name providers. |
|
261 |
*/ |
|
262 |
private static final int SYMBOL = 0; |
|
263 |
private static final int DISPLAYNAME = 1; |
|
264 |
||
265 |
||
266 |
/** |
|
267 |
* Constructs a <code>Currency</code> instance. The constructor is private |
|
268 |
* so that we can insure that there's never more than one instance for a |
|
269 |
* given currency. |
|
270 |
*/ |
|
271 |
private Currency(String currencyCode, int defaultFractionDigits, int numericCode) { |
|
272 |
this.currencyCode = currencyCode; |
|
273 |
this.defaultFractionDigits = defaultFractionDigits; |
|
274 |
this.numericCode = numericCode; |
|
275 |
} |
|
276 |
||
277 |
/** |
|
278 |
* Returns the <code>Currency</code> instance for the given currency code. |
|
279 |
* |
|
280 |
* @param currencyCode the ISO 4217 code of the currency |
|
281 |
* @return the <code>Currency</code> instance for the given currency code |
|
282 |
* @exception NullPointerException if <code>currencyCode</code> is null |
|
283 |
* @exception IllegalArgumentException if <code>currencyCode</code> is not |
|
284 |
* a supported ISO 4217 code. |
|
285 |
*/ |
|
286 |
public static Currency getInstance(String currencyCode) { |
|
287 |
return getInstance(currencyCode, Integer.MIN_VALUE, 0); |
|
288 |
} |
|
289 |
||
290 |
private static Currency getInstance(String currencyCode, int defaultFractionDigits, |
|
291 |
int numericCode) { |
|
12297
d12a3f2860eb
7156459: Remove unnecessary get() from Currency.getInstance()
naoto
parents:
12202
diff
changeset
|
292 |
// Try to look up the currency code in the instances table. |
d12a3f2860eb
7156459: Remove unnecessary get() from Currency.getInstance()
naoto
parents:
12202
diff
changeset
|
293 |
// This does the null pointer check as a side effect. |
d12a3f2860eb
7156459: Remove unnecessary get() from Currency.getInstance()
naoto
parents:
12202
diff
changeset
|
294 |
// 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
|
295 |
Currency instance = instances.get(currencyCode); |
d12a3f2860eb
7156459: Remove unnecessary get() from Currency.getInstance()
naoto
parents:
12202
diff
changeset
|
296 |
if (instance != null) { |
d12a3f2860eb
7156459: Remove unnecessary get() from Currency.getInstance()
naoto
parents:
12202
diff
changeset
|
297 |
return instance; |
d12a3f2860eb
7156459: Remove unnecessary get() from Currency.getInstance()
naoto
parents:
12202
diff
changeset
|
298 |
} |
d12a3f2860eb
7156459: Remove unnecessary get() from Currency.getInstance()
naoto
parents:
12202
diff
changeset
|
299 |
|
d12a3f2860eb
7156459: Remove unnecessary get() from Currency.getInstance()
naoto
parents:
12202
diff
changeset
|
300 |
if (defaultFractionDigits == Integer.MIN_VALUE) { |
d12a3f2860eb
7156459: Remove unnecessary get() from Currency.getInstance()
naoto
parents:
12202
diff
changeset
|
301 |
// Currency code not internally generated, need to verify first |
d12a3f2860eb
7156459: Remove unnecessary get() from Currency.getInstance()
naoto
parents:
12202
diff
changeset
|
302 |
// 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
|
303 |
// or in the list of other currencies. |
38440
9e77c5b81def
7102969: currency.properties supercede not working correctly
nishjain
parents:
37815
diff
changeset
|
304 |
boolean found = false; |
12297
d12a3f2860eb
7156459: Remove unnecessary get() from Currency.getInstance()
naoto
parents:
12202
diff
changeset
|
305 |
if (currencyCode.length() != 3) { |
d12a3f2860eb
7156459: Remove unnecessary get() from Currency.getInstance()
naoto
parents:
12202
diff
changeset
|
306 |
throw new IllegalArgumentException(); |
2 | 307 |
} |
12297
d12a3f2860eb
7156459: Remove unnecessary get() from Currency.getInstance()
naoto
parents:
12202
diff
changeset
|
308 |
char char1 = currencyCode.charAt(0); |
d12a3f2860eb
7156459: Remove unnecessary get() from Currency.getInstance()
naoto
parents:
12202
diff
changeset
|
309 |
char char2 = currencyCode.charAt(1); |
d12a3f2860eb
7156459: Remove unnecessary get() from Currency.getInstance()
naoto
parents:
12202
diff
changeset
|
310 |
int tableEntry = getMainTableEntry(char1, char2); |
d12a3f2860eb
7156459: Remove unnecessary get() from Currency.getInstance()
naoto
parents:
12202
diff
changeset
|
311 |
if ((tableEntry & COUNTRY_TYPE_MASK) == SIMPLE_CASE_COUNTRY_MASK |
d12a3f2860eb
7156459: Remove unnecessary get() from Currency.getInstance()
naoto
parents:
12202
diff
changeset
|
312 |
&& tableEntry != INVALID_COUNTRY_ENTRY |
d12a3f2860eb
7156459: Remove unnecessary get() from Currency.getInstance()
naoto
parents:
12202
diff
changeset
|
313 |
&& currencyCode.charAt(2) - 'A' == (tableEntry & SIMPLE_CASE_COUNTRY_FINAL_CHAR_MASK)) { |
d12a3f2860eb
7156459: Remove unnecessary get() from Currency.getInstance()
naoto
parents:
12202
diff
changeset
|
314 |
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
|
315 |
numericCode = (tableEntry & NUMERIC_CODE_MASK) >> NUMERIC_CODE_SHIFT; |
38440
9e77c5b81def
7102969: currency.properties supercede not working correctly
nishjain
parents:
37815
diff
changeset
|
316 |
found = true; |
9e77c5b81def
7102969: currency.properties supercede not working correctly
nishjain
parents:
37815
diff
changeset
|
317 |
} else { //special case |
9e77c5b81def
7102969: currency.properties supercede not working correctly
nishjain
parents:
37815
diff
changeset
|
318 |
int[] fractionAndNumericCode = SpecialCaseEntry.findEntry(currencyCode); |
9e77c5b81def
7102969: currency.properties supercede not working correctly
nishjain
parents:
37815
diff
changeset
|
319 |
if (fractionAndNumericCode != null) { |
9e77c5b81def
7102969: currency.properties supercede not working correctly
nishjain
parents:
37815
diff
changeset
|
320 |
defaultFractionDigits = fractionAndNumericCode[0]; |
9e77c5b81def
7102969: currency.properties supercede not working correctly
nishjain
parents:
37815
diff
changeset
|
321 |
numericCode = fractionAndNumericCode[1]; |
9e77c5b81def
7102969: currency.properties supercede not working correctly
nishjain
parents:
37815
diff
changeset
|
322 |
found = true; |
9e77c5b81def
7102969: currency.properties supercede not working correctly
nishjain
parents:
37815
diff
changeset
|
323 |
} |
9e77c5b81def
7102969: currency.properties supercede not working correctly
nishjain
parents:
37815
diff
changeset
|
324 |
} |
9e77c5b81def
7102969: currency.properties supercede not working correctly
nishjain
parents:
37815
diff
changeset
|
325 |
|
9e77c5b81def
7102969: currency.properties supercede not working correctly
nishjain
parents:
37815
diff
changeset
|
326 |
if (!found) { |
9e77c5b81def
7102969: currency.properties supercede not working correctly
nishjain
parents:
37815
diff
changeset
|
327 |
OtherCurrencyEntry ocEntry = OtherCurrencyEntry.findEntry(currencyCode); |
9e77c5b81def
7102969: currency.properties supercede not working correctly
nishjain
parents:
37815
diff
changeset
|
328 |
if (ocEntry == null) { |
2 | 329 |
throw new IllegalArgumentException(); |
330 |
} |
|
38440
9e77c5b81def
7102969: currency.properties supercede not working correctly
nishjain
parents:
37815
diff
changeset
|
331 |
defaultFractionDigits = ocEntry.fraction; |
9e77c5b81def
7102969: currency.properties supercede not working correctly
nishjain
parents:
37815
diff
changeset
|
332 |
numericCode = ocEntry.numericCode; |
2 | 333 |
} |
12297
d12a3f2860eb
7156459: Remove unnecessary get() from Currency.getInstance()
naoto
parents:
12202
diff
changeset
|
334 |
} |
2 | 335 |
|
12297
d12a3f2860eb
7156459: Remove unnecessary get() from Currency.getInstance()
naoto
parents:
12202
diff
changeset
|
336 |
Currency currencyVal = |
d12a3f2860eb
7156459: Remove unnecessary get() from Currency.getInstance()
naoto
parents:
12202
diff
changeset
|
337 |
new Currency(currencyCode, defaultFractionDigits, numericCode); |
d12a3f2860eb
7156459: Remove unnecessary get() from Currency.getInstance()
naoto
parents:
12202
diff
changeset
|
338 |
instance = instances.putIfAbsent(currencyCode, currencyVal); |
d12a3f2860eb
7156459: Remove unnecessary get() from Currency.getInstance()
naoto
parents:
12202
diff
changeset
|
339 |
return (instance != null ? instance : currencyVal); |
2 | 340 |
} |
341 |
||
342 |
/** |
|
343 |
* Returns the <code>Currency</code> instance for the country of the |
|
344 |
* given locale. The language and variant components of the locale |
|
345 |
* are ignored. The result may vary over time, as countries change their |
|
346 |
* currencies. For example, for the original member countries of the |
|
347 |
* European Monetary Union, the method returns the old national currencies |
|
348 |
* until December 31, 2001, and the Euro from January 1, 2002, local time |
|
349 |
* of the respective countries. |
|
350 |
* <p> |
|
351 |
* The method returns <code>null</code> for territories that don't |
|
352 |
* have a currency, such as Antarctica. |
|
353 |
* |
|
354 |
* @param locale the locale for whose country a <code>Currency</code> |
|
355 |
* instance is needed |
|
356 |
* @return the <code>Currency</code> instance for the country of the given |
|
13583 | 357 |
* locale, or {@code null} |
32930
7616af8ec145
8075315: API doc of Currency.getInstance(Locale) method is incorrect.
naoto
parents:
32649
diff
changeset
|
358 |
* @exception NullPointerException if <code>locale</code> |
7616af8ec145
8075315: API doc of Currency.getInstance(Locale) method is incorrect.
naoto
parents:
32649
diff
changeset
|
359 |
* is {@code null} |
13583 | 360 |
* @exception IllegalArgumentException if the country of the given {@code locale} |
2 | 361 |
* is not a supported ISO 3166 country code. |
362 |
*/ |
|
363 |
public static Currency getInstance(Locale locale) { |
|
364 |
String country = locale.getCountry(); |
|
365 |
if (country == null) { |
|
366 |
throw new NullPointerException(); |
|
367 |
} |
|
368 |
||
369 |
if (country.length() != 2) { |
|
370 |
throw new IllegalArgumentException(); |
|
371 |
} |
|
372 |
||
373 |
char char1 = country.charAt(0); |
|
374 |
char char2 = country.charAt(1); |
|
375 |
int tableEntry = getMainTableEntry(char1, char2); |
|
376 |
if ((tableEntry & COUNTRY_TYPE_MASK) == SIMPLE_CASE_COUNTRY_MASK |
|
377 |
&& tableEntry != INVALID_COUNTRY_ENTRY) { |
|
378 |
char finalChar = (char) ((tableEntry & SIMPLE_CASE_COUNTRY_FINAL_CHAR_MASK) + 'A'); |
|
379 |
int defaultFractionDigits = (tableEntry & SIMPLE_CASE_COUNTRY_DEFAULT_DIGITS_MASK) >> SIMPLE_CASE_COUNTRY_DEFAULT_DIGITS_SHIFT; |
|
380 |
int numericCode = (tableEntry & NUMERIC_CODE_MASK) >> NUMERIC_CODE_SHIFT; |
|
13583 | 381 |
StringBuilder sb = new StringBuilder(country); |
2 | 382 |
sb.append(finalChar); |
383 |
return getInstance(sb.toString(), defaultFractionDigits, numericCode); |
|
384 |
} else { |
|
385 |
// special cases |
|
386 |
if (tableEntry == INVALID_COUNTRY_ENTRY) { |
|
387 |
throw new IllegalArgumentException(); |
|
388 |
} |
|
389 |
if (tableEntry == COUNTRY_WITHOUT_CURRENCY_ENTRY) { |
|
390 |
return null; |
|
391 |
} else { |
|
38440
9e77c5b81def
7102969: currency.properties supercede not working correctly
nishjain
parents:
37815
diff
changeset
|
392 |
int index = SpecialCaseEntry.toIndex(tableEntry); |
9e77c5b81def
7102969: currency.properties supercede not working correctly
nishjain
parents:
37815
diff
changeset
|
393 |
SpecialCaseEntry scEntry = specialCasesList.get(index); |
9e77c5b81def
7102969: currency.properties supercede not working correctly
nishjain
parents:
37815
diff
changeset
|
394 |
if (scEntry.cutOverTime == Long.MAX_VALUE |
9e77c5b81def
7102969: currency.properties supercede not working correctly
nishjain
parents:
37815
diff
changeset
|
395 |
|| System.currentTimeMillis() < scEntry.cutOverTime) { |
9e77c5b81def
7102969: currency.properties supercede not working correctly
nishjain
parents:
37815
diff
changeset
|
396 |
return getInstance(scEntry.oldCurrency, |
9e77c5b81def
7102969: currency.properties supercede not working correctly
nishjain
parents:
37815
diff
changeset
|
397 |
scEntry.oldCurrencyFraction, |
9e77c5b81def
7102969: currency.properties supercede not working correctly
nishjain
parents:
37815
diff
changeset
|
398 |
scEntry.oldCurrencyNumericCode); |
2 | 399 |
} else { |
38440
9e77c5b81def
7102969: currency.properties supercede not working correctly
nishjain
parents:
37815
diff
changeset
|
400 |
return getInstance(scEntry.newCurrency, |
9e77c5b81def
7102969: currency.properties supercede not working correctly
nishjain
parents:
37815
diff
changeset
|
401 |
scEntry.newCurrencyFraction, |
9e77c5b81def
7102969: currency.properties supercede not working correctly
nishjain
parents:
37815
diff
changeset
|
402 |
scEntry.newCurrencyNumericCode); |
2 | 403 |
} |
404 |
} |
|
405 |
} |
|
406 |
} |
|
407 |
||
408 |
/** |
|
409 |
* Gets the set of available currencies. The returned set of currencies |
|
410 |
* contains all of the available currencies, which may include currencies |
|
411 |
* that represent obsolete ISO 4217 codes. The set can be modified |
|
412 |
* without affecting the available currencies in the runtime. |
|
413 |
* |
|
414 |
* @return the set of available currencies. If there is no currency |
|
415 |
* available in the runtime, the returned set is empty. |
|
416 |
* @since 1.7 |
|
417 |
*/ |
|
418 |
public static Set<Currency> getAvailableCurrencies() { |
|
419 |
synchronized(Currency.class) { |
|
420 |
if (available == null) { |
|
12448 | 421 |
available = new HashSet<>(256); |
2 | 422 |
|
423 |
// Add simple currencies first |
|
424 |
for (char c1 = 'A'; c1 <= 'Z'; c1 ++) { |
|
425 |
for (char c2 = 'A'; c2 <= 'Z'; c2 ++) { |
|
426 |
int tableEntry = getMainTableEntry(c1, c2); |
|
427 |
if ((tableEntry & COUNTRY_TYPE_MASK) == SIMPLE_CASE_COUNTRY_MASK |
|
428 |
&& tableEntry != INVALID_COUNTRY_ENTRY) { |
|
429 |
char finalChar = (char) ((tableEntry & SIMPLE_CASE_COUNTRY_FINAL_CHAR_MASK) + 'A'); |
|
430 |
int defaultFractionDigits = (tableEntry & SIMPLE_CASE_COUNTRY_DEFAULT_DIGITS_MASK) >> SIMPLE_CASE_COUNTRY_DEFAULT_DIGITS_SHIFT; |
|
431 |
int numericCode = (tableEntry & NUMERIC_CODE_MASK) >> NUMERIC_CODE_SHIFT; |
|
432 |
StringBuilder sb = new StringBuilder(); |
|
433 |
sb.append(c1); |
|
434 |
sb.append(c2); |
|
435 |
sb.append(finalChar); |
|
436 |
available.add(getInstance(sb.toString(), defaultFractionDigits, numericCode)); |
|
38440
9e77c5b81def
7102969: currency.properties supercede not working correctly
nishjain
parents:
37815
diff
changeset
|
437 |
} else if ((tableEntry & COUNTRY_TYPE_MASK) == SPECIAL_CASE_COUNTRY_MASK |
9e77c5b81def
7102969: currency.properties supercede not working correctly
nishjain
parents:
37815
diff
changeset
|
438 |
&& tableEntry != INVALID_COUNTRY_ENTRY |
9e77c5b81def
7102969: currency.properties supercede not working correctly
nishjain
parents:
37815
diff
changeset
|
439 |
&& tableEntry != COUNTRY_WITHOUT_CURRENCY_ENTRY) { |
9e77c5b81def
7102969: currency.properties supercede not working correctly
nishjain
parents:
37815
diff
changeset
|
440 |
int index = SpecialCaseEntry.toIndex(tableEntry); |
9e77c5b81def
7102969: currency.properties supercede not working correctly
nishjain
parents:
37815
diff
changeset
|
441 |
SpecialCaseEntry scEntry = specialCasesList.get(index); |
9e77c5b81def
7102969: currency.properties supercede not working correctly
nishjain
parents:
37815
diff
changeset
|
442 |
|
9e77c5b81def
7102969: currency.properties supercede not working correctly
nishjain
parents:
37815
diff
changeset
|
443 |
if (scEntry.cutOverTime == Long.MAX_VALUE |
9e77c5b81def
7102969: currency.properties supercede not working correctly
nishjain
parents:
37815
diff
changeset
|
444 |
|| System.currentTimeMillis() < scEntry.cutOverTime) { |
9e77c5b81def
7102969: currency.properties supercede not working correctly
nishjain
parents:
37815
diff
changeset
|
445 |
available.add(getInstance(scEntry.oldCurrency, |
9e77c5b81def
7102969: currency.properties supercede not working correctly
nishjain
parents:
37815
diff
changeset
|
446 |
scEntry.oldCurrencyFraction, |
9e77c5b81def
7102969: currency.properties supercede not working correctly
nishjain
parents:
37815
diff
changeset
|
447 |
scEntry.oldCurrencyNumericCode)); |
9e77c5b81def
7102969: currency.properties supercede not working correctly
nishjain
parents:
37815
diff
changeset
|
448 |
} else { |
9e77c5b81def
7102969: currency.properties supercede not working correctly
nishjain
parents:
37815
diff
changeset
|
449 |
available.add(getInstance(scEntry.newCurrency, |
9e77c5b81def
7102969: currency.properties supercede not working correctly
nishjain
parents:
37815
diff
changeset
|
450 |
scEntry.newCurrencyFraction, |
9e77c5b81def
7102969: currency.properties supercede not working correctly
nishjain
parents:
37815
diff
changeset
|
451 |
scEntry.newCurrencyNumericCode)); |
9e77c5b81def
7102969: currency.properties supercede not working correctly
nishjain
parents:
37815
diff
changeset
|
452 |
} |
2 | 453 |
} |
454 |
} |
|
455 |
} |
|
456 |
||
457 |
// Now add other currencies |
|
38440
9e77c5b81def
7102969: currency.properties supercede not working correctly
nishjain
parents:
37815
diff
changeset
|
458 |
for (OtherCurrencyEntry entry : otherCurrenciesList) { |
9e77c5b81def
7102969: currency.properties supercede not working correctly
nishjain
parents:
37815
diff
changeset
|
459 |
available.add(getInstance(entry.currencyCode)); |
2 | 460 |
} |
461 |
} |
|
462 |
} |
|
463 |
||
11138
9121a1a92512
7117469: Warning cleanup for j.u.Currency and j.u.Locale related classes
naoto
parents:
10419
diff
changeset
|
464 |
@SuppressWarnings("unchecked") |
9121a1a92512
7117469: Warning cleanup for j.u.Currency and j.u.Locale related classes
naoto
parents:
10419
diff
changeset
|
465 |
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
|
466 |
return result; |
2 | 467 |
} |
468 |
||
469 |
/** |
|
470 |
* Gets the ISO 4217 currency code of this currency. |
|
471 |
* |
|
472 |
* @return the ISO 4217 currency code of this currency. |
|
473 |
*/ |
|
474 |
public String getCurrencyCode() { |
|
475 |
return currencyCode; |
|
476 |
} |
|
477 |
||
478 |
/** |
|
16010
2727163b5df5
7092447: Clarify the default locale used in each locale sensitive operation
naoto
parents:
16006
diff
changeset
|
479 |
* 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
|
480 |
* {@link Locale.Category#DISPLAY DISPLAY} locale. |
2 | 481 |
* For example, for the US Dollar, the symbol is "$" if the default |
482 |
* locale is the US, while for other locales it may be "US$". If no |
|
483 |
* 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
|
484 |
* <p> |
2727163b5df5
7092447: Clarify the default locale used in each locale sensitive operation
naoto
parents:
16006
diff
changeset
|
485 |
* This is equivalent to calling |
2727163b5df5
7092447: Clarify the default locale used in each locale sensitive operation
naoto
parents:
16006
diff
changeset
|
486 |
* {@link #getSymbol(Locale) |
2727163b5df5
7092447: Clarify the default locale used in each locale sensitive operation
naoto
parents:
16006
diff
changeset
|
487 |
* getSymbol(Locale.getDefault(Locale.Category.DISPLAY))}. |
2 | 488 |
* |
16010
2727163b5df5
7092447: Clarify the default locale used in each locale sensitive operation
naoto
parents:
16006
diff
changeset
|
489 |
* @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
|
490 |
* {@link Locale.Category#DISPLAY DISPLAY} locale |
2 | 491 |
*/ |
492 |
public String getSymbol() { |
|
6489
9e7015635425
4700857: RFE: separating user locale and user interface locale
naoto
parents:
5506
diff
changeset
|
493 |
return getSymbol(Locale.getDefault(Locale.Category.DISPLAY)); |
2 | 494 |
} |
495 |
||
496 |
/** |
|
497 |
* Gets the symbol of this currency for the specified locale. |
|
498 |
* For example, for the US Dollar, the symbol is "$" if the specified |
|
499 |
* locale is the US, while for other locales it may be "US$". If no |
|
500 |
* symbol can be determined, the ISO 4217 currency code is returned. |
|
501 |
* |
|
502 |
* @param locale the locale for which a display name for this currency is |
|
503 |
* needed |
|
504 |
* @return the symbol of this currency for the specified locale |
|
505 |
* @exception NullPointerException if <code>locale</code> is null |
|
506 |
*/ |
|
507 |
public String getSymbol(Locale locale) { |
|
13583 | 508 |
LocaleServiceProviderPool pool = |
509 |
LocaleServiceProviderPool.getPool(CurrencyNameProvider.class); |
|
510 |
String symbol = pool.getLocalizedObject( |
|
511 |
CurrencyNameGetter.INSTANCE, |
|
512 |
locale, currencyCode, SYMBOL); |
|
513 |
if (symbol != null) { |
|
514 |
return symbol; |
|
515 |
} |
|
2 | 516 |
|
13583 | 517 |
// use currency code as symbol of last resort |
518 |
return currencyCode; |
|
2 | 519 |
} |
520 |
||
521 |
/** |
|
38440
9e77c5b81def
7102969: currency.properties supercede not working correctly
nishjain
parents:
37815
diff
changeset
|
522 |
* Gets the default number of fraction digits used with this currency. |
9e77c5b81def
7102969: currency.properties supercede not working correctly
nishjain
parents:
37815
diff
changeset
|
523 |
* 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
|
524 |
* minor unit for the currency. |
9e77c5b81def
7102969: currency.properties supercede not working correctly
nishjain
parents:
37815
diff
changeset
|
525 |
* 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
|
526 |
* while for the Japanese Yen it's 0. |
9e77c5b81def
7102969: currency.properties supercede not working correctly
nishjain
parents:
37815
diff
changeset
|
527 |
* 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
|
528 |
* -1 is returned. |
9e77c5b81def
7102969: currency.properties supercede not working correctly
nishjain
parents:
37815
diff
changeset
|
529 |
* |
9e77c5b81def
7102969: currency.properties supercede not working correctly
nishjain
parents:
37815
diff
changeset
|
530 |
* @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
|
531 |
*/ |
2 | 532 |
public int getDefaultFractionDigits() { |
533 |
return defaultFractionDigits; |
|
534 |
} |
|
535 |
||
536 |
/** |
|
537 |
* Returns the ISO 4217 numeric code of this currency. |
|
538 |
* |
|
539 |
* @return the ISO 4217 numeric code of this currency |
|
540 |
* @since 1.7 |
|
541 |
*/ |
|
542 |
public int getNumericCode() { |
|
543 |
return numericCode; |
|
544 |
} |
|
545 |
||
546 |
/** |
|
37815
0ecfe8f6500e
8154295: Currency iso code is int and hence looses the preceeding zero.
peytoia
parents:
36113
diff
changeset
|
547 |
* Returns 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
|
548 |
* Unlike {@link getNumericCode()}, which returns the numeric code as {@code int}, |
0ecfe8f6500e
8154295: Currency iso code is int and hence looses the preceeding zero.
peytoia
parents:
36113
diff
changeset
|
549 |
* 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
|
550 |
* 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
|
551 |
* 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
|
552 |
* |
0ecfe8f6500e
8154295: Currency iso code is int and hence looses the preceeding zero.
peytoia
parents:
36113
diff
changeset
|
553 |
* @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
|
554 |
* @since 9 |
0ecfe8f6500e
8154295: Currency iso code is int and hence looses the preceeding zero.
peytoia
parents:
36113
diff
changeset
|
555 |
*/ |
0ecfe8f6500e
8154295: Currency iso code is int and hence looses the preceeding zero.
peytoia
parents:
36113
diff
changeset
|
556 |
public String getNumericCodeAsString() { |
0ecfe8f6500e
8154295: Currency iso code is int and hence looses the preceeding zero.
peytoia
parents:
36113
diff
changeset
|
557 |
/* 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
|
558 |
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
|
559 |
"%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
|
560 |
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
|
561 |
*/ |
0ecfe8f6500e
8154295: Currency iso code is int and hence looses the preceeding zero.
peytoia
parents:
36113
diff
changeset
|
562 |
if (numericCode < 100) { |
0ecfe8f6500e
8154295: Currency iso code is int and hence looses the preceeding zero.
peytoia
parents:
36113
diff
changeset
|
563 |
StringBuilder sb = new StringBuilder(); |
0ecfe8f6500e
8154295: Currency iso code is int and hence looses the preceeding zero.
peytoia
parents:
36113
diff
changeset
|
564 |
sb.append('0'); |
0ecfe8f6500e
8154295: Currency iso code is int and hence looses the preceeding zero.
peytoia
parents:
36113
diff
changeset
|
565 |
if (numericCode < 10) { |
0ecfe8f6500e
8154295: Currency iso code is int and hence looses the preceeding zero.
peytoia
parents:
36113
diff
changeset
|
566 |
sb.append('0'); |
0ecfe8f6500e
8154295: Currency iso code is int and hence looses the preceeding zero.
peytoia
parents:
36113
diff
changeset
|
567 |
} |
0ecfe8f6500e
8154295: Currency iso code is int and hence looses the preceeding zero.
peytoia
parents:
36113
diff
changeset
|
568 |
return sb.append(numericCode).toString(); |
0ecfe8f6500e
8154295: Currency iso code is int and hence looses the preceeding zero.
peytoia
parents:
36113
diff
changeset
|
569 |
} |
0ecfe8f6500e
8154295: Currency iso code is int and hence looses the preceeding zero.
peytoia
parents:
36113
diff
changeset
|
570 |
return String.valueOf(numericCode); |
0ecfe8f6500e
8154295: Currency iso code is int and hence looses the preceeding zero.
peytoia
parents:
36113
diff
changeset
|
571 |
} |
0ecfe8f6500e
8154295: Currency iso code is int and hence looses the preceeding zero.
peytoia
parents:
36113
diff
changeset
|
572 |
|
0ecfe8f6500e
8154295: Currency iso code is int and hence looses the preceeding zero.
peytoia
parents:
36113
diff
changeset
|
573 |
/** |
2 | 574 |
* 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
|
575 |
* 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
|
576 |
* If there is no suitable display name found |
2 | 577 |
* 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
|
578 |
* <p> |
2727163b5df5
7092447: Clarify the default locale used in each locale sensitive operation
naoto
parents:
16006
diff
changeset
|
579 |
* This is equivalent to calling |
2727163b5df5
7092447: Clarify the default locale used in each locale sensitive operation
naoto
parents:
16006
diff
changeset
|
580 |
* {@link #getDisplayName(Locale) |
2727163b5df5
7092447: Clarify the default locale used in each locale sensitive operation
naoto
parents:
16006
diff
changeset
|
581 |
* getDisplayName(Locale.getDefault(Locale.Category.DISPLAY))}. |
2 | 582 |
* |
16010
2727163b5df5
7092447: Clarify the default locale used in each locale sensitive operation
naoto
parents:
16006
diff
changeset
|
583 |
* @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
|
584 |
* {@link Locale.Category#DISPLAY DISPLAY} locale |
2 | 585 |
* @since 1.7 |
586 |
*/ |
|
587 |
public String getDisplayName() { |
|
6489
9e7015635425
4700857: RFE: separating user locale and user interface locale
naoto
parents:
5506
diff
changeset
|
588 |
return getDisplayName(Locale.getDefault(Locale.Category.DISPLAY)); |
2 | 589 |
} |
590 |
||
591 |
/** |
|
592 |
* Gets the name that is suitable for displaying this currency for |
|
593 |
* the specified locale. If there is no suitable display name found |
|
594 |
* for the specified locale, the ISO 4217 currency code is returned. |
|
595 |
* |
|
596 |
* @param locale the locale for which a display name for this currency is |
|
597 |
* needed |
|
598 |
* @return the display name of this currency for the specified locale |
|
599 |
* @exception NullPointerException if <code>locale</code> is null |
|
600 |
* @since 1.7 |
|
601 |
*/ |
|
602 |
public String getDisplayName(Locale locale) { |
|
13583 | 603 |
LocaleServiceProviderPool pool = |
604 |
LocaleServiceProviderPool.getPool(CurrencyNameProvider.class); |
|
605 |
String result = pool.getLocalizedObject( |
|
606 |
CurrencyNameGetter.INSTANCE, |
|
607 |
locale, currencyCode, DISPLAYNAME); |
|
608 |
if (result != null) { |
|
609 |
return result; |
|
2 | 610 |
} |
611 |
||
612 |
// use currency code as symbol of last resort |
|
613 |
return currencyCode; |
|
614 |
} |
|
615 |
||
616 |
/** |
|
617 |
* Returns the ISO 4217 currency code of this currency. |
|
618 |
* |
|
619 |
* @return the ISO 4217 currency code of this currency |
|
620 |
*/ |
|
13583 | 621 |
@Override |
2 | 622 |
public String toString() { |
623 |
return currencyCode; |
|
624 |
} |
|
625 |
||
626 |
/** |
|
627 |
* Resolves instances being deserialized to a single instance per currency. |
|
628 |
*/ |
|
629 |
private Object readResolve() { |
|
630 |
return getInstance(currencyCode); |
|
631 |
} |
|
632 |
||
633 |
/** |
|
634 |
* Gets the main table entry for the country whose country code consists |
|
635 |
* of char1 and char2. |
|
636 |
*/ |
|
637 |
private static int getMainTableEntry(char char1, char char2) { |
|
638 |
if (char1 < 'A' || char1 > 'Z' || char2 < 'A' || char2 > 'Z') { |
|
639 |
throw new IllegalArgumentException(); |
|
640 |
} |
|
641 |
return mainTable[(char1 - 'A') * A_TO_Z + (char2 - 'A')]; |
|
642 |
} |
|
643 |
||
644 |
/** |
|
645 |
* Sets the main table entry for the country whose country code consists |
|
646 |
* of char1 and char2. |
|
647 |
*/ |
|
648 |
private static void setMainTableEntry(char char1, char char2, int entry) { |
|
649 |
if (char1 < 'A' || char1 > 'Z' || char2 < 'A' || char2 > 'Z') { |
|
650 |
throw new IllegalArgumentException(); |
|
651 |
} |
|
652 |
mainTable[(char1 - 'A') * A_TO_Z + (char2 - 'A')] = entry; |
|
653 |
} |
|
654 |
||
655 |
/** |
|
656 |
* Obtains a localized currency names from a CurrencyNameProvider |
|
657 |
* implementation. |
|
658 |
*/ |
|
659 |
private static class CurrencyNameGetter |
|
660 |
implements LocaleServiceProviderPool.LocalizedObjectGetter<CurrencyNameProvider, |
|
661 |
String> { |
|
662 |
private static final CurrencyNameGetter INSTANCE = new CurrencyNameGetter(); |
|
663 |
||
13583 | 664 |
@Override |
2 | 665 |
public String getObject(CurrencyNameProvider currencyNameProvider, |
666 |
Locale locale, |
|
667 |
String key, |
|
668 |
Object... params) { |
|
669 |
assert params.length == 1; |
|
670 |
int type = (Integer)params[0]; |
|
671 |
||
672 |
switch(type) { |
|
673 |
case SYMBOL: |
|
674 |
return currencyNameProvider.getSymbol(key, locale); |
|
675 |
case DISPLAYNAME: |
|
676 |
return currencyNameProvider.getDisplayName(key, locale); |
|
677 |
default: |
|
678 |
assert false; // shouldn't happen |
|
679 |
} |
|
680 |
||
681 |
return null; |
|
682 |
} |
|
683 |
} |
|
684 |
||
685 |
private static int[] readIntArray(DataInputStream dis, int count) throws IOException { |
|
686 |
int[] ret = new int[count]; |
|
687 |
for (int i = 0; i < count; i++) { |
|
688 |
ret[i] = dis.readInt(); |
|
689 |
} |
|
690 |
||
691 |
return ret; |
|
692 |
} |
|
693 |
||
38440
9e77c5b81def
7102969: currency.properties supercede not working correctly
nishjain
parents:
37815
diff
changeset
|
694 |
private static List<SpecialCaseEntry> readSpecialCases(DataInputStream dis, |
9e77c5b81def
7102969: currency.properties supercede not working correctly
nishjain
parents:
37815
diff
changeset
|
695 |
int count) |
9e77c5b81def
7102969: currency.properties supercede not working correctly
nishjain
parents:
37815
diff
changeset
|
696 |
throws IOException { |
9e77c5b81def
7102969: currency.properties supercede not working correctly
nishjain
parents:
37815
diff
changeset
|
697 |
|
9e77c5b81def
7102969: currency.properties supercede not working correctly
nishjain
parents:
37815
diff
changeset
|
698 |
List<SpecialCaseEntry> list = new ArrayList<>(count); |
9e77c5b81def
7102969: currency.properties supercede not working correctly
nishjain
parents:
37815
diff
changeset
|
699 |
long cutOverTime; |
9e77c5b81def
7102969: currency.properties supercede not working correctly
nishjain
parents:
37815
diff
changeset
|
700 |
String oldCurrency; |
9e77c5b81def
7102969: currency.properties supercede not working correctly
nishjain
parents:
37815
diff
changeset
|
701 |
String newCurrency; |
9e77c5b81def
7102969: currency.properties supercede not working correctly
nishjain
parents:
37815
diff
changeset
|
702 |
int oldCurrencyFraction; |
9e77c5b81def
7102969: currency.properties supercede not working correctly
nishjain
parents:
37815
diff
changeset
|
703 |
int newCurrencyFraction; |
9e77c5b81def
7102969: currency.properties supercede not working correctly
nishjain
parents:
37815
diff
changeset
|
704 |
int oldCurrencyNumericCode; |
9e77c5b81def
7102969: currency.properties supercede not working correctly
nishjain
parents:
37815
diff
changeset
|
705 |
int newCurrencyNumericCode; |
9e77c5b81def
7102969: currency.properties supercede not working correctly
nishjain
parents:
37815
diff
changeset
|
706 |
|
2 | 707 |
for (int i = 0; i < count; i++) { |
38440
9e77c5b81def
7102969: currency.properties supercede not working correctly
nishjain
parents:
37815
diff
changeset
|
708 |
cutOverTime = dis.readLong(); |
9e77c5b81def
7102969: currency.properties supercede not working correctly
nishjain
parents:
37815
diff
changeset
|
709 |
oldCurrency = dis.readUTF(); |
9e77c5b81def
7102969: currency.properties supercede not working correctly
nishjain
parents:
37815
diff
changeset
|
710 |
newCurrency = dis.readUTF(); |
9e77c5b81def
7102969: currency.properties supercede not working correctly
nishjain
parents:
37815
diff
changeset
|
711 |
oldCurrencyFraction = dis.readInt(); |
9e77c5b81def
7102969: currency.properties supercede not working correctly
nishjain
parents:
37815
diff
changeset
|
712 |
newCurrencyFraction = dis.readInt(); |
9e77c5b81def
7102969: currency.properties supercede not working correctly
nishjain
parents:
37815
diff
changeset
|
713 |
oldCurrencyNumericCode = dis.readInt(); |
9e77c5b81def
7102969: currency.properties supercede not working correctly
nishjain
parents:
37815
diff
changeset
|
714 |
newCurrencyNumericCode = dis.readInt(); |
9e77c5b81def
7102969: currency.properties supercede not working correctly
nishjain
parents:
37815
diff
changeset
|
715 |
SpecialCaseEntry sc = new SpecialCaseEntry(cutOverTime, |
9e77c5b81def
7102969: currency.properties supercede not working correctly
nishjain
parents:
37815
diff
changeset
|
716 |
oldCurrency, newCurrency, |
9e77c5b81def
7102969: currency.properties supercede not working correctly
nishjain
parents:
37815
diff
changeset
|
717 |
oldCurrencyFraction, newCurrencyFraction, |
9e77c5b81def
7102969: currency.properties supercede not working correctly
nishjain
parents:
37815
diff
changeset
|
718 |
oldCurrencyNumericCode, newCurrencyNumericCode); |
9e77c5b81def
7102969: currency.properties supercede not working correctly
nishjain
parents:
37815
diff
changeset
|
719 |
list.add(sc); |
2 | 720 |
} |
38440
9e77c5b81def
7102969: currency.properties supercede not working correctly
nishjain
parents:
37815
diff
changeset
|
721 |
return list; |
2 | 722 |
} |
723 |
||
38440
9e77c5b81def
7102969: currency.properties supercede not working correctly
nishjain
parents:
37815
diff
changeset
|
724 |
private static List<OtherCurrencyEntry> readOtherCurrencies(DataInputStream dis, |
9e77c5b81def
7102969: currency.properties supercede not working correctly
nishjain
parents:
37815
diff
changeset
|
725 |
int count) |
9e77c5b81def
7102969: currency.properties supercede not working correctly
nishjain
parents:
37815
diff
changeset
|
726 |
throws IOException { |
9e77c5b81def
7102969: currency.properties supercede not working correctly
nishjain
parents:
37815
diff
changeset
|
727 |
|
9e77c5b81def
7102969: currency.properties supercede not working correctly
nishjain
parents:
37815
diff
changeset
|
728 |
List<OtherCurrencyEntry> list = new ArrayList<>(count); |
9e77c5b81def
7102969: currency.properties supercede not working correctly
nishjain
parents:
37815
diff
changeset
|
729 |
String currencyCode; |
9e77c5b81def
7102969: currency.properties supercede not working correctly
nishjain
parents:
37815
diff
changeset
|
730 |
int fraction; |
9e77c5b81def
7102969: currency.properties supercede not working correctly
nishjain
parents:
37815
diff
changeset
|
731 |
int numericCode; |
9e77c5b81def
7102969: currency.properties supercede not working correctly
nishjain
parents:
37815
diff
changeset
|
732 |
|
2 | 733 |
for (int i = 0; i < count; i++) { |
38440
9e77c5b81def
7102969: currency.properties supercede not working correctly
nishjain
parents:
37815
diff
changeset
|
734 |
currencyCode = dis.readUTF(); |
9e77c5b81def
7102969: currency.properties supercede not working correctly
nishjain
parents:
37815
diff
changeset
|
735 |
fraction = dis.readInt(); |
9e77c5b81def
7102969: currency.properties supercede not working correctly
nishjain
parents:
37815
diff
changeset
|
736 |
numericCode = dis.readInt(); |
9e77c5b81def
7102969: currency.properties supercede not working correctly
nishjain
parents:
37815
diff
changeset
|
737 |
OtherCurrencyEntry oc = new OtherCurrencyEntry(currencyCode, |
9e77c5b81def
7102969: currency.properties supercede not working correctly
nishjain
parents:
37815
diff
changeset
|
738 |
fraction, |
9e77c5b81def
7102969: currency.properties supercede not working correctly
nishjain
parents:
37815
diff
changeset
|
739 |
numericCode); |
9e77c5b81def
7102969: currency.properties supercede not working correctly
nishjain
parents:
37815
diff
changeset
|
740 |
list.add(oc); |
2 | 741 |
} |
38440
9e77c5b81def
7102969: currency.properties supercede not working correctly
nishjain
parents:
37815
diff
changeset
|
742 |
return list; |
2 | 743 |
} |
744 |
||
745 |
/** |
|
746 |
* Replaces currency data found in the currencydata.properties file |
|
747 |
* |
|
748 |
* @param pattern regex pattern for the properties |
|
749 |
* @param ctry country code |
|
14014 | 750 |
* @param curdata currency data. This is a comma separated string that |
2 | 751 |
* consists of "three-letter alphabet code", "three-digit numeric code", |
29524
2dbceeab4b8b
8074350: Support ISO 4217 "Current funds codes" table (A.2)
naoto
parents:
27565
diff
changeset
|
752 |
* and "one-digit (0-9) default fraction digit". |
2 | 753 |
* For example, "JPZ,392,0". |
13790
5b29e3921008
7180362: RFE: Implement date cutover functionality for currency.properties file
coffeys
parents:
13583
diff
changeset
|
754 |
* An optional UTC date can be appended to the string (comma separated) |
5b29e3921008
7180362: RFE: Implement date cutover functionality for currency.properties file
coffeys
parents:
13583
diff
changeset
|
755 |
* to allow a currency change take effect after date specified. |
5b29e3921008
7180362: RFE: Implement date cutover functionality for currency.properties file
coffeys
parents:
13583
diff
changeset
|
756 |
* For example, "JP=JPZ,999,0,2014-01-01T00:00:00" has no effect unless |
5b29e3921008
7180362: RFE: Implement date cutover functionality for currency.properties file
coffeys
parents:
13583
diff
changeset
|
757 |
* UTC time is past 1st January 2014 00:00:00 GMT. |
2 | 758 |
*/ |
759 |
private static void replaceCurrencyData(Pattern pattern, String ctry, String curdata) { |
|
760 |
||
761 |
if (ctry.length() != 2) { |
|
762 |
// ignore invalid country code |
|
13790
5b29e3921008
7180362: RFE: Implement date cutover functionality for currency.properties file
coffeys
parents:
13583
diff
changeset
|
763 |
info("currency.properties entry for " + ctry + |
5b29e3921008
7180362: RFE: Implement date cutover functionality for currency.properties file
coffeys
parents:
13583
diff
changeset
|
764 |
" is ignored because of the invalid country code.", null); |
2 | 765 |
return; |
766 |
} |
|
767 |
||
768 |
Matcher m = pattern.matcher(curdata); |
|
13790
5b29e3921008
7180362: RFE: Implement date cutover functionality for currency.properties file
coffeys
parents:
13583
diff
changeset
|
769 |
if (!m.find() || (m.group(4) == null && countOccurrences(curdata, ',') >= 3)) { |
2 | 770 |
// format is not recognized. ignore the data |
13790
5b29e3921008
7180362: RFE: Implement date cutover functionality for currency.properties file
coffeys
parents:
13583
diff
changeset
|
771 |
// if group(4) date string is null and we've 4 values, bad date value |
5b29e3921008
7180362: RFE: Implement date cutover functionality for currency.properties file
coffeys
parents:
13583
diff
changeset
|
772 |
info("currency.properties entry for " + ctry + |
5b29e3921008
7180362: RFE: Implement date cutover functionality for currency.properties file
coffeys
parents:
13583
diff
changeset
|
773 |
" ignored because the value format is not recognized.", null); |
5b29e3921008
7180362: RFE: Implement date cutover functionality for currency.properties file
coffeys
parents:
13583
diff
changeset
|
774 |
return; |
5b29e3921008
7180362: RFE: Implement date cutover functionality for currency.properties file
coffeys
parents:
13583
diff
changeset
|
775 |
} |
5b29e3921008
7180362: RFE: Implement date cutover functionality for currency.properties file
coffeys
parents:
13583
diff
changeset
|
776 |
|
5b29e3921008
7180362: RFE: Implement date cutover functionality for currency.properties file
coffeys
parents:
13583
diff
changeset
|
777 |
try { |
5b29e3921008
7180362: RFE: Implement date cutover functionality for currency.properties file
coffeys
parents:
13583
diff
changeset
|
778 |
if (m.group(4) != null && !isPastCutoverDate(m.group(4))) { |
5b29e3921008
7180362: RFE: Implement date cutover functionality for currency.properties file
coffeys
parents:
13583
diff
changeset
|
779 |
info("currency.properties entry for " + ctry + |
5b29e3921008
7180362: RFE: Implement date cutover functionality for currency.properties file
coffeys
parents:
13583
diff
changeset
|
780 |
" ignored since cutover date has not passed :" + curdata, null); |
5b29e3921008
7180362: RFE: Implement date cutover functionality for currency.properties file
coffeys
parents:
13583
diff
changeset
|
781 |
return; |
5b29e3921008
7180362: RFE: Implement date cutover functionality for currency.properties file
coffeys
parents:
13583
diff
changeset
|
782 |
} |
16006
bab9013bc05e
7197187: Currency.isPastCutoverDate should be made more robust
coffeys
parents:
14697
diff
changeset
|
783 |
} catch (ParseException ex) { |
13790
5b29e3921008
7180362: RFE: Implement date cutover functionality for currency.properties file
coffeys
parents:
13583
diff
changeset
|
784 |
info("currency.properties entry for " + ctry + |
5b29e3921008
7180362: RFE: Implement date cutover functionality for currency.properties file
coffeys
parents:
13583
diff
changeset
|
785 |
" ignored since exception encountered :" + ex.getMessage(), null); |
2 | 786 |
return; |
787 |
} |
|
788 |
||
789 |
String code = m.group(1); |
|
790 |
int numeric = Integer.parseInt(m.group(2)); |
|
29524
2dbceeab4b8b
8074350: Support ISO 4217 "Current funds codes" table (A.2)
naoto
parents:
27565
diff
changeset
|
791 |
int entry = numeric << NUMERIC_CODE_SHIFT; |
2 | 792 |
int fraction = Integer.parseInt(m.group(3)); |
29524
2dbceeab4b8b
8074350: Support ISO 4217 "Current funds codes" table (A.2)
naoto
parents:
27565
diff
changeset
|
793 |
if (fraction > SIMPLE_CASE_COUNTRY_MAX_DEFAULT_DIGITS) { |
2dbceeab4b8b
8074350: Support ISO 4217 "Current funds codes" table (A.2)
naoto
parents:
27565
diff
changeset
|
794 |
info("currency.properties entry for " + ctry + |
2dbceeab4b8b
8074350: Support ISO 4217 "Current funds codes" table (A.2)
naoto
parents:
27565
diff
changeset
|
795 |
" ignored since the fraction is more than " + |
2dbceeab4b8b
8074350: Support ISO 4217 "Current funds codes" table (A.2)
naoto
parents:
27565
diff
changeset
|
796 |
SIMPLE_CASE_COUNTRY_MAX_DEFAULT_DIGITS + ":" + curdata, null); |
2dbceeab4b8b
8074350: Support ISO 4217 "Current funds codes" table (A.2)
naoto
parents:
27565
diff
changeset
|
797 |
return; |
2dbceeab4b8b
8074350: Support ISO 4217 "Current funds codes" table (A.2)
naoto
parents:
27565
diff
changeset
|
798 |
} |
2 | 799 |
|
38440
9e77c5b81def
7102969: currency.properties supercede not working correctly
nishjain
parents:
37815
diff
changeset
|
800 |
int index = SpecialCaseEntry.indexOf(code, fraction, numeric); |
9e77c5b81def
7102969: currency.properties supercede not working correctly
nishjain
parents:
37815
diff
changeset
|
801 |
|
9e77c5b81def
7102969: currency.properties supercede not working correctly
nishjain
parents:
37815
diff
changeset
|
802 |
/* if a country switches from simple case to special case or |
9e77c5b81def
7102969: currency.properties supercede not working correctly
nishjain
parents:
37815
diff
changeset
|
803 |
* one special case to other special case which is not present |
9e77c5b81def
7102969: currency.properties supercede not working correctly
nishjain
parents:
37815
diff
changeset
|
804 |
* in the sc arrays then insert the new entry in special case arrays |
9e77c5b81def
7102969: currency.properties supercede not working correctly
nishjain
parents:
37815
diff
changeset
|
805 |
*/ |
9e77c5b81def
7102969: currency.properties supercede not working correctly
nishjain
parents:
37815
diff
changeset
|
806 |
if (index == -1 && (ctry.charAt(0) != code.charAt(0) |
9e77c5b81def
7102969: currency.properties supercede not working correctly
nishjain
parents:
37815
diff
changeset
|
807 |
|| ctry.charAt(1) != code.charAt(1))) { |
9e77c5b81def
7102969: currency.properties supercede not working correctly
nishjain
parents:
37815
diff
changeset
|
808 |
|
9e77c5b81def
7102969: currency.properties supercede not working correctly
nishjain
parents:
37815
diff
changeset
|
809 |
specialCasesList.add(new SpecialCaseEntry(code, fraction, numeric)); |
9e77c5b81def
7102969: currency.properties supercede not working correctly
nishjain
parents:
37815
diff
changeset
|
810 |
index = specialCasesList.size() - 1; |
2 | 811 |
} |
812 |
||
38440
9e77c5b81def
7102969: currency.properties supercede not working correctly
nishjain
parents:
37815
diff
changeset
|
813 |
if (index == -1) { |
2 | 814 |
// simple case |
38440
9e77c5b81def
7102969: currency.properties supercede not working correctly
nishjain
parents:
37815
diff
changeset
|
815 |
entry |= (fraction << SIMPLE_CASE_COUNTRY_DEFAULT_DIGITS_SHIFT) |
9e77c5b81def
7102969: currency.properties supercede not working correctly
nishjain
parents:
37815
diff
changeset
|
816 |
| (code.charAt(2) - 'A'); |
2 | 817 |
} else { |
818 |
// special case |
|
38440
9e77c5b81def
7102969: currency.properties supercede not working correctly
nishjain
parents:
37815
diff
changeset
|
819 |
entry = SPECIAL_CASE_COUNTRY_MASK |
9e77c5b81def
7102969: currency.properties supercede not working correctly
nishjain
parents:
37815
diff
changeset
|
820 |
| (index + SPECIAL_CASE_COUNTRY_INDEX_DELTA); |
2 | 821 |
} |
822 |
setMainTableEntry(ctry.charAt(0), ctry.charAt(1), entry); |
|
823 |
} |
|
824 |
||
16006
bab9013bc05e
7197187: Currency.isPastCutoverDate should be made more robust
coffeys
parents:
14697
diff
changeset
|
825 |
private static boolean isPastCutoverDate(String s) throws ParseException { |
13790
5b29e3921008
7180362: RFE: Implement date cutover functionality for currency.properties file
coffeys
parents:
13583
diff
changeset
|
826 |
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss", Locale.ROOT); |
5b29e3921008
7180362: RFE: Implement date cutover functionality for currency.properties file
coffeys
parents:
13583
diff
changeset
|
827 |
format.setTimeZone(TimeZone.getTimeZone("UTC")); |
5b29e3921008
7180362: RFE: Implement date cutover functionality for currency.properties file
coffeys
parents:
13583
diff
changeset
|
828 |
format.setLenient(false); |
5b29e3921008
7180362: RFE: Implement date cutover functionality for currency.properties file
coffeys
parents:
13583
diff
changeset
|
829 |
long time = format.parse(s.trim()).getTime(); |
5b29e3921008
7180362: RFE: Implement date cutover functionality for currency.properties file
coffeys
parents:
13583
diff
changeset
|
830 |
return System.currentTimeMillis() > time; |
5b29e3921008
7180362: RFE: Implement date cutover functionality for currency.properties file
coffeys
parents:
13583
diff
changeset
|
831 |
|
5b29e3921008
7180362: RFE: Implement date cutover functionality for currency.properties file
coffeys
parents:
13583
diff
changeset
|
832 |
} |
5b29e3921008
7180362: RFE: Implement date cutover functionality for currency.properties file
coffeys
parents:
13583
diff
changeset
|
833 |
|
5b29e3921008
7180362: RFE: Implement date cutover functionality for currency.properties file
coffeys
parents:
13583
diff
changeset
|
834 |
private static int countOccurrences(String value, char match) { |
5b29e3921008
7180362: RFE: Implement date cutover functionality for currency.properties file
coffeys
parents:
13583
diff
changeset
|
835 |
int count = 0; |
5b29e3921008
7180362: RFE: Implement date cutover functionality for currency.properties file
coffeys
parents:
13583
diff
changeset
|
836 |
for (char c : value.toCharArray()) { |
5b29e3921008
7180362: RFE: Implement date cutover functionality for currency.properties file
coffeys
parents:
13583
diff
changeset
|
837 |
if (c == match) { |
5b29e3921008
7180362: RFE: Implement date cutover functionality for currency.properties file
coffeys
parents:
13583
diff
changeset
|
838 |
++count; |
5b29e3921008
7180362: RFE: Implement date cutover functionality for currency.properties file
coffeys
parents:
13583
diff
changeset
|
839 |
} |
5b29e3921008
7180362: RFE: Implement date cutover functionality for currency.properties file
coffeys
parents:
13583
diff
changeset
|
840 |
} |
5b29e3921008
7180362: RFE: Implement date cutover functionality for currency.properties file
coffeys
parents:
13583
diff
changeset
|
841 |
return count; |
5b29e3921008
7180362: RFE: Implement date cutover functionality for currency.properties file
coffeys
parents:
13583
diff
changeset
|
842 |
} |
5b29e3921008
7180362: RFE: Implement date cutover functionality for currency.properties file
coffeys
parents:
13583
diff
changeset
|
843 |
|
3861
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
2
diff
changeset
|
844 |
private static void info(String message, Throwable t) { |
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
2
diff
changeset
|
845 |
PlatformLogger logger = PlatformLogger.getLogger("java.util.Currency"); |
18178
ee71c923891d
8016747: Replace deprecated PlatformLogger isLoggable(int) with isLoggable(Level)
chegar
parents:
17156
diff
changeset
|
846 |
if (logger.isLoggable(PlatformLogger.Level.INFO)) { |
2 | 847 |
if (t != null) { |
3861
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
2
diff
changeset
|
848 |
logger.info(message, t); |
2 | 849 |
} else { |
3861
a98a057ec335
6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents:
2
diff
changeset
|
850 |
logger.info(message); |
2 | 851 |
} |
852 |
} |
|
853 |
} |
|
38440
9e77c5b81def
7102969: currency.properties supercede not working correctly
nishjain
parents:
37815
diff
changeset
|
854 |
|
9e77c5b81def
7102969: currency.properties supercede not working correctly
nishjain
parents:
37815
diff
changeset
|
855 |
/* Used to represent a special case currency entry |
9e77c5b81def
7102969: currency.properties supercede not working correctly
nishjain
parents:
37815
diff
changeset
|
856 |
* - cutOverTime: cut-over time in millis as returned by |
9e77c5b81def
7102969: currency.properties supercede not working correctly
nishjain
parents:
37815
diff
changeset
|
857 |
* System.currentTimeMillis for special case countries that are changing |
9e77c5b81def
7102969: currency.properties supercede not working correctly
nishjain
parents:
37815
diff
changeset
|
858 |
* currencies; Long.MAX_VALUE for countries that are not changing currencies |
9e77c5b81def
7102969: currency.properties supercede not working correctly
nishjain
parents:
37815
diff
changeset
|
859 |
* - oldCurrency: old currencies for special case countries |
9e77c5b81def
7102969: currency.properties supercede not working correctly
nishjain
parents:
37815
diff
changeset
|
860 |
* - newCurrency: new currencies for special case countries that are |
9e77c5b81def
7102969: currency.properties supercede not working correctly
nishjain
parents:
37815
diff
changeset
|
861 |
* changing currencies; null for others |
9e77c5b81def
7102969: currency.properties supercede not working correctly
nishjain
parents:
37815
diff
changeset
|
862 |
* - oldCurrencyFraction: default fraction digits for old currencies |
9e77c5b81def
7102969: currency.properties supercede not working correctly
nishjain
parents:
37815
diff
changeset
|
863 |
* - newCurrencyFraction: default fraction digits for new currencies, 0 for |
9e77c5b81def
7102969: currency.properties supercede not working correctly
nishjain
parents:
37815
diff
changeset
|
864 |
* countries that are not changing currencies |
9e77c5b81def
7102969: currency.properties supercede not working correctly
nishjain
parents:
37815
diff
changeset
|
865 |
* - oldCurrencyNumericCode: numeric code for old currencies |
9e77c5b81def
7102969: currency.properties supercede not working correctly
nishjain
parents:
37815
diff
changeset
|
866 |
* - newCurrencyNumericCode: numeric code for new currencies, 0 for countries |
9e77c5b81def
7102969: currency.properties supercede not working correctly
nishjain
parents:
37815
diff
changeset
|
867 |
* that are not changing currencies |
9e77c5b81def
7102969: currency.properties supercede not working correctly
nishjain
parents:
37815
diff
changeset
|
868 |
*/ |
9e77c5b81def
7102969: currency.properties supercede not working correctly
nishjain
parents:
37815
diff
changeset
|
869 |
private static class SpecialCaseEntry { |
9e77c5b81def
7102969: currency.properties supercede not working correctly
nishjain
parents:
37815
diff
changeset
|
870 |
|
9e77c5b81def
7102969: currency.properties supercede not working correctly
nishjain
parents:
37815
diff
changeset
|
871 |
final private long cutOverTime; |
9e77c5b81def
7102969: currency.properties supercede not working correctly
nishjain
parents:
37815
diff
changeset
|
872 |
final private String oldCurrency; |
9e77c5b81def
7102969: currency.properties supercede not working correctly
nishjain
parents:
37815
diff
changeset
|
873 |
final private String newCurrency; |
9e77c5b81def
7102969: currency.properties supercede not working correctly
nishjain
parents:
37815
diff
changeset
|
874 |
final private int oldCurrencyFraction; |
9e77c5b81def
7102969: currency.properties supercede not working correctly
nishjain
parents:
37815
diff
changeset
|
875 |
final private int newCurrencyFraction; |
9e77c5b81def
7102969: currency.properties supercede not working correctly
nishjain
parents:
37815
diff
changeset
|
876 |
final private int oldCurrencyNumericCode; |
9e77c5b81def
7102969: currency.properties supercede not working correctly
nishjain
parents:
37815
diff
changeset
|
877 |
final private int newCurrencyNumericCode; |
9e77c5b81def
7102969: currency.properties supercede not working correctly
nishjain
parents:
37815
diff
changeset
|
878 |
|
9e77c5b81def
7102969: currency.properties supercede not working correctly
nishjain
parents:
37815
diff
changeset
|
879 |
private SpecialCaseEntry(long cutOverTime, String oldCurrency, String newCurrency, |
9e77c5b81def
7102969: currency.properties supercede not working correctly
nishjain
parents:
37815
diff
changeset
|
880 |
int oldCurrencyFraction, int newCurrencyFraction, |
9e77c5b81def
7102969: currency.properties supercede not working correctly
nishjain
parents:
37815
diff
changeset
|
881 |
int oldCurrencyNumericCode, int newCurrencyNumericCode) { |
9e77c5b81def
7102969: currency.properties supercede not working correctly
nishjain
parents:
37815
diff
changeset
|
882 |
this.cutOverTime = cutOverTime; |
9e77c5b81def
7102969: currency.properties supercede not working correctly
nishjain
parents:
37815
diff
changeset
|
883 |
this.oldCurrency = oldCurrency; |
9e77c5b81def
7102969: currency.properties supercede not working correctly
nishjain
parents:
37815
diff
changeset
|
884 |
this.newCurrency = newCurrency; |
9e77c5b81def
7102969: currency.properties supercede not working correctly
nishjain
parents:
37815
diff
changeset
|
885 |
this.oldCurrencyFraction = oldCurrencyFraction; |
9e77c5b81def
7102969: currency.properties supercede not working correctly
nishjain
parents:
37815
diff
changeset
|
886 |
this.newCurrencyFraction = newCurrencyFraction; |
9e77c5b81def
7102969: currency.properties supercede not working correctly
nishjain
parents:
37815
diff
changeset
|
887 |
this.oldCurrencyNumericCode = oldCurrencyNumericCode; |
9e77c5b81def
7102969: currency.properties supercede not working correctly
nishjain
parents:
37815
diff
changeset
|
888 |
this.newCurrencyNumericCode = newCurrencyNumericCode; |
9e77c5b81def
7102969: currency.properties supercede not working correctly
nishjain
parents:
37815
diff
changeset
|
889 |
} |
9e77c5b81def
7102969: currency.properties supercede not working correctly
nishjain
parents:
37815
diff
changeset
|
890 |
|
9e77c5b81def
7102969: currency.properties supercede not working correctly
nishjain
parents:
37815
diff
changeset
|
891 |
private SpecialCaseEntry(String currencyCode, int fraction, |
9e77c5b81def
7102969: currency.properties supercede not working correctly
nishjain
parents:
37815
diff
changeset
|
892 |
int numericCode) { |
9e77c5b81def
7102969: currency.properties supercede not working correctly
nishjain
parents:
37815
diff
changeset
|
893 |
this(Long.MAX_VALUE, currencyCode, "", fraction, 0, numericCode, 0); |
9e77c5b81def
7102969: currency.properties supercede not working correctly
nishjain
parents:
37815
diff
changeset
|
894 |
} |
9e77c5b81def
7102969: currency.properties supercede not working correctly
nishjain
parents:
37815
diff
changeset
|
895 |
|
9e77c5b81def
7102969: currency.properties supercede not working correctly
nishjain
parents:
37815
diff
changeset
|
896 |
//get the index of the special case entry |
9e77c5b81def
7102969: currency.properties supercede not working correctly
nishjain
parents:
37815
diff
changeset
|
897 |
private static int indexOf(String code, int fraction, int numeric) { |
9e77c5b81def
7102969: currency.properties supercede not working correctly
nishjain
parents:
37815
diff
changeset
|
898 |
int size = specialCasesList.size(); |
9e77c5b81def
7102969: currency.properties supercede not working correctly
nishjain
parents:
37815
diff
changeset
|
899 |
for (int index = 0; index < size; index++) { |
9e77c5b81def
7102969: currency.properties supercede not working correctly
nishjain
parents:
37815
diff
changeset
|
900 |
SpecialCaseEntry scEntry = specialCasesList.get(index); |
9e77c5b81def
7102969: currency.properties supercede not working correctly
nishjain
parents:
37815
diff
changeset
|
901 |
if (scEntry.oldCurrency.equals(code) |
9e77c5b81def
7102969: currency.properties supercede not working correctly
nishjain
parents:
37815
diff
changeset
|
902 |
&& scEntry.oldCurrencyFraction == fraction |
9e77c5b81def
7102969: currency.properties supercede not working correctly
nishjain
parents:
37815
diff
changeset
|
903 |
&& scEntry.oldCurrencyNumericCode == numeric |
9e77c5b81def
7102969: currency.properties supercede not working correctly
nishjain
parents:
37815
diff
changeset
|
904 |
&& scEntry.cutOverTime == Long.MAX_VALUE) { |
9e77c5b81def
7102969: currency.properties supercede not working correctly
nishjain
parents:
37815
diff
changeset
|
905 |
return index; |
9e77c5b81def
7102969: currency.properties supercede not working correctly
nishjain
parents:
37815
diff
changeset
|
906 |
} |
9e77c5b81def
7102969: currency.properties supercede not working correctly
nishjain
parents:
37815
diff
changeset
|
907 |
} |
9e77c5b81def
7102969: currency.properties supercede not working correctly
nishjain
parents:
37815
diff
changeset
|
908 |
return -1; |
9e77c5b81def
7102969: currency.properties supercede not working correctly
nishjain
parents:
37815
diff
changeset
|
909 |
} |
9e77c5b81def
7102969: currency.properties supercede not working correctly
nishjain
parents:
37815
diff
changeset
|
910 |
|
9e77c5b81def
7102969: currency.properties supercede not working correctly
nishjain
parents:
37815
diff
changeset
|
911 |
// get the fraction and numericCode of the sc currencycode |
9e77c5b81def
7102969: currency.properties supercede not working correctly
nishjain
parents:
37815
diff
changeset
|
912 |
private static int[] findEntry(String code) { |
9e77c5b81def
7102969: currency.properties supercede not working correctly
nishjain
parents:
37815
diff
changeset
|
913 |
int[] fractionAndNumericCode = null; |
9e77c5b81def
7102969: currency.properties supercede not working correctly
nishjain
parents:
37815
diff
changeset
|
914 |
int size = specialCasesList.size(); |
9e77c5b81def
7102969: currency.properties supercede not working correctly
nishjain
parents:
37815
diff
changeset
|
915 |
for (int index = 0; index < size; index++) { |
9e77c5b81def
7102969: currency.properties supercede not working correctly
nishjain
parents:
37815
diff
changeset
|
916 |
SpecialCaseEntry scEntry = specialCasesList.get(index); |
9e77c5b81def
7102969: currency.properties supercede not working correctly
nishjain
parents:
37815
diff
changeset
|
917 |
if (scEntry.oldCurrency.equals(code) && (scEntry.cutOverTime == Long.MAX_VALUE |
9e77c5b81def
7102969: currency.properties supercede not working correctly
nishjain
parents:
37815
diff
changeset
|
918 |
|| System.currentTimeMillis() < scEntry.cutOverTime)) { |
9e77c5b81def
7102969: currency.properties supercede not working correctly
nishjain
parents:
37815
diff
changeset
|
919 |
//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
|
920 |
fractionAndNumericCode = new int[2]; |
9e77c5b81def
7102969: currency.properties supercede not working correctly
nishjain
parents:
37815
diff
changeset
|
921 |
fractionAndNumericCode[0] = scEntry.oldCurrencyFraction; |
9e77c5b81def
7102969: currency.properties supercede not working correctly
nishjain
parents:
37815
diff
changeset
|
922 |
fractionAndNumericCode[1] = scEntry.oldCurrencyNumericCode; |
9e77c5b81def
7102969: currency.properties supercede not working correctly
nishjain
parents:
37815
diff
changeset
|
923 |
break; |
9e77c5b81def
7102969: currency.properties supercede not working correctly
nishjain
parents:
37815
diff
changeset
|
924 |
} else if (scEntry.newCurrency.equals(code) |
9e77c5b81def
7102969: currency.properties supercede not working correctly
nishjain
parents:
37815
diff
changeset
|
925 |
&& System.currentTimeMillis() >= scEntry.cutOverTime) { |
9e77c5b81def
7102969: currency.properties supercede not working correctly
nishjain
parents:
37815
diff
changeset
|
926 |
//consider only if the cutover time is passed |
9e77c5b81def
7102969: currency.properties supercede not working correctly
nishjain
parents:
37815
diff
changeset
|
927 |
fractionAndNumericCode = new int[2]; |
9e77c5b81def
7102969: currency.properties supercede not working correctly
nishjain
parents:
37815
diff
changeset
|
928 |
fractionAndNumericCode[0] = scEntry.newCurrencyFraction; |
9e77c5b81def
7102969: currency.properties supercede not working correctly
nishjain
parents:
37815
diff
changeset
|
929 |
fractionAndNumericCode[1] = scEntry.newCurrencyNumericCode; |
9e77c5b81def
7102969: currency.properties supercede not working correctly
nishjain
parents:
37815
diff
changeset
|
930 |
break; |
9e77c5b81def
7102969: currency.properties supercede not working correctly
nishjain
parents:
37815
diff
changeset
|
931 |
} |
9e77c5b81def
7102969: currency.properties supercede not working correctly
nishjain
parents:
37815
diff
changeset
|
932 |
} |
9e77c5b81def
7102969: currency.properties supercede not working correctly
nishjain
parents:
37815
diff
changeset
|
933 |
return fractionAndNumericCode; |
9e77c5b81def
7102969: currency.properties supercede not working correctly
nishjain
parents:
37815
diff
changeset
|
934 |
} |
9e77c5b81def
7102969: currency.properties supercede not working correctly
nishjain
parents:
37815
diff
changeset
|
935 |
|
9e77c5b81def
7102969: currency.properties supercede not working correctly
nishjain
parents:
37815
diff
changeset
|
936 |
// convert the special case entry to sc arrays index |
9e77c5b81def
7102969: currency.properties supercede not working correctly
nishjain
parents:
37815
diff
changeset
|
937 |
private static int toIndex(int tableEntry) { |
9e77c5b81def
7102969: currency.properties supercede not working correctly
nishjain
parents:
37815
diff
changeset
|
938 |
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
|
939 |
} |
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 |
} |
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 |
/* Used to represent Other currencies |
9e77c5b81def
7102969: currency.properties supercede not working correctly
nishjain
parents:
37815
diff
changeset
|
944 |
* - currencyCode: currency codes that are not the main currency |
9e77c5b81def
7102969: currency.properties supercede not working correctly
nishjain
parents:
37815
diff
changeset
|
945 |
* of a simple country |
9e77c5b81def
7102969: currency.properties supercede not working correctly
nishjain
parents:
37815
diff
changeset
|
946 |
* - otherCurrenciesDFD: decimal format digits for other currencies |
9e77c5b81def
7102969: currency.properties supercede not working correctly
nishjain
parents:
37815
diff
changeset
|
947 |
* - otherCurrenciesNumericCode: numeric code for other currencies |
9e77c5b81def
7102969: currency.properties supercede not working correctly
nishjain
parents:
37815
diff
changeset
|
948 |
*/ |
9e77c5b81def
7102969: currency.properties supercede not working correctly
nishjain
parents:
37815
diff
changeset
|
949 |
private static class OtherCurrencyEntry { |
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 |
final private String currencyCode; |
9e77c5b81def
7102969: currency.properties supercede not working correctly
nishjain
parents:
37815
diff
changeset
|
952 |
final private int fraction; |
9e77c5b81def
7102969: currency.properties supercede not working correctly
nishjain
parents:
37815
diff
changeset
|
953 |
final private int numericCode; |
9e77c5b81def
7102969: currency.properties supercede not working correctly
nishjain
parents:
37815
diff
changeset
|
954 |
|
9e77c5b81def
7102969: currency.properties supercede not working correctly
nishjain
parents:
37815
diff
changeset
|
955 |
private OtherCurrencyEntry(String currencyCode, int fraction, |
9e77c5b81def
7102969: currency.properties supercede not working correctly
nishjain
parents:
37815
diff
changeset
|
956 |
int numericCode) { |
9e77c5b81def
7102969: currency.properties supercede not working correctly
nishjain
parents:
37815
diff
changeset
|
957 |
this.currencyCode = currencyCode; |
9e77c5b81def
7102969: currency.properties supercede not working correctly
nishjain
parents:
37815
diff
changeset
|
958 |
this.fraction = fraction; |
9e77c5b81def
7102969: currency.properties supercede not working correctly
nishjain
parents:
37815
diff
changeset
|
959 |
this.numericCode = numericCode; |
9e77c5b81def
7102969: currency.properties supercede not working correctly
nishjain
parents:
37815
diff
changeset
|
960 |
} |
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 |
//get the instance of the other currency code |
9e77c5b81def
7102969: currency.properties supercede not working correctly
nishjain
parents:
37815
diff
changeset
|
963 |
private static OtherCurrencyEntry findEntry(String code) { |
9e77c5b81def
7102969: currency.properties supercede not working correctly
nishjain
parents:
37815
diff
changeset
|
964 |
int size = otherCurrenciesList.size(); |
9e77c5b81def
7102969: currency.properties supercede not working correctly
nishjain
parents:
37815
diff
changeset
|
965 |
for (int index = 0; index < size; index++) { |
9e77c5b81def
7102969: currency.properties supercede not working correctly
nishjain
parents:
37815
diff
changeset
|
966 |
OtherCurrencyEntry ocEntry = otherCurrenciesList.get(index); |
9e77c5b81def
7102969: currency.properties supercede not working correctly
nishjain
parents:
37815
diff
changeset
|
967 |
if (ocEntry.currencyCode.equalsIgnoreCase(code)) { |
9e77c5b81def
7102969: currency.properties supercede not working correctly
nishjain
parents:
37815
diff
changeset
|
968 |
return ocEntry; |
9e77c5b81def
7102969: currency.properties supercede not working correctly
nishjain
parents:
37815
diff
changeset
|
969 |
} |
9e77c5b81def
7102969: currency.properties supercede not working correctly
nishjain
parents:
37815
diff
changeset
|
970 |
} |
9e77c5b81def
7102969: currency.properties supercede not working correctly
nishjain
parents:
37815
diff
changeset
|
971 |
return null; |
9e77c5b81def
7102969: currency.properties supercede not working correctly
nishjain
parents:
37815
diff
changeset
|
972 |
} |
9e77c5b81def
7102969: currency.properties supercede not working correctly
nishjain
parents:
37815
diff
changeset
|
973 |
|
9e77c5b81def
7102969: currency.properties supercede not working correctly
nishjain
parents:
37815
diff
changeset
|
974 |
} |
9e77c5b81def
7102969: currency.properties supercede not working correctly
nishjain
parents:
37815
diff
changeset
|
975 |
|
2 | 976 |
} |
37815
0ecfe8f6500e
8154295: Currency iso code is int and hence looses the preceeding zero.
peytoia
parents:
36113
diff
changeset
|
977 |
|
38440
9e77c5b81def
7102969: currency.properties supercede not working correctly
nishjain
parents:
37815
diff
changeset
|
978 |