* @stable ICU 4.2
*/
public static final int PLURAL_LONG_NAME = 2;
+
+ private static final EquivalenceRelation<String> EQUIVALENT_CURRENCY_SYMBOLS =
+ new EquivalenceRelation<String>()
+ .add("\u00a5", "\uffe5")
+ .add("$", "\ufe69", "\uff04")
+ .add("\u20a8", "\u20b9")
+ .add("\u00a3", "\u20a4");
// begin registry stuff
for (Map.Entry<String, String> e : names.symbolMap().entrySet()) {
String symbol = e.getKey();
String isoCode = e.getValue();
- symTrie.put(symbol, new CurrencyStringInfo(isoCode, symbol));
+ for (String equivalentSymbol : EQUIVALENT_CURRENCY_SYMBOLS.get(symbol)) {
+ symTrie.put(equivalentSymbol, new CurrencyStringInfo(isoCode, symbol));
+ }
}
for (Map.Entry<String, String> e : names.nameMap().entrySet()) {
String name = e.getKey();
CurrencyMetaInfo info = CurrencyMetaInfo.getInstance();
return info.currencies(filter.withTender());
}
+
+ private static final class EquivalenceRelation<T> {
+
+ private Map<T, Set<T>> data = new HashMap<T, Set<T>>();
+
+ public EquivalenceRelation<T> add(T... items) {
+ Set<T> group = new HashSet<T>();
+ for (T item : items) {
+ if (data.containsKey(item)) {
+ throw new IllegalArgumentException("All groups passed to add must be disjoint.");
+ }
+ group.add(item);
+ }
+ for (T item : items) {
+ data.put(item, group);
+ }
+ return this;
+ }
+
+ public Set<T> get(T item) {
+ Set<T> result = data.get(item);
+ if (result == null) {
+ return Collections.singleton(item);
+ }
+ return Collections.unmodifiableSet(result);
+ }
+ }
}
//eof
expectCurrency(fmt, Currency.getInstance(Locale.FRANCE),
1234.56, "1 234,56 \u20AC"); // Euro
}
+
+ public void TestCompatibleCurrencies() {
+ NumberFormat fmt =
+ NumberFormat.getCurrencyInstance(Locale.US);
+ expectParseCurrency(fmt, Currency.getInstance(Locale.JAPAN), "\u00A51,235"); // Yen half-width
+ expectParseCurrency(fmt, Currency.getInstance(Locale.JAPAN), "\uFFE51,235"); // Yen full-wdith
+ }
public void TestCurrencyPatterns() {
int i;
errln("FAIL \"" + pat + "\", expected \"" + exp + "\"");
}
}
+
+
+ private void expectParseCurrency(NumberFormat fmt, Currency expected, String text) {
+ ParsePosition pos = new ParsePosition(0);
+ CurrencyAmount currencyAmount = fmt.parseCurrency(text, pos);
+ assertTrue("Parse of " + text + " should have succeeded.", pos.getIndex() > 0);
+ assertEquals("Currency should be correct.", expected, currencyAmount.getCurrency());
+ }
public void TestJB3832(){
ULocale locale = new ULocale("pt_PT@currency=PTE");