Currency.java
7.98 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
/*
* Decompiled with CFR 0_118.
*/
package com.adobe.agl.util;
import com.adobe.agl.impl.ICUDebug;
import com.adobe.agl.impl.ICUResourceBundle;
import com.adobe.agl.util.MeasureUnit;
import com.adobe.agl.util.ULocale;
import com.adobe.agl.util.UResourceBundle;
import java.io.Serializable;
import java.text.ChoiceFormat;
import java.text.ParsePosition;
import java.util.Locale;
import java.util.MissingResourceException;
public class Currency
extends MeasureUnit
implements Serializable {
private static final boolean DEBUG = ICUDebug.enabled("currency");
private String isoCode;
private static ServiceShim shim;
private static final int[] LAST_RESORT_DATA;
private static final int[] POW10;
public static Currency getInstance(ULocale locale) {
String currency = locale.getKeywordValue("currency");
if (currency != null) {
return Currency.getInstance(currency);
}
if (shim == null) {
return Currency.createCurrency(locale);
}
return shim.createInstance(locale);
}
static Currency createCurrency(ULocale loc) {
String country = loc.getCountry();
String variant = loc.getVariant();
boolean isPreEuro = variant.equals("PREEURO");
boolean isEuro = variant.equals("EURO");
ICUResourceBundle bundle = (ICUResourceBundle)ICUResourceBundle.getBundleInstance("com/adobe/agl/impl/data/icudt40b", "supplementalData", ICUResourceBundle.ICU_DATA_CLASS_LOADER);
if (bundle == null) {
return null;
}
try {
UResourceBundle cm = bundle.get("CurrencyMap");
String curriso = null;
UResourceBundle countryArray = cm.get(country);
UResourceBundle currencyReq = countryArray.get(0);
curriso = currencyReq.getString("id");
if (isPreEuro && curriso.equals("EUR")) {
currencyReq = countryArray.get(1);
curriso = currencyReq.getString("id");
} else if (isEuro) {
curriso = "EUR";
}
if (curriso != null) {
return new Currency(curriso);
}
}
catch (MissingResourceException ex) {
// empty catch block
}
return null;
}
public static Currency getInstance(String theISOCode) {
if (theISOCode == null) {
throw new NullPointerException("The input currency code is null.");
}
boolean is3alpha = true;
if (theISOCode.length() != 3) {
is3alpha = false;
} else {
for (int i = 0; i < 3; ++i) {
char ch = theISOCode.charAt(i);
if (ch >= 'A' && (ch <= 'Z' || ch >= 'a') && ch <= 'z') continue;
is3alpha = false;
break;
}
}
if (!is3alpha) {
throw new IllegalArgumentException("The input currency code is not 3-letter alphabetic code.");
}
return new Currency(theISOCode.toUpperCase(Locale.US));
}
public int hashCode() {
return this.isoCode.hashCode();
}
public boolean equals(Object rhs) {
if (rhs == null) {
return false;
}
if (rhs == this) {
return true;
}
try {
Currency c = (Currency)rhs;
return this.isoCode.equals(c.isoCode);
}
catch (ClassCastException e) {
return false;
}
}
public String getCurrencyCode() {
return this.isoCode;
}
public String getName(ULocale locale, int nameStyle, boolean[] isChoiceFormat) {
if (nameStyle < 0 || nameStyle > 1) {
throw new IllegalArgumentException();
}
String s = null;
try {
UResourceBundle rb = UResourceBundle.getBundleInstance("com/adobe/agl/impl/data/icudt40b", locale);
ICUResourceBundle currencies = (ICUResourceBundle)rb.get("Currencies");
s = currencies.getWithFallback(this.isoCode).getString(nameStyle);
}
catch (MissingResourceException e) {
// empty catch block
}
isChoiceFormat[0] = false;
if (s != null) {
int i;
for (i = 0; i < s.length() && s.charAt(i) == '=' && i < 2; ++i) {
}
boolean bl = isChoiceFormat[0] = i == 1;
if (i != 0) {
s = s.substring(1);
}
return s;
}
return this.isoCode;
}
public static String parse(ULocale locale, String text, ParsePosition pos) {
int start = pos.getIndex();
String fragment = text.substring(start);
String iso = null;
int max = 0;
while (locale != null) {
UResourceBundle rb = UResourceBundle.getBundleInstance("com/adobe/agl/impl/data/icudt40b", locale);
try {
UResourceBundle currencies = rb.get("Currencies");
for (int i = 0; i < currencies.getSize(); ++i) {
UResourceBundle item = currencies.get(i);
String name = item.getString(0);
if (name.length() < 1) continue;
if (name.charAt(0) == '=' && (name = name.substring(1)).length() > 0 && name.charAt(0) != '=') {
ChoiceFormat choice = new ChoiceFormat(name);
choice.parse(text, pos);
int len = pos.getIndex() - start;
if (len > max) {
iso = item.getKey();
max = len;
}
pos.setIndex(start);
continue;
}
if (name.length() <= max || !fragment.startsWith(name)) continue;
iso = item.getKey();
max = name.length();
}
}
catch (MissingResourceException e) {
// empty catch block
}
locale = locale.getFallback();
}
if (max < 3 && text.length() - start >= 3) {
boolean valid = true;
for (int k = 0; k < 3; ++k) {
char ch = text.charAt(start + k);
if (ch >= 'A' && ch <= 'Z') continue;
valid = false;
break;
}
if (valid) {
iso = text.substring(start, start + 3);
max = 3;
}
}
pos.setIndex(start + max);
return iso;
}
public int getDefaultFractionDigits() {
return this.findData()[0];
}
public double getRoundingIncrement() {
int[] data = this.findData();
int data1 = data[1];
if (data1 == 0) {
return 0.0;
}
int data0 = data[0];
if (data0 < 0 || data0 >= POW10.length) {
return 0.0;
}
return (double)data1 / (double)POW10[data0];
}
public String toString() {
return this.isoCode;
}
protected Currency(String theISOCode) {
this.isoCode = theISOCode;
}
private int[] findData() {
try {
UResourceBundle root = ICUResourceBundle.getBundleInstance("com/adobe/agl/impl/data/icudt40b", "supplementalData", ICUResourceBundle.ICU_DATA_CLASS_LOADER);
UResourceBundle currencyMeta = root.get("CurrencyMeta");
int[] i = currencyMeta.get(this.isoCode).getIntVector();
if (i == null) {
i = currencyMeta.get("DEFAULT").getIntVector();
}
if (i != null && i.length >= 2) {
return i;
}
}
catch (MissingResourceException e) {
// empty catch block
}
return LAST_RESORT_DATA;
}
static {
LAST_RESORT_DATA = new int[]{2, 0};
POW10 = new int[]{1, 10, 100, 1000, 10000, 100000, 1000000, 10000000, 100000000, 1000000000};
}
static abstract class ServiceShim {
abstract Currency createInstance(ULocale var1);
}
}