LEFT | RIGHT |
(no file at all) | |
1 // © 2017 and later: Unicode, Inc. and others. | 1 // © 2017 and later: Unicode, Inc. and others. |
2 // License & terms of use: http://www.unicode.org/copyright.html#License | 2 // License & terms of use: http://www.unicode.org/copyright.html#License |
3 package com.ibm.icu.impl.number; | 3 package com.ibm.icu.impl.number; |
4 | 4 |
5 import com.ibm.icu.text.DecimalFormatSymbols; | 5 import com.ibm.icu.text.DecimalFormatSymbols; |
6 import com.ibm.icu.util.Currency; | 6 import com.ibm.icu.util.Currency; |
7 import com.ibm.icu.util.ULocale; | 7 import com.ibm.icu.util.ULocale; |
8 | 8 |
9 public class CustomSymbolCurrency extends Currency { | 9 public class CustomSymbolCurrency extends Currency { |
10 private static final long serialVersionUID = 2497493016770137670L; | 10 private static final long serialVersionUID = 2497493016770137670L; |
11 // TODO: Serialization methods? | 11 // TODO: Serialization methods? |
12 | 12 |
13 private String symbol1; | 13 private String symbol1; |
14 private String symbol2; | 14 private String symbol2; |
15 | 15 |
16 public static Currency resolve(Currency currency, ULocale locale, DecimalForma
tSymbols symbols) { | 16 public static Currency resolve(Currency currency, ULocale locale, DecimalFor
matSymbols symbols) { |
17 if (currency == null) { | 17 if (currency == null) { |
18 currency = symbols.getCurrency(); | 18 currency = symbols.getCurrency(); |
| 19 } |
| 20 String currency1Sym = symbols.getCurrencySymbol(); |
| 21 String currency2Sym = symbols.getInternationalCurrencySymbol(); |
| 22 if (currency == null) { |
| 23 return new CustomSymbolCurrency("XXX", currency1Sym, currency2Sym); |
| 24 } |
| 25 if (!currency.equals(symbols.getCurrency())) { |
| 26 return currency; |
| 27 } |
| 28 String currency1 = currency.getName(symbols.getULocale(), Currency.SYMBO
L_NAME, null); |
| 29 String currency2 = currency.getCurrencyCode(); |
| 30 if (!currency1.equals(currency1Sym) || !currency2.equals(currency2Sym))
{ |
| 31 return new CustomSymbolCurrency(currency2, currency1Sym, currency2Sy
m); |
| 32 } |
| 33 return currency; |
19 } | 34 } |
20 String currency1Sym = symbols.getCurrencySymbol(); | 35 |
21 String currency2Sym = symbols.getInternationalCurrencySymbol(); | 36 public CustomSymbolCurrency(String isoCode, String currency1Sym, String curr
ency2Sym) { |
22 if (currency == null) { | 37 super(isoCode); |
23 return new CustomSymbolCurrency("XXX", currency1Sym, currency2Sym); | 38 this.symbol1 = currency1Sym; |
| 39 this.symbol2 = currency2Sym; |
24 } | 40 } |
25 if (!currency.equals(symbols.getCurrency())) { | 41 |
26 return currency; | 42 @Override |
| 43 public String getName(ULocale locale, int nameStyle, boolean[] isChoiceForma
t) { |
| 44 if (nameStyle == SYMBOL_NAME) { |
| 45 return symbol1; |
| 46 } |
| 47 return super.getName(locale, nameStyle, isChoiceFormat); |
27 } | 48 } |
28 String currency1 = currency.getName(symbols.getULocale(), Currency.SYMBOL_NA
ME, null); | 49 |
29 String currency2 = currency.getCurrencyCode(); | 50 @Override |
30 if (!currency1.equals(currency1Sym) || !currency2.equals(currency2Sym)) { | 51 public String getName(ULocale locale, int nameStyle, String pluralCount, boo
lean[] isChoiceFormat) { |
31 return new CustomSymbolCurrency(currency2, currency1Sym, currency2Sym); | 52 if (nameStyle == PLURAL_LONG_NAME && subType.equals("XXX")) { |
| 53 // Plural in absence of a currency should return the symbol |
| 54 return symbol1; |
| 55 } |
| 56 return super.getName(locale, nameStyle, pluralCount, isChoiceFormat); |
32 } | 57 } |
33 return currency; | |
34 } | |
35 | 58 |
36 public CustomSymbolCurrency(String isoCode, String currency1Sym, String curren
cy2Sym) { | 59 @Override |
37 super(isoCode); | 60 public String getCurrencyCode() { |
38 this.symbol1 = currency1Sym; | 61 return symbol2; |
39 this.symbol2 = currency2Sym; | 62 } |
40 } | |
41 | 63 |
42 @Override | 64 @Override |
43 public String getName(ULocale locale, int nameStyle, boolean[] isChoiceFormat)
{ | 65 public int hashCode() { |
44 if (nameStyle == SYMBOL_NAME) { | 66 return super.hashCode() ^ symbol1.hashCode() ^ symbol2.hashCode(); |
45 return symbol1; | |
46 } | 67 } |
47 return super.getName(locale, nameStyle, isChoiceFormat); | |
48 } | |
49 | 68 |
50 @Override | 69 @Override |
51 public String getName( | 70 public boolean equals(Object other) { |
52 ULocale locale, int nameStyle, String pluralCount, boolean[] isChoiceForma
t) { | 71 return super.equals(other) |
53 if (nameStyle == PLURAL_LONG_NAME && subType.equals("XXX")) { | 72 && ((CustomSymbolCurrency) other).symbol1.equals(symbol1) |
54 // Plural in absence of a currency should return the symbol | 73 && ((CustomSymbolCurrency) other).symbol2.equals(symbol2); |
55 return symbol1; | |
56 } | 74 } |
57 return super.getName(locale, nameStyle, pluralCount, isChoiceFormat); | |
58 } | |
59 | |
60 @Override | |
61 public String getCurrencyCode() { | |
62 return symbol2; | |
63 } | |
64 | |
65 @Override | |
66 public int hashCode() { | |
67 return super.hashCode() ^ symbol1.hashCode() ^ symbol2.hashCode(); | |
68 } | |
69 | |
70 @Override | |
71 public boolean equals(Object other) { | |
72 return super.equals(other) | |
73 && ((CustomSymbolCurrency)other).symbol1.equals(symbol1) | |
74 && ((CustomSymbolCurrency)other).symbol2.equals(symbol2); | |
75 } | |
76 } | 75 } |
LEFT | RIGHT |