diff --git a/teavm-classlib/src/main/java/org/teavm/classlib/impl/currency/CountriesGenerator.java b/teavm-classlib/src/main/java/org/teavm/classlib/impl/currency/CountriesGenerator.java new file mode 100644 index 000000000..2f2d58dfe --- /dev/null +++ b/teavm-classlib/src/main/java/org/teavm/classlib/impl/currency/CountriesGenerator.java @@ -0,0 +1,108 @@ +/* + * Copyright 2015 Alexey Andreev. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.teavm.classlib.impl.currency; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.util.ArrayList; +import java.util.List; +import org.teavm.model.MethodReference; +import org.teavm.platform.metadata.*; + +/** + * + * @author Alexey Andreev + */ +public class CountriesGenerator implements MetadataGenerator { + @Override + public Resource generateMetadata(MetadataGeneratorContext context, MethodReference method) { + try (InputStream input = context.getClassLoader().getResourceAsStream( + "org/teavm/classlib/impl/currency/iso3166.csv")) { + if (input == null) { + throw new AssertionError("ISO 3166 table was not found"); + } + try (BufferedReader reader = new BufferedReader(new InputStreamReader(input, "UTF-8"))) { + return readIso3166(context, reader); + } + } catch (IOException e) { + throw new RuntimeException("Error reading ISO 3166 table", e); + } + } + + private ResourceMap readIso3166(MetadataGeneratorContext context, BufferedReader reader) + throws IOException { + ResourceMap result = context.createResourceMap(); + int index = 0; + while (true) { + String line = reader.readLine(); + if (line == null) { + break; + } + if (index++ == 0 || line.trim().isEmpty()) { + continue; + } + String[] cells = readCsvRow(index - 1, line); + StringResource currency = context.createResource(StringResource.class); + currency.setValue(cells[7]); + result.put(cells[10], currency); + } + return result; + } + + private String[] readCsvRow(int rowIndex, String row) { + List values = new ArrayList<>(); + int index = 0; + while (index < row.length()) { + char c = row.charAt(index); + int next = index; + if (c == '"') { + ++index; + StringBuilder sb = new StringBuilder(); + while (index < row.length()) { + next = row.indexOf('"', index); + if (next == -1) { + throw new IllegalStateException("Syntax error at row " + rowIndex + + ": closing quote not found"); + } + if (next + 1 == row.length() || row.charAt(next + 1) != '"') { + sb.append(row.substring(index, next)); + index = next + 1; + break; + } + index = next + 2; + } + if (index < row.length() && row.charAt(index) != ',') { + throw new IllegalStateException("Syntax error at row " + rowIndex + ": closing quote must be " + + "followed by either line separator or comma"); + } + values.add(sb.toString()); + } else { + next = row.indexOf(',', index); + if (next == -1) { + values.add(row.substring(index)); + index = row.length(); + } else { + values.add(row.substring(index, next)); + ++next; + index = next; + } + } + } + return values.toArray(new String[values.size()]); + } +} diff --git a/teavm-classlib/src/main/java/org/teavm/classlib/impl/currency/CurrenciesGenerator.java b/teavm-classlib/src/main/java/org/teavm/classlib/impl/currency/CurrenciesGenerator.java new file mode 100644 index 000000000..e301e2bdd --- /dev/null +++ b/teavm-classlib/src/main/java/org/teavm/classlib/impl/currency/CurrenciesGenerator.java @@ -0,0 +1,143 @@ +/* + * Copyright 2015 Alexey Andreev. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.teavm.classlib.impl.currency; + +import java.io.IOException; +import java.io.InputStream; +import java.util.Iterator; +import javax.xml.parsers.DocumentBuilder; +import javax.xml.parsers.DocumentBuilderFactory; +import javax.xml.parsers.ParserConfigurationException; +import org.teavm.model.MethodReference; +import org.teavm.platform.metadata.MetadataGenerator; +import org.teavm.platform.metadata.MetadataGeneratorContext; +import org.teavm.platform.metadata.Resource; +import org.teavm.platform.metadata.ResourceArray; +import org.w3c.dom.*; +import org.xml.sax.SAXException; + +/** + * + * @author Alexey Andreev + */ +public class CurrenciesGenerator implements MetadataGenerator { + @Override + public Resource generateMetadata(MetadataGeneratorContext context, MethodReference method) { + Document doc; + try (InputStream input = context.getClassLoader().getResourceAsStream( + "org/teavm/classlib/impl/currency/iso4217.xml")) { + DocumentBuilderFactory builderFactory = DocumentBuilderFactory.newInstance(); + DocumentBuilder builder = builderFactory.newDocumentBuilder(); + doc = builder.parse(input); + } catch (IOException | ParserConfigurationException | SAXException e) { + throw new RuntimeException("Error reading ISO 4217 medata from file"); + } + + ResourceArray currencies = context.createResourceArray(); + Element root = doc.getDocumentElement(); + for (Element elem : childElements(root)) { + if (elem.getTagName().equals("CcyTbl")) { + parseCurrencies(context, elem, currencies); + } + } + return currencies; + } + + private void parseCurrencies(MetadataGeneratorContext context, Element tableElem, + ResourceArray currencies) { + for (Element currencyElem : childElements(tableElem)) { + if (!currencyElem.getTagName().equals("CcyNtry")) { + continue; + } + CurrencyResource currency = context.createResource(CurrencyResource.class); + for (Element propertyElem : childElements(currencyElem)) { + switch (propertyElem.getTagName()) { + case "Ccy": + currency.setCode(getText(propertyElem)); + break; + case "CcyNbr": + currency.setNumericCode(Integer.parseInt(getText(propertyElem))); + break; + case "CcyMnrUnts": + String value = getText(propertyElem); + if (value.equals("N.A.")) { + currency.setFractionDigits(-1); + } else { + currency.setFractionDigits(Integer.parseInt(value)); + } + break; + } + } + currencies.add(currency); + } + } + + private Iterable childElements(final Element parent) { + return new Iterable() { + NodeList nodes = parent.getChildNodes(); + @Override + public Iterator iterator() { + return new Iterator() { + int index = -1; + { + following(); + } + @Override + public void remove() { + throw new UnsupportedOperationException(); + } + @Override + public Element next() { + Element result = (Element)nodes.item(index); + following(); + return result; + } + @Override + public boolean hasNext() { + return index < nodes.getLength(); + } + private void following() { + while (++index < nodes.getLength()) { + if (nodes.item(index).getNodeType() == Node.ELEMENT_NODE) { + break; + } + } + } + }; + } + }; + } + + private String getText(Element element) { + StringBuilder sb = new StringBuilder(); + NodeList nodes = element.getChildNodes(); + for (int i = 0; i < nodes.getLength(); ++i) { + Node child = nodes.item(i); + switch (child.getNodeType()) { + case Node.TEXT_NODE: + case Node.CDATA_SECTION_NODE: + CharacterData cdata = (CharacterData)child; + sb.append(cdata.getData()); + break; + case Node.ENTITY_REFERENCE_NODE: + EntityReference ref = (EntityReference)child; + sb.append(ref.getNodeValue()); + break; + } + } + return sb.toString(); + } +} diff --git a/teavm-classlib/src/main/java/org/teavm/classlib/impl/currency/CurrencyHelper.java b/teavm-classlib/src/main/java/org/teavm/classlib/impl/currency/CurrencyHelper.java new file mode 100644 index 000000000..7cb7cc824 --- /dev/null +++ b/teavm-classlib/src/main/java/org/teavm/classlib/impl/currency/CurrencyHelper.java @@ -0,0 +1,33 @@ +/* + * Copyright 2015 Alexey Andreev. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.teavm.classlib.impl.currency; + +import org.teavm.platform.metadata.MetadataProvider; +import org.teavm.platform.metadata.ResourceArray; +import org.teavm.platform.metadata.ResourceMap; +import org.teavm.platform.metadata.StringResource; + +/** + * + * @author Alexey Andreev + */ +public final class CurrencyHelper { + @MetadataProvider(CurrenciesGenerator.class) + public static native ResourceArray getCurrencies(); + + @MetadataProvider(CountriesGenerator.class) + public static native ResourceMap getCountryToCurrencyMap(); +} diff --git a/teavm-classlib/src/main/java/org/teavm/classlib/impl/currency/CurrencyResource.java b/teavm-classlib/src/main/java/org/teavm/classlib/impl/currency/CurrencyResource.java new file mode 100644 index 000000000..95d5ef0b6 --- /dev/null +++ b/teavm-classlib/src/main/java/org/teavm/classlib/impl/currency/CurrencyResource.java @@ -0,0 +1,36 @@ +/* + * Copyright 2015 Alexey Andreev. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.teavm.classlib.impl.currency; + +import org.teavm.platform.metadata.Resource; + +/** + * + * @author Alexey Andreev + */ +public interface CurrencyResource extends Resource { + String getCode(); + + void setCode(String code); + + int getNumericCode(); + + void setNumericCode(int code); + + int getFractionDigits(); + + void setFractionDigits(int fractionDigits); +} diff --git a/teavm-classlib/src/main/java/org/teavm/classlib/impl/unicode/CLDRCurrency.java b/teavm-classlib/src/main/java/org/teavm/classlib/impl/unicode/CLDRCurrency.java new file mode 100644 index 000000000..c6373e30d --- /dev/null +++ b/teavm-classlib/src/main/java/org/teavm/classlib/impl/unicode/CLDRCurrency.java @@ -0,0 +1,33 @@ +/* + * Copyright 2015 Alexey Andreev. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.teavm.classlib.impl.unicode; + +/** + * + * @author Alexey Andreev + */ +public class CLDRCurrency { + String symbol; + String name; + + public String getSymbol() { + return symbol; + } + + public String getName() { + return name; + } +} diff --git a/teavm-classlib/src/main/java/org/teavm/classlib/impl/unicode/CLDRHelper.java b/teavm-classlib/src/main/java/org/teavm/classlib/impl/unicode/CLDRHelper.java index 7c2c9a395..3f8d7b5e2 100644 --- a/teavm-classlib/src/main/java/org/teavm/classlib/impl/unicode/CLDRHelper.java +++ b/teavm-classlib/src/main/java/org/teavm/classlib/impl/unicode/CLDRHelper.java @@ -33,6 +33,15 @@ public class CLDRHelper { return map.has(localeCode) ? map.get(localeCode).getValue() : localeCode; } + public static String resolveCountry(String language, String country) { + if (country.isEmpty()) { + String subtags = getLikelySubtags(language); + int index = subtags.lastIndexOf('_'); + country = index > 0 ? subtags.substring(index + 1) : ""; + } + return country; + } + @MetadataProvider(LikelySubtagsMetadataGenerator.class) private static native ResourceMap getLikelySubtagsMap(); @@ -199,4 +208,25 @@ public class CLDRHelper { } private static native ResourceMap getDecimalDataMap(); + + public static CurrencyLocalization resolveCurrency(String language, String country, String currency) { + String localeCode = getCode(language, country); + ResourceMap> map = getCurrencyMap(); + if (map.has(localeCode)) { + ResourceMap currencies = map.get(localeCode); + if (currencies.has(currency)) { + return currencies.get(currency); + } + } + if (map.has(language)) { + ResourceMap currencies = map.get(language); + if (currencies.has(currency)) { + return currencies.get(currency); + } + } + return null; + } + + @MetadataProvider(CurrencyLocalizationMetadataGenerator.class) + private static native ResourceMap> getCurrencyMap(); } diff --git a/teavm-classlib/src/main/java/org/teavm/classlib/impl/unicode/CLDRLocale.java b/teavm-classlib/src/main/java/org/teavm/classlib/impl/unicode/CLDRLocale.java index 6810b7c11..6d8a60981 100644 --- a/teavm-classlib/src/main/java/org/teavm/classlib/impl/unicode/CLDRLocale.java +++ b/teavm-classlib/src/main/java/org/teavm/classlib/impl/unicode/CLDRLocale.java @@ -27,6 +27,7 @@ import java.util.Map; public class CLDRLocale { final Map languages = new LinkedHashMap<>(); final Map territories = new LinkedHashMap<>(); + final Map currencies = new LinkedHashMap<>(); String[] eras; String[] dayPeriods; String[] months; @@ -46,6 +47,10 @@ public class CLDRLocale { return Collections.unmodifiableMap(territories); } + public Map getCurrencies() { + return Collections.unmodifiableMap(currencies); + } + public String[] getEras() { return Arrays.copyOf(eras, eras.length); } diff --git a/teavm-classlib/src/main/java/org/teavm/classlib/impl/unicode/CLDRReader.java b/teavm-classlib/src/main/java/org/teavm/classlib/impl/unicode/CLDRReader.java index 74af6989d..cce19a42d 100644 --- a/teavm-classlib/src/main/java/org/teavm/classlib/impl/unicode/CLDRReader.java +++ b/teavm-classlib/src/main/java/org/teavm/classlib/impl/unicode/CLDRReader.java @@ -127,6 +127,9 @@ public class CLDRReader { readDateTimeFormats(localeName, localeInfo, root); break; } + case "currencies.json": { + readCurrencies(localeName, localeInfo, input); + } } } } catch (IOException e) { @@ -188,6 +191,22 @@ public class CLDRReader { locale.timeZones = timeZones.toArray(new CLDRTimeZone[timeZones.size()]); } + private void readCurrencies(String localeCode, CLDRLocale locale, InputStream input) { + JsonObject root = (JsonObject)new JsonParser().parse(new InputStreamReader(input)); + JsonObject currenciesJson = root.get("main").getAsJsonObject().get(localeCode).getAsJsonObject() + .get("numbers").getAsJsonObject().get("currencies").getAsJsonObject(); + for (Map.Entry currencyEntry : currenciesJson.entrySet()) { + String currencyCode = currencyEntry.getKey(); + JsonObject currencyJson = currencyEntry.getValue().getAsJsonObject(); + CLDRCurrency currency = new CLDRCurrency(); + currency.name = currencyJson.get("displayName").getAsString(); + if (currencyJson.has("symbol")) { + currency.symbol = currencyJson.get("symbol").getAsString(); + } + locale.currencies.put(currencyCode, currency); + } + } + private void readEras(String localeCode, CLDRLocale locale, JsonObject root) { JsonObject erasJson = root.get("main").getAsJsonObject().get(localeCode).getAsJsonObject() .get("dates").getAsJsonObject().get("calendars").getAsJsonObject() diff --git a/teavm-classlib/src/main/java/org/teavm/classlib/impl/unicode/CurrencyLocalization.java b/teavm-classlib/src/main/java/org/teavm/classlib/impl/unicode/CurrencyLocalization.java new file mode 100644 index 000000000..e90c127c4 --- /dev/null +++ b/teavm-classlib/src/main/java/org/teavm/classlib/impl/unicode/CurrencyLocalization.java @@ -0,0 +1,32 @@ +/* + * Copyright 2015 Alexey Andreev. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.teavm.classlib.impl.unicode; + +import org.teavm.platform.metadata.Resource; + +/** + * + * @author Alexey Andreev + */ +public interface CurrencyLocalization extends Resource { + String getName(); + + void setName(String name); + + String getSymbol(); + + void setSymbol(String symbol); +} diff --git a/teavm-classlib/src/main/java/org/teavm/classlib/impl/unicode/CurrencyLocalizationMetadataGenerator.java b/teavm-classlib/src/main/java/org/teavm/classlib/impl/unicode/CurrencyLocalizationMetadataGenerator.java new file mode 100644 index 000000000..1b474a4fa --- /dev/null +++ b/teavm-classlib/src/main/java/org/teavm/classlib/impl/unicode/CurrencyLocalizationMetadataGenerator.java @@ -0,0 +1,48 @@ +/* + * Copyright 2015 Alexey Andreev. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.teavm.classlib.impl.unicode; + +import java.util.Map; +import org.teavm.model.MethodReference; +import org.teavm.platform.metadata.MetadataGenerator; +import org.teavm.platform.metadata.MetadataGeneratorContext; +import org.teavm.platform.metadata.Resource; +import org.teavm.platform.metadata.ResourceMap; + +/** + * + * @author Alexey Andreev + */ +public class CurrencyLocalizationMetadataGenerator implements MetadataGenerator { + @Override + public Resource generateMetadata(MetadataGeneratorContext context, MethodReference method) { + CLDRReader reader = context.getService(CLDRReader.class); + ResourceMap> map = context.createResourceMap(); + for (Map.Entry localeEntry : reader.getKnownLocales().entrySet()) { + CLDRLocale locale = localeEntry.getValue(); + ResourceMap currencies = context.createResourceMap(); + map.put(localeEntry.getKey(), currencies); + for (Map.Entry currencyEntry : locale.getCurrencies().entrySet()) { + CLDRCurrency currency = currencyEntry.getValue(); + CurrencyLocalization localization = context.createResource(CurrencyLocalization.class); + localization.setName(currency.getName()); + localization.setSymbol(currency.getSymbol() != null ? currency.getSymbol() : ""); + currencies.put(currencyEntry.getKey(), localization); + } + } + return map; + } +} diff --git a/teavm-classlib/src/main/java/org/teavm/classlib/java/util/TCalendar.java b/teavm-classlib/src/main/java/org/teavm/classlib/java/util/TCalendar.java index 2c835c7d3..f54c9901b 100644 --- a/teavm-classlib/src/main/java/org/teavm/classlib/java/util/TCalendar.java +++ b/teavm-classlib/src/main/java/org/teavm/classlib/java/util/TCalendar.java @@ -175,21 +175,11 @@ public abstract class TCalendar implements TSerializable, TCloneable, TComparabl cacheFor = locale; } - private static String resolveCountry(TLocale locale) { - String country = locale.getCountry(); - if (country.isEmpty()) { - String subtags = CLDRHelper.getLikelySubtags(locale.getLanguage()); - int index = subtags.lastIndexOf('_'); - country = index > 0 ? subtags.substring(index + 1) : ""; - } - return country; - } - private static int resolveFirstDayOfWeek(TLocale locale) { if (locale == cacheFor && firstDayOfWeekCache >= 0) { return firstDayOfWeekCache; } - String country = resolveCountry(locale); + String country = CLDRHelper.resolveCountry(locale.getLanguage(), locale.getCountry()); ResourceMap dayMap = CLDRHelper.getFirstDayOfWeek(); firstDayOfWeekCache = dayMap.has(country) ? dayMap.get(country).getValue() : dayMap.get("001").getValue(); return firstDayOfWeekCache; @@ -199,7 +189,7 @@ public abstract class TCalendar implements TSerializable, TCloneable, TComparabl if (locale == cacheFor && minimalDaysInFirstWeekCache >= 0) { return minimalDaysInFirstWeekCache; } - String country = resolveCountry(locale); + String country = CLDRHelper.resolveCountry(locale.getLanguage(), locale.getCountry()); ResourceMap dayMap = CLDRHelper.getMinimalDaysInFirstWeek(); minimalDaysInFirstWeekCache = dayMap.has(country) ? dayMap.get(country).getValue() : dayMap.get("001").getValue(); diff --git a/teavm-classlib/src/main/java/org/teavm/classlib/java/util/TCurrency.java b/teavm-classlib/src/main/java/org/teavm/classlib/java/util/TCurrency.java new file mode 100644 index 000000000..184ed2aeb --- /dev/null +++ b/teavm-classlib/src/main/java/org/teavm/classlib/java/util/TCurrency.java @@ -0,0 +1,121 @@ +/* + * Copyright 2015 Alexey Andreev. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.teavm.classlib.java.util; + +import java.util.HashMap; +import java.util.HashSet; +import java.util.Map; +import java.util.Set; +import org.teavm.classlib.impl.currency.CurrencyHelper; +import org.teavm.classlib.impl.currency.CurrencyResource; +import org.teavm.classlib.impl.unicode.CLDRHelper; +import org.teavm.classlib.impl.unicode.CurrencyLocalization; +import org.teavm.classlib.java.io.TSerializable; +import org.teavm.platform.metadata.ResourceArray; +import org.teavm.platform.metadata.ResourceMap; +import org.teavm.platform.metadata.StringResource; + +/** + * + * @author Alexey Andreev + */ +public final class TCurrency implements TSerializable { + private static Map currencies; + private CurrencyResource resource; + + private TCurrency(CurrencyResource resource) { + this.resource = resource; + } + + private static void initCurrencies() { + if (currencies != null) { + return; + } + currencies = new HashMap<>(); + ResourceArray resources = CurrencyHelper.getCurrencies(); + for (int i = 0; i < resources.size(); ++i) { + CurrencyResource resource = resources.get(i); + currencies.put(resource.getCode(), new TCurrency(resource)); + } + } + + public static TCurrency getInstance(String currencyCode) { + if (currencyCode == null) { + throw new NullPointerException(); + } + initCurrencies(); + TCurrency currency = currencies.get(currencyCode); + if (currency == null) { + throw new IllegalArgumentException("Currency not found: " + currencyCode); + } + return currency; + } + + public static TCurrency getInstance(TLocale locale) { + if (locale == null) { + throw new NullPointerException(); + } + String coutry = CLDRHelper.resolveCountry(locale.getLanguage(), locale.getCountry()); + ResourceMap countryMap = CurrencyHelper.getCountryToCurrencyMap(); + if (!countryMap.has(coutry)) { + return null; + } + return getInstance(countryMap.get(coutry).getValue()); + } + + public static Set getAvailableCurrencies() { + initCurrencies(); + return new HashSet<>(currencies.values()); + } + + public String getCurrencyCode() { + return resource.getCode(); + } + + public String getSymbol() { + return getSymbol(TLocale.getDefault()); + } + + public String getSymbol(TLocale locale) { + CurrencyLocalization localization = CLDRHelper.resolveCurrency(locale.getLanguage(), locale.getCountry(), + getCurrencyCode()); + return localization != null && !localization.getSymbol().isEmpty() ? + localization.getSymbol() : getCurrencyCode(); + } + + public int getDefaultFractionDigits() { + return resource.getFractionDigits(); + } + + public int getNumericCode() { + return resource.getNumericCode(); + } + + public String getDisplayName() { + return getDisplayName(TLocale.getDefault()); + } + + public String getDisplayName(TLocale locale) { + CurrencyLocalization localization = CLDRHelper.resolveCurrency(locale.getLanguage(), locale.getCountry(), + getCurrencyCode()); + return localization != null ? localization.getName() : getCurrencyCode(); + } + + @Override + public String toString() { + return resource.getCode(); + } +} diff --git a/teavm-classlib/src/main/resources/org/teavm/classlib/impl/currency/iso3166.csv b/teavm-classlib/src/main/resources/org/teavm/classlib/impl/currency/iso3166.csv new file mode 100644 index 000000000..9a14d8dd6 --- /dev/null +++ b/teavm-classlib/src/main/resources/org/teavm/classlib/impl/currency/iso3166.csv @@ -0,0 +1,269 @@ +Sort Order,Common Name,Formal Name,Type,Sub Type,Sovereignty,Capital,ISO 4217 Currency Code,ISO 4217 Currency Name,ITU-T Telephone Code,ISO 3166-1 2 Letter Code,ISO 3166-1 3 Letter Code,ISO 3166-1 Number,IANA Country Code TLD +1,Afghanistan,Islamic State of Afghanistan,Independent State,,,Kabul,AFN,Afghani,93,AF,AFG,4,.af +2,Albania,Republic of Albania,Independent State,,,Tirana,ALL,Lek,355,AL,ALB,8,.al +3,Algeria,People's Democratic Republic of Algeria,Independent State,,,Algiers,DZD,Dinar,213,DZ,DZA,12,.dz +4,Andorra,Principality of Andorra,Independent State,,,Andorra la Vella,EUR,Euro,376,AD,AND,20,.ad +5,Angola,Republic of Angola,Independent State,,,Luanda,AOA,Kwanza,244,AO,AGO,24,.ao +6,Antigua and Barbuda,,Independent State,,,Saint John's,XCD,Dollar,-267,AG,ATG,28,.ag +7,Argentina,Argentine Republic,Independent State,,,Buenos Aires,ARS,Peso,54,AR,ARG,32,.ar +8,Armenia,Republic of Armenia,Independent State,,,Yerevan,AMD,Dram,374,AM,ARM,51,.am +9,Australia,Commonwealth of Australia,Independent State,,,Canberra,AUD,Dollar,61,AU,AUS,36,.au +10,Austria,Republic of Austria,Independent State,,,Vienna,EUR,Euro,43,AT,AUT,40,.at +11,Azerbaijan,Republic of Azerbaijan,Independent State,,,Baku,AZN,Manat,994,AZ,AZE,31,.az +12,"Bahamas, The",Commonwealth of The Bahamas,Independent State,,,Nassau,BSD,Dollar,-241,BS,BHS,44,.bs +13,Bahrain,Kingdom of Bahrain,Independent State,,,Manama,BHD,Dinar,973,BH,BHR,48,.bh +14,Bangladesh,People's Republic of Bangladesh,Independent State,,,Dhaka,BDT,Taka,880,BD,BGD,50,.bd +15,Barbados,,Independent State,,,Bridgetown,BBD,Dollar,-245,BB,BRB,52,.bb +16,Belarus,Republic of Belarus,Independent State,,,Minsk,BYR,Ruble,375,BY,BLR,112,.by +17,Belgium,Kingdom of Belgium,Independent State,,,Brussels,EUR,Euro,32,BE,BEL,56,.be +18,Belize,,Independent State,,,Belmopan,BZD,Dollar,501,BZ,BLZ,84,.bz +19,Benin,Republic of Benin,Independent State,,,Porto-Novo,XOF,Franc,229,BJ,BEN,204,.bj +20,Bhutan,Kingdom of Bhutan,Independent State,,,Thimphu,BTN,Ngultrum,975,BT,BTN,64,.bt +21,Bolivia,Republic of Bolivia,Independent State,,,La Paz (administrative/legislative) and Sucre (judical),BOB,Boliviano,591,BO,BOL,68,.bo +22,Bosnia and Herzegovina,,Independent State,,,Sarajevo,BAM,Marka,387,BA,BIH,70,.ba +23,Botswana,Republic of Botswana,Independent State,,,Gaborone,BWP,Pula,267,BW,BWA,72,.bw +24,Brazil,Federative Republic of Brazil,Independent State,,,Brasilia,BRL,Real,55,BR,BRA,76,.br +25,Brunei,Negara Brunei Darussalam,Independent State,,,Bandar Seri Begawan,BND,Dollar,673,BN,BRN,96,.bn +26,Bulgaria,Republic of Bulgaria,Independent State,,,Sofia,BGN,Lev,359,BG,BGR,100,.bg +27,Burkina Faso,,Independent State,,,Ouagadougou,XOF,Franc,226,BF,BFA,854,.bf +28,Burundi,Republic of Burundi,Independent State,,,Bujumbura,BIF,Franc,257,BI,BDI,108,.bi +29,Cambodia,Kingdom of Cambodia,Independent State,,,Phnom Penh,KHR,Riels,855,KH,KHM,116,.kh +30,Cameroon,Republic of Cameroon,Independent State,,,Yaounde,XAF,Franc,237,CM,CMR,120,.cm +31,Canada,,Independent State,,,Ottawa,CAD,Dollar,1,CA,CAN,124,.ca +32,Cape Verde,Republic of Cape Verde,Independent State,,,Praia,CVE,Escudo,238,CV,CPV,132,.cv +33,Central African Republic,,Independent State,,,Bangui,XAF,Franc,236,CF,CAF,140,.cf +34,Chad,Republic of Chad,Independent State,,,N'Djamena,XAF,Franc,235,TD,TCD,148,.td +35,Chile,Republic of Chile,Independent State,,,Santiago (administrative/judical) and Valparaiso (legislative),CLP,Peso,56,CL,CHL,152,.cl +36,"China, People's Republic of",People's Republic of China,Independent State,,,Beijing,CNY,Yuan Renminbi,86,CN,CHN,156,.cn +37,Colombia,Republic of Colombia,Independent State,,,Bogota,COP,Peso,57,CO,COL,170,.co +38,Comoros,Union of Comoros,Independent State,,,Moroni,KMF,Franc,269,KM,COM,174,.km +39,"Congo, (Congo – Kinshasa)",Democratic Republic of the Congo,Independent State,,,Kinshasa,CDF,Franc,243,CD,COD,180,.cd +40,"Congo, (Congo – Brazzaville)",Republic of the Congo,Independent State,,,Brazzaville,XAF,Franc,242,CG,COG,178,.cg +41,Costa Rica,Republic of Costa Rica,Independent State,,,San Jose,CRC,Colon,506,CR,CRI,188,.cr +42,Cote d'Ivoire (Ivory Coast),Republic of Cote d'Ivoire,Independent State,,,Yamoussoukro,XOF,Franc,225,CI,CIV,384,.ci +43,Croatia,Republic of Croatia,Independent State,,,Zagreb,HRK,Kuna,385,HR,HRV,191,.hr +44,Cuba,Republic of Cuba,Independent State,,,Havana,CUP,Peso,53,CU,CUB,192,.cu +45,Cyprus,Republic of Cyprus,Independent State,,,Nicosia,CYP,Pound,357,CY,CYP,196,.cy +46,Czech Republic,,Independent State,,,Prague,CZK,Koruna,420,CZ,CZE,203,.cz +47,Denmark,Kingdom of Denmark,Independent State,,,Copenhagen,DKK,Krone,45,DK,DNK,208,.dk +48,Djibouti,Republic of Djibouti,Independent State,,,Djibouti,DJF,Franc,253,DJ,DJI,262,.dj +49,Dominica,Commonwealth of Dominica,Independent State,,,Roseau,XCD,Dollar,-766,DM,DMA,212,.dm +50,Dominican Republic,,Independent State,,,Santo Domingo,DOP,Peso,+1-809 and 1-829,DO,DOM,214,.do +51,Ecuador,Republic of Ecuador,Independent State,,,Quito,USD,Dollar,593,EC,ECU,218,.ec +52,Egypt,Arab Republic of Egypt,Independent State,,,Cairo,EGP,Pound,20,EG,EGY,818,.eg +53,El Salvador,Republic of El Salvador,Independent State,,,San Salvador,USD,Dollar,503,SV,SLV,222,.sv +54,Equatorial Guinea,Republic of Equatorial Guinea,Independent State,,,Malabo,XAF,Franc,240,GQ,GNQ,226,.gq +55,Eritrea,State of Eritrea,Independent State,,,Asmara,ERN,Nakfa,291,ER,ERI,232,.er +56,Estonia,Republic of Estonia,Independent State,,,Tallinn,EEK,Kroon,372,EE,EST,233,.ee +57,Ethiopia,Federal Democratic Republic of Ethiopia,Independent State,,,Addis Ababa,ETB,Birr,251,ET,ETH,231,.et +58,Fiji,Republic of the Fiji Islands,Independent State,,,Suva,FJD,Dollar,679,FJ,FJI,242,.fj +59,Finland,Republic of Finland,Independent State,,,Helsinki,EUR,Euro,358,FI,FIN,246,.fi +60,France,French Republic,Independent State,,,Paris,EUR,Euro,33,FR,FRA,250,.fr +61,Gabon,Gabonese Republic,Independent State,,,Libreville,XAF,Franc,241,GA,GAB,266,.ga +62,"Gambia, The",Republic of The Gambia,Independent State,,,Banjul,GMD,Dalasi,220,GM,GMB,270,.gm +63,Georgia,Republic of Georgia,Independent State,,,Tbilisi,GEL,Lari,995,GE,GEO,268,.ge +64,Germany,Federal Republic of Germany,Independent State,,,Berlin,EUR,Euro,49,DE,DEU,276,.de +65,Ghana,Republic of Ghana,Independent State,,,Accra,GHC,Cedi,233,GH,GHA,288,.gh +66,Greece,Hellenic Republic,Independent State,,,Athens,EUR,Euro,30,GR,GRC,300,.gr +67,Grenada,,Independent State,,,Saint George's,XCD,Dollar,-472,GD,GRD,308,.gd +68,Guatemala,Republic of Guatemala,Independent State,,,Guatemala,GTQ,Quetzal,502,GT,GTM,320,.gt +69,Guinea,Republic of Guinea,Independent State,,,Conakry,GNF,Franc,224,GN,GIN,324,.gn +70,Guinea-Bissau,Republic of Guinea-Bissau,Independent State,,,Bissau,XOF,Franc,245,GW,GNB,624,.gw +71,Guyana,Co-operative Republic of Guyana,Independent State,,,Georgetown,GYD,Dollar,592,GY,GUY,328,.gy +72,Haiti,Republic of Haiti,Independent State,,,Port-au-Prince,HTG,Gourde,509,HT,HTI,332,.ht +73,Honduras,Republic of Honduras,Independent State,,,Tegucigalpa,HNL,Lempira,504,HN,HND,340,.hn +74,Hungary,Republic of Hungary,Independent State,,,Budapest,HUF,Forint,36,HU,HUN,348,.hu +75,Iceland,Republic of Iceland,Independent State,,,Reykjavik,ISK,Krona,354,IS,ISL,352,.is +76,India,Republic of India,Independent State,,,New Delhi,INR,Rupee,91,IN,IND,356,.in +77,Indonesia,Republic of Indonesia,Independent State,,,Jakarta,IDR,Rupiah,62,ID,IDN,360,.id +78,Iran,Islamic Republic of Iran,Independent State,,,Tehran,IRR,Rial,98,IR,IRN,364,.ir +79,Iraq,Republic of Iraq,Independent State,,,Baghdad,IQD,Dinar,964,IQ,IRQ,368,.iq +80,Ireland,,Independent State,,,Dublin,EUR,Euro,353,IE,IRL,372,.ie +81,Israel,State of Israel,Independent State,,,Jerusalem,ILS,Shekel,972,IL,ISR,376,.il +82,Italy,Italian Republic,Independent State,,,Rome,EUR,Euro,39,IT,ITA,380,.it +83,Jamaica,,Independent State,,,Kingston,JMD,Dollar,-875,JM,JAM,388,.jm +84,Japan,,Independent State,,,Tokyo,JPY,Yen,81,JP,JPN,392,.jp +85,Jordan,Hashemite Kingdom of Jordan,Independent State,,,Amman,JOD,Dinar,962,JO,JOR,400,.jo +86,Kazakhstan,Republic of Kazakhstan,Independent State,,,Astana,KZT,Tenge,7,KZ,KAZ,398,.kz +87,Kenya,Republic of Kenya,Independent State,,,Nairobi,KES,Shilling,254,KE,KEN,404,.ke +88,Kiribati,Republic of Kiribati,Independent State,,,Tarawa,AUD,Dollar,686,KI,KIR,296,.ki +89,"Korea, North",Democratic People's Republic of Korea,Independent State,,,Pyongyang,KPW,Won,850,KP,PRK,408,.kp +90,"Korea, South",Republic of Korea,Independent State,,,Seoul,KRW,Won,82,KR,KOR,410,.kr +91,Kuwait,State of Kuwait,Independent State,,,Kuwait,KWD,Dinar,965,KW,KWT,414,.kw +92,Kyrgyzstan,Kyrgyz Republic,Independent State,,,Bishkek,KGS,Som,996,KG,KGZ,417,.kg +93,Laos,Lao People's Democratic Republic,Independent State,,,Vientiane,LAK,Kip,856,LA,LAO,418,.la +94,Latvia,Republic of Latvia,Independent State,,,Riga,LVL,Lat,371,LV,LVA,428,.lv +95,Lebanon,Lebanese Republic,Independent State,,,Beirut,LBP,Pound,961,LB,LBN,422,.lb +96,Lesotho,Kingdom of Lesotho,Independent State,,,Maseru,LSL,Loti,266,LS,LSO,426,.ls +97,Liberia,Republic of Liberia,Independent State,,,Monrovia,LRD,Dollar,231,LR,LBR,430,.lr +98,Libya,Great Socialist People's Libyan Arab Jamahiriya,Independent State,,,Tripoli,LYD,Dinar,218,LY,LBY,434,.ly +99,Liechtenstein,Principality of Liechtenstein,Independent State,,,Vaduz,CHF,Franc,423,LI,LIE,438,.li +100,Lithuania,Republic of Lithuania,Independent State,,,Vilnius,LTL,Litas,370,LT,LTU,440,.lt +101,Luxembourg,Grand Duchy of Luxembourg,Independent State,,,Luxembourg,EUR,Euro,352,LU,LUX,442,.lu +102,Macedonia,Republic of Macedonia,Independent State,,,Skopje,MKD,Denar,389,MK,MKD,807,.mk +103,Madagascar,Republic of Madagascar,Independent State,,,Antananarivo,MGA,Ariary,261,MG,MDG,450,.mg +104,Malawi,Republic of Malawi,Independent State,,,Lilongwe,MWK,Kwacha,265,MW,MWI,454,.mw +105,Malaysia,,Independent State,,,Kuala Lumpur (legislative/judical) and Putrajaya (administrative),MYR,Ringgit,60,MY,MYS,458,.my +106,Maldives,Republic of Maldives,Independent State,,,Male,MVR,Rufiyaa,960,MV,MDV,462,.mv +107,Mali,Republic of Mali,Independent State,,,Bamako,XOF,Franc,223,ML,MLI,466,.ml +108,Malta,Republic of Malta,Independent State,,,Valletta,MTL,Lira,356,MT,MLT,470,.mt +109,Marshall Islands,Republic of the Marshall Islands,Independent State,,,Majuro,USD,Dollar,692,MH,MHL,584,.mh +110,Mauritania,Islamic Republic of Mauritania,Independent State,,,Nouakchott,MRO,Ouguiya,222,MR,MRT,478,.mr +111,Mauritius,Republic of Mauritius,Independent State,,,Port Louis,MUR,Rupee,230,MU,MUS,480,.mu +112,Mexico,United Mexican States,Independent State,,,Mexico,MXN,Peso,52,MX,MEX,484,.mx +113,Micronesia,Federated States of Micronesia,Independent State,,,Palikir,USD,Dollar,691,FM,FSM,583,.fm +114,Moldova,Republic of Moldova,Independent State,,,Chisinau,MDL,Leu,373,MD,MDA,498,.md +115,Monaco,Principality of Monaco,Independent State,,,Monaco,EUR,Euro,377,MC,MCO,492,.mc +116,Mongolia,,Independent State,,,Ulaanbaatar,MNT,Tugrik,976,MN,MNG,496,.mn +117,Montenegro,Republic of Montenegro,Independent State,,,Podgorica,EUR,Euro,382,ME,MNE,499,.me and .yu +118,Morocco,Kingdom of Morocco,Independent State,,,Rabat,MAD,Dirham,212,MA,MAR,504,.ma +119,Mozambique,Republic of Mozambique,Independent State,,,Maputo,MZM,Meticail,258,MZ,MOZ,508,.mz +120,Myanmar (Burma),Union of Myanmar,Independent State,,,Naypyidaw,MMK,Kyat,95,MM,MMR,104,.mm +121,Namibia,Republic of Namibia,Independent State,,,Windhoek,NAD,Dollar,264,NA,NAM,516,.na +122,Nauru,Republic of Nauru,Independent State,,,Yaren,AUD,Dollar,674,NR,NRU,520,.nr +123,Nepal,,Independent State,,,Kathmandu,NPR,Rupee,977,NP,NPL,524,.np +124,Netherlands,Kingdom of the Netherlands,Independent State,,,Amsterdam (administrative) and The Hague (legislative/judical),EUR,Euro,31,NL,NLD,528,.nl +125,New Zealand,,Independent State,,,Wellington,NZD,Dollar,64,NZ,NZL,554,.nz +126,Nicaragua,Republic of Nicaragua,Independent State,,,Managua,NIO,Cordoba,505,NI,NIC,558,.ni +127,Niger,Republic of Niger,Independent State,,,Niamey,XOF,Franc,227,NE,NER,562,.ne +128,Nigeria,Federal Republic of Nigeria,Independent State,,,Abuja,NGN,Naira,234,NG,NGA,566,.ng +129,Norway,Kingdom of Norway,Independent State,,,Oslo,NOK,Krone,47,NO,NOR,578,.no +130,Oman,Sultanate of Oman,Independent State,,,Muscat,OMR,Rial,968,OM,OMN,512,.om +131,Pakistan,Islamic Republic of Pakistan,Independent State,,,Islamabad,PKR,Rupee,92,PK,PAK,586,.pk +132,Palau,Republic of Palau,Independent State,,,Melekeok,USD,Dollar,680,PW,PLW,585,.pw +133,Panama,Republic of Panama,Independent State,,,Panama,PAB,Balboa,507,PA,PAN,591,.pa +134,Papua New Guinea,Independent State of Papua New Guinea,Independent State,,,Port Moresby,PGK,Kina,675,PG,PNG,598,.pg +135,Paraguay,Republic of Paraguay,Independent State,,,Asuncion,PYG,Guarani,595,PY,PRY,600,.py +136,Peru,Republic of Peru,Independent State,,,Lima,PEN,Sol,51,PE,PER,604,.pe +137,Philippines,Republic of the Philippines,Independent State,,,Manila,PHP,Peso,63,PH,PHL,608,.ph +138,Poland,Republic of Poland,Independent State,,,Warsaw,PLN,Zloty,48,PL,POL,616,.pl +139,Portugal,Portuguese Republic,Independent State,,,Lisbon,EUR,Euro,351,PT,PRT,620,.pt +140,Qatar,State of Qatar,Independent State,,,Doha,QAR,Rial,974,QA,QAT,634,.qa +141,Romania,,Independent State,,,Bucharest,RON,Leu,40,RO,ROU,642,.ro +142,Russia,Russian Federation,Independent State,,,Moscow,RUB,Ruble,7,RU,RUS,643,.ru and .su +143,Rwanda,Republic of Rwanda,Independent State,,,Kigali,RWF,Franc,250,RW,RWA,646,.rw +144,Saint Kitts and Nevis,Federation of Saint Kitts and Nevis,Independent State,,,Basseterre,XCD,Dollar,-868,KN,KNA,659,.kn +145,Saint Lucia,,Independent State,,,Castries,XCD,Dollar,-757,LC,LCA,662,.lc +146,Saint Vincent and the Grenadines,,Independent State,,,Kingstown,XCD,Dollar,-783,VC,VCT,670,.vc +147,Samoa,Independent State of Samoa,Independent State,,,Apia,WST,Tala,685,WS,WSM,882,.ws +148,San Marino,Republic of San Marino,Independent State,,,San Marino,EUR,Euro,378,SM,SMR,674,.sm +149,Sao Tome and Principe,Democratic Republic of Sao Tome and Principe,Independent State,,,Sao Tome,STD,Dobra,239,ST,STP,678,.st +150,Saudi Arabia,Kingdom of Saudi Arabia,Independent State,,,Riyadh,SAR,Rial,966,SA,SAU,682,.sa +151,Senegal,Republic of Senegal,Independent State,,,Dakar,XOF,Franc,221,SN,SEN,686,.sn +152,Serbia,Republic of Serbia,Independent State,,,Belgrade,RSD,Dinar,381,RS,SRB,688,.rs and .yu +153,Seychelles,Republic of Seychelles,Independent State,,,Victoria,SCR,Rupee,248,SC,SYC,690,.sc +154,Sierra Leone,Republic of Sierra Leone,Independent State,,,Freetown,SLL,Leone,232,SL,SLE,694,.sl +155,Singapore,Republic of Singapore,Independent State,,,Singapore,SGD,Dollar,65,SG,SGP,702,.sg +156,Slovakia,Slovak Republic,Independent State,,,Bratislava,SKK,Koruna,421,SK,SVK,703,.sk +157,Slovenia,Republic of Slovenia,Independent State,,,Ljubljana,EUR,Euro,386,SI,SVN,705,.si +158,Solomon Islands,,Independent State,,,Honiara,SBD,Dollar,677,SB,SLB,90,.sb +159,Somalia,,Independent State,,,Mogadishu,SOS,Shilling,252,SO,SOM,706,.so +160,South Africa,Republic of South Africa,Independent State,,,"Pretoria (administrative), Cape Town (legislative), and Bloemfontein (judical)",ZAR,Rand,27,ZA,ZAF,710,.za +161,Spain,Kingdom of Spain,Independent State,,,Madrid,EUR,Euro,34,ES,ESP,724,.es +162,Sri Lanka,Democratic Socialist Republic of Sri Lanka,Independent State,,,Colombo (administrative/judical) and Sri Jayewardenepura Kotte (legislative),LKR,Rupee,94,LK,LKA,144,.lk +163,Sudan,Republic of the Sudan,Independent State,,,Khartoum,SDD,Dinar,249,SD,SDN,736,.sd +164,Suriname,Republic of Suriname,Independent State,,,Paramaribo,SRD,Dollar,597,SR,SUR,740,.sr +165,Swaziland,Kingdom of Swaziland,Independent State,,,Mbabane (administrative) and Lobamba (legislative),SZL,Lilangeni,268,SZ,SWZ,748,.sz +166,Sweden,Kingdom of Sweden,Independent State,,,Stockholm,SEK,Kronoa,46,SE,SWE,752,.se +167,Switzerland,Swiss Confederation,Independent State,,,Bern,CHF,Franc,41,CH,CHE,756,.ch +168,Syria,Syrian Arab Republic,Independent State,,,Damascus,SYP,Pound,963,SY,SYR,760,.sy +169,Tajikistan,Republic of Tajikistan,Independent State,,,Dushanbe,TJS,Somoni,992,TJ,TJK,762,.tj +170,Tanzania,United Republic of Tanzania,Independent State,,,Dar es Salaam (administrative/judical) and Dodoma (legislative),TZS,Shilling,255,TZ,TZA,834,.tz +171,Thailand,Kingdom of Thailand,Independent State,,,Bangkok,THB,Baht,66,TH,THA,764,.th +172,Timor-Leste (East Timor),Democratic Republic of Timor-Leste,Independent State,,,Dili,USD,Dollar,670,TL,TLS,626,.tp and .tl +173,Togo,Togolese Republic,Independent State,,,Lome,XOF,Franc,228,TG,TGO,768,.tg +174,Tonga,Kingdom of Tonga,Independent State,,,Nuku'alofa,TOP,Pa'anga,676,TO,TON,776,.to +175,Trinidad and Tobago,Republic of Trinidad and Tobago,Independent State,,,Port-of-Spain,TTD,Dollar,-867,TT,TTO,780,.tt +176,Tunisia,Tunisian Republic,Independent State,,,Tunis,TND,Dinar,216,TN,TUN,788,.tn +177,Turkey,Republic of Turkey,Independent State,,,Ankara,TRY,Lira,90,TR,TUR,792,.tr +178,Turkmenistan,,Independent State,,,Ashgabat,TMM,Manat,993,TM,TKM,795,.tm +179,Tuvalu,,Independent State,,,Funafuti,AUD,Dollar,688,TV,TUV,798,.tv +180,Uganda,Republic of Uganda,Independent State,,,Kampala,UGX,Shilling,256,UG,UGA,800,.ug +181,Ukraine,,Independent State,,,Kiev,UAH,Hryvnia,380,UA,UKR,804,.ua +182,United Arab Emirates,United Arab Emirates,Independent State,,,Abu Dhabi,AED,Dirham,971,AE,ARE,784,.ae +183,United Kingdom,United Kingdom of Great Britain and Northern Ireland,Independent State,,,London,GBP,Pound,44,GB,GBR,826,.uk +184,United States,United States of America,Independent State,,,Washington,USD,Dollar,1,US,USA,840,.us +185,Uruguay,Oriental Republic of Uruguay,Independent State,,,Montevideo,UYU,Peso,598,UY,URY,858,.uy +186,Uzbekistan,Republic of Uzbekistan,Independent State,,,Tashkent,UZS,Som,998,UZ,UZB,860,.uz +187,Vanuatu,Republic of Vanuatu,Independent State,,,Port-Vila,VUV,Vatu,678,VU,VUT,548,.vu +188,Vatican City,State of the Vatican City,Independent State,,,Vatican City,EUR,Euro,379,VA,VAT,336,.va +189,Venezuela,Bolivarian Republic of Venezuela,Independent State,,,Caracas,VEB,Bolivar,58,VE,VEN,862,.ve +190,Vietnam,Socialist Republic of Vietnam,Independent State,,,Hanoi,VND,Dong,84,VN,VNM,704,.vn +191,Yemen,Republic of Yemen,Independent State,,,Sanaa,YER,Rial,967,YE,YEM,887,.ye +192,Zambia,Republic of Zambia,Independent State,,,Lusaka,ZMK,Kwacha,260,ZM,ZMB,894,.zm +193,Zimbabwe,Republic of Zimbabwe,Independent State,,,Harare,ZWD,Dollar,263,ZW,ZWE,716,.zw +194,Abkhazia,Republic of Abkhazia,Proto Independent State,,,Sokhumi,RUB,Ruble,995,GE,GEO,268,.ge +195,"China, Republic of (Taiwan)",Republic of China,Proto Independent State,,,Taipei,TWD,Dollar,886,TW,TWN,158,.tw +196,Nagorno-Karabakh,Nagorno-Karabakh Republic,Proto Independent State,,,Stepanakert,AMD,Dram,277,AZ,AZE,31,.az +197,Northern Cyprus,Turkish Republic of Northern Cyprus,Proto Independent State,,,Nicosia,TRY,Lira,-302,CY,CYP,196,.nc.tr +198,Pridnestrovie (Transnistria),Pridnestrovian Moldavian Republic,Proto Independent State,,,Tiraspol,,Ruple,-160,MD,MDA,498,.md +199,Somaliland,Republic of Somaliland,Proto Independent State,,,Hargeisa,,Shilling,252,SO,SOM,706,.so +200,South Ossetia,Republic of South Ossetia,Proto Independent State,,,Tskhinvali,RUB and GEL,Ruble and Lari,995,GE,GEO,268,.ge +201,Ashmore and Cartier Islands,Territory of Ashmore and Cartier Islands,Dependency,External Territory,Australia,,,,,AU,AUS,36,.au +202,Christmas Island,Territory of Christmas Island,Dependency,External Territory,Australia,The Settlement (Flying Fish Cove),AUD,Dollar,61,CX,CXR,162,.cx +203,Cocos (Keeling) Islands,Territory of Cocos (Keeling) Islands,Dependency,External Territory,Australia,West Island,AUD,Dollar,61,CC,CCK,166,.cc +204,Coral Sea Islands,Coral Sea Islands Territory,Dependency,External Territory,Australia,,,,,AU,AUS,36,.au +205,Heard Island and McDonald Islands,Territory of Heard Island and McDonald Islands,Dependency,External Territory,Australia,,,,,HM,HMD,334,.hm +206,Norfolk Island,Territory of Norfolk Island,Dependency,External Territory,Australia,Kingston,AUD,Dollar,672,NF,NFK,574,.nf +207,New Caledonia,,Dependency,Sui generis Collectivity,France,Noumea,XPF,Franc,687,NC,NCL,540,.nc +208,French Polynesia,Overseas Country of French Polynesia,Dependency,Overseas Collectivity,France,Papeete,XPF,Franc,689,PF,PYF,258,.pf +209,Mayotte,Departmental Collectivity of Mayotte,Dependency,Overseas Collectivity,France,Mamoudzou,EUR,Euro,262,YT,MYT,175,.yt +210,Saint Barthelemy,Collectivity of Saint Barthelemy,Dependency,Overseas Collectivity,France,Gustavia,EUR,Euro,590,GP,GLP,312,.gp +211,Saint Martin,Collectivity of Saint Martin,Dependency,Overseas Collectivity,France,Marigot,EUR,Euro,590,GP,GLP,312,.gp +212,Saint Pierre and Miquelon,Territorial Collectivity of Saint Pierre and Miquelon,Dependency,Overseas Collectivity,France,Saint-Pierre,EUR,Euro,508,PM,SPM,666,.pm +213,Wallis and Futuna,Collectivity of the Wallis and Futuna Islands,Dependency,Overseas Collectivity,France,Mata'utu,XPF,Franc,681,WF,WLF,876,.wf +214,French Southern and Antarctic Lands,Territory of the French Southern and Antarctic Lands,Dependency,Overseas Territory,France,Martin-de-Viviès,,,,TF,ATF,260,.tf +215,Clipperton Island,,Dependency,Possession,France,,,,,PF,PYF,258,.pf +216,Bouvet Island,,Dependency,Territory,Norway,,,,,BV,BVT,74,.bv +217,Cook Islands,,Dependency,Self-Governing in Free Association,New Zealand,Avarua,NZD,Dollar,682,CK,COK,184,.ck +218,Niue,,Dependency,Self-Governing in Free Association,New Zealand,Alofi,NZD,Dollar,683,NU,NIU,570,.nu +219,Tokelau,,Dependency,Territory,New Zealand,,NZD,Dollar,690,TK,TKL,772,.tk +220,Guernsey,Bailiwick of Guernsey,Dependency,Crown Dependency,United Kingdom,Saint Peter Port,GGP,Pound,44,GG,GGY,831,.gg +221,Isle of Man,,Dependency,Crown Dependency,United Kingdom,Douglas,IMP,Pound,44,IM,IMN,833,.im +222,Jersey,Bailiwick of Jersey,Dependency,Crown Dependency,United Kingdom,Saint Helier,JEP,Pound,44,JE,JEY,832,.je +223,Anguilla,,Dependency,Overseas Territory,United Kingdom,The Valley,XCD,Dollar,-263,AI,AIA,660,.ai +224,Bermuda,,Dependency,Overseas Territory,United Kingdom,Hamilton,BMD,Dollar,-440,BM,BMU,60,.bm +225,British Indian Ocean Territory,,Dependency,Overseas Territory,United Kingdom,,,,246,IO,IOT,86,.io +226,British Sovereign Base Areas,,Dependency,Overseas Territory,United Kingdom,Episkopi,CYP,Pound,357,,,, +227,British Virgin Islands,,Dependency,Overseas Territory,United Kingdom,Road Town,USD,Dollar,-283,VG,VGB,92,.vg +228,Cayman Islands,,Dependency,Overseas Territory,United Kingdom,George Town,KYD,Dollar,-344,KY,CYM,136,.ky +229,Falkland Islands (Islas Malvinas),,Dependency,Overseas Territory,United Kingdom,Stanley,FKP,Pound,500,FK,FLK,238,.fk +230,Gibraltar,,Dependency,Overseas Territory,United Kingdom,Gibraltar,GIP,Pound,350,GI,GIB,292,.gi +231,Montserrat,,Dependency,Overseas Territory,United Kingdom,Plymouth,XCD,Dollar,-663,MS,MSR,500,.ms +232,Pitcairn Islands,,Dependency,Overseas Territory,United Kingdom,Adamstown,NZD,Dollar,,PN,PCN,612,.pn +233,Saint Helena,,Dependency,Overseas Territory,United Kingdom,Jamestown,SHP,Pound,290,SH,SHN,654,.sh +234,South Georgia & South Sandwich Islands,,Dependency,Overseas Territory,United Kingdom,,,,,GS,SGS,239,.gs +235,Turks and Caicos Islands,,Dependency,Overseas Territory,United Kingdom,Grand Turk,USD,Dollar,-648,TC,TCA,796,.tc +236,Northern Mariana Islands,Commonwealth of The Northern Mariana Islands,Dependency,Commonwealth,United States,Saipan,USD,Dollar,-669,MP,MNP,580,.mp +237,Puerto Rico,Commonwealth of Puerto Rico,Dependency,Commonwealth,United States,San Juan,USD,Dollar,+1-787 and 1-939,PR,PRI,630,.pr +238,American Samoa,Territory of American Samoa,Dependency,Territory,United States,Pago Pago,USD,Dollar,-683,AS,ASM,16,.as +239,Baker Island,,Dependency,Territory,United States,,,,,UM,UMI,581, +240,Guam,Territory of Guam,Dependency,Territory,United States,Hagatna,USD,Dollar,-670,GU,GUM,316,.gu +241,Howland Island,,Dependency,Territory,United States,,,,,UM,UMI,581, +242,Jarvis Island,,Dependency,Territory,United States,,,,,UM,UMI,581, +243,Johnston Atoll,,Dependency,Territory,United States,,,,,UM,UMI,581, +244,Kingman Reef,,Dependency,Territory,United States,,,,,UM,UMI,581, +245,Midway Islands,,Dependency,Territory,United States,,,,,UM,UMI,581, +246,Navassa Island,,Dependency,Territory,United States,,,,,UM,UMI,581, +247,Palmyra Atoll,,Dependency,Territory,United States,,,,,UM,UMI,581, +248,U.S. Virgin Islands,United States Virgin Islands,Dependency,Territory,United States,Charlotte Amalie,USD,Dollar,-339,VI,VIR,850,.vi +249,Wake Island,,Dependency,Territory,United States,,,,,UM,UMI,850, +250,Hong Kong,Hong Kong Special Administrative Region,Proto Dependency,Special Administrative Region,China,,HKD,Dollar,852,HK,HKG,344,.hk +251,Macau,Macau Special Administrative Region,Proto Dependency,Special Administrative Region,China,Macau,MOP,Pataca,853,MO,MAC,446,.mo +252,Faroe Islands,,Proto Dependency,,Denmark,Torshavn,DKK,Krone,298,FO,FRO,234,.fo +253,Greenland,,Proto Dependency,,Denmark,Nuuk (Godthab),DKK,Krone,299,GL,GRL,304,.gl +254,French Guiana,Overseas Region of Guiana,Proto Dependency,Overseas Region,France,Cayenne,EUR,Euro,594,GF,GUF,254,.gf +255,Guadeloupe,Overseas Region of Guadeloupe,Proto Dependency,Overseas Region,France,Basse-Terre,EUR,Euro,590,GP,GLP,312,.gp +256,Martinique,Overseas Region of Martinique,Proto Dependency,Overseas Region,France,Fort-de-France,EUR,Euro,596,MQ,MTQ,474,.mq +257,Reunion,Overseas Region of Reunion,Proto Dependency,Overseas Region,France,Saint-Denis,EUR,Euro,262,RE,REU,638,.re +258,Aland,,Proto Dependency,,Finland,Mariehamn,EUR,Euro,340,AX,ALA,248,.ax +259,Aruba,,Proto Dependency,,Netherlands,Oranjestad,AWG,Guilder,297,AW,ABW,533,.aw +260,Netherlands Antilles,,Proto Dependency,,Netherlands,Willemstad,ANG,Guilder,599,AN,ANT,530,.an +261,Svalbard,,Proto Dependency,,Norway,Longyearbyen,NOK,Krone,47,SJ,SJM,744,.sj +262,Ascension,,Proto Dependency,Dependency of Saint Helena,United Kingdom,Georgetown,SHP,Pound,247,AC,ASC,,.ac +263,Tristan da Cunha,,Proto Dependency,Dependency of Saint Helena,United Kingdom,Edinburgh,SHP,Pound,290,TA,TAA,, +268,Australian Antarctic Territory,,Antarctic Territory,External Territory,Australia,,,,,AQ,ATA,10,.aq +269,Ross Dependency,,Antarctic Territory,Territory,New Zealand,,,,,AQ,ATA,10,.aq +270,Peter I Island,,Antarctic Territory,Territory,Norway,,,,,AQ,ATA,10,.aq +271,Queen Maud Land,,Antarctic Territory,Territory,Norway,,,,,AQ,ATA,10,.aq +272,British Antarctic Territory,,Antarctic Territory,Overseas Territory,United Kingdom,,,,,AQ,ATA,10,.aq diff --git a/teavm-classlib/src/main/resources/org/teavm/classlib/impl/currency/iso4217.xml b/teavm-classlib/src/main/resources/org/teavm/classlib/impl/currency/iso4217.xml new file mode 100644 index 000000000..ce05608b1 --- /dev/null +++ b/teavm-classlib/src/main/resources/org/teavm/classlib/impl/currency/iso4217.xml @@ -0,0 +1,1944 @@ + + + + + AFGHANISTAN + Afghani + AFN + 971 + 2 + + + ÅLAND ISLANDS + Euro + EUR + 978 + 2 + + + ALBANIA + Lek + ALL + 008 + 2 + + + ALGERIA + Algerian Dinar + DZD + 012 + 2 + + + AMERICAN SAMOA + US Dollar + USD + 840 + 2 + + + ANDORRA + Euro + EUR + 978 + 2 + + + ANGOLA + Kwanza + AOA + 973 + 2 + + + ANGUILLA + East Caribbean Dollar + XCD + 951 + 2 + + + ANTARCTICA + No universal currency + + + ANTIGUA AND BARBUDA + East Caribbean Dollar + XCD + 951 + 2 + + + ARGENTINA + Argentine Peso + ARS + 032 + 2 + + + ARMENIA + Armenian Dram + AMD + 051 + 2 + + + ARUBA + Aruban Florin + AWG + 533 + 2 + + + AUSTRALIA + Australian Dollar + AUD + 036 + 2 + + + AUSTRIA + Euro + EUR + 978 + 2 + + + AZERBAIJAN + Azerbaijanian Manat + AZN + 944 + 2 + + + BAHAMAS + Bahamian Dollar + BSD + 044 + 2 + + + BAHRAIN + Bahraini Dinar + BHD + 048 + 3 + + + BANGLADESH + Taka + BDT + 050 + 2 + + + BARBADOS + Barbados Dollar + BBD + 052 + 2 + + + BELARUS + Belarussian Ruble + BYR + 974 + 0 + + + BELGIUM + Euro + EUR + 978 + 2 + + + BELIZE + Belize Dollar + BZD + 084 + 2 + + + BENIN + CFA Franc BCEAO + XOF + 952 + 0 + + + BERMUDA + Bermudian Dollar + BMD + 060 + 2 + + + BHUTAN + Ngultrum + BTN + 064 + 2 + + + BHUTAN + Indian Rupee + INR + 356 + 2 + + + BOLIVIA, PLURINATIONAL STATE OF + Boliviano + BOB + 068 + 2 + + + BOLIVIA, PLURINATIONAL STATE OF + Mvdol + BOV + 984 + 2 + + + BONAIRE, SINT EUSTATIUS AND SABA + US Dollar + USD + 840 + 2 + + + BOSNIA AND HERZEGOVINA + Convertible Mark + BAM + 977 + 2 + + + BOTSWANA + Pula + BWP + 072 + 2 + + + BOUVET ISLAND + Norwegian Krone + NOK + 578 + 2 + + + BRAZIL + Brazilian Real + BRL + 986 + 2 + + + BRITISH INDIAN OCEAN TERRITORY + US Dollar + USD + 840 + 2 + + + BRUNEI DARUSSALAM + Brunei Dollar + BND + 096 + 2 + + + BULGARIA + Bulgarian Lev + BGN + 975 + 2 + + + BURKINA FASO + CFA Franc BCEAO + XOF + 952 + 0 + + + BURUNDI + Burundi Franc + BIF + 108 + 0 + + + CAMBODIA + Riel + KHR + 116 + 2 + + + CAMEROON + CFA Franc BEAC + XAF + 950 + 0 + + + CANADA + Canadian Dollar + CAD + 124 + 2 + + + CABO VERDE + Cabo Verde Escudo + CVE + 132 + 2 + + + CAYMAN ISLANDS + Cayman Islands Dollar + KYD + 136 + 2 + + + CENTRAL AFRICAN REPUBLIC + CFA Franc BEAC + XAF + 950 + 0 + + + CHAD + CFA Franc BEAC + XAF + 950 + 0 + + + CHILE + Unidad de Fomento + CLF + 990 + 4 + + + CHILE + Chilean Peso + CLP + 152 + 0 + + + CHINA + Yuan Renminbi + CNY + 156 + 2 + + + CHRISTMAS ISLAND + Australian Dollar + AUD + 036 + 2 + + + COCOS (KEELING) ISLANDS + Australian Dollar + AUD + 036 + 2 + + + COLOMBIA + Colombian Peso + COP + 170 + 2 + + + COLOMBIA + Unidad de Valor Real + COU + 970 + 2 + + + COMOROS + Comoro Franc + KMF + 174 + 0 + + + CONGO + CFA Franc BEAC + XAF + 950 + 0 + + + CONGO, DEMOCRATIC REPUBLIC OF THE + Congolese Franc + CDF + 976 + 2 + + + COOK ISLANDS + New Zealand Dollar + NZD + 554 + 2 + + + COSTA RICA + Costa Rican Colon + CRC + 188 + 2 + + + CÔTE D'IVOIRE + CFA Franc BCEAO + XOF + 952 + 0 + + + CROATIA + Croatian Kuna + HRK + 191 + 2 + + + CUBA + Peso Convertible + CUC + 931 + 2 + + + CUBA + Cuban Peso + CUP + 192 + 2 + + + CURAÇAO + Netherlands Antillean Guilder + ANG + 532 + 2 + + + CYPRUS + Euro + EUR + 978 + 2 + + + CZECH REPUBLIC + Czech Koruna + CZK + 203 + 2 + + + DENMARK + Danish Krone + DKK + 208 + 2 + + + DJIBOUTI + Djibouti Franc + DJF + 262 + 0 + + + DOMINICA + East Caribbean Dollar + XCD + 951 + 2 + + + DOMINICAN REPUBLIC + Dominican Peso + DOP + 214 + 2 + + + ECUADOR + US Dollar + USD + 840 + 2 + + + EGYPT + Egyptian Pound + EGP + 818 + 2 + + + EL SALVADOR + El Salvador Colon + SVC + 222 + 2 + + + EL SALVADOR + US Dollar + USD + 840 + 2 + + + EQUATORIAL GUINEA + CFA Franc BEAC + XAF + 950 + 0 + + + ERITREA + Nakfa + ERN + 232 + 2 + + + ESTONIA + Euro + EUR + 978 + 2 + + + ETHIOPIA + Ethiopian Birr + ETB + 230 + 2 + + + EUROPEAN UNION + Euro + EUR + 978 + 2 + + + FALKLAND ISLANDS (MALVINAS) + Falkland Islands Pound + FKP + 238 + 2 + + + FAROE ISLANDS + Danish Krone + DKK + 208 + 2 + + + FIJI + Fiji Dollar + FJD + 242 + 2 + + + FINLAND + Euro + EUR + 978 + 2 + + + FRANCE + Euro + EUR + 978 + 2 + + + FRENCH GUIANA + Euro + EUR + 978 + 2 + + + FRENCH POLYNESIA + CFP Franc + XPF + 953 + 0 + + + FRENCH SOUTHERN TERRITORIES + Euro + EUR + 978 + 2 + + + GABON + CFA Franc BEAC + XAF + 950 + 0 + + + GAMBIA + Dalasi + GMD + 270 + 2 + + + GEORGIA + Lari + GEL + 981 + 2 + + + GERMANY + Euro + EUR + 978 + 2 + + + GHANA + Ghana Cedi + GHS + 936 + 2 + + + GIBRALTAR + Gibraltar Pound + GIP + 292 + 2 + + + GREECE + Euro + EUR + 978 + 2 + + + GREENLAND + Danish Krone + DKK + 208 + 2 + + + GRENADA + East Caribbean Dollar + XCD + 951 + 2 + + + GUADELOUPE + Euro + EUR + 978 + 2 + + + GUAM + US Dollar + USD + 840 + 2 + + + GUATEMALA + Quetzal + GTQ + 320 + 2 + + + GUERNSEY + Pound Sterling + GBP + 826 + 2 + + + GUINEA + Guinea Franc + GNF + 324 + 0 + + + GUINEA-BISSAU + CFA Franc BCEAO + XOF + 952 + 0 + + + GUYANA + Guyana Dollar + GYD + 328 + 2 + + + HAITI + Gourde + HTG + 332 + 2 + + + HAITI + US Dollar + USD + 840 + 2 + + + HEARD ISLAND AND McDONALD ISLANDS + Australian Dollar + AUD + 036 + 2 + + + HOLY SEE (VATICAN CITY STATE) + Euro + EUR + 978 + 2 + + + HONDURAS + Lempira + HNL + 340 + 2 + + + HONG KONG + Hong Kong Dollar + HKD + 344 + 2 + + + HUNGARY + Forint + HUF + 348 + 2 + + + ICELAND + Iceland Krona + ISK + 352 + 0 + + + INDIA + Indian Rupee + INR + 356 + 2 + + + INDONESIA + Rupiah + IDR + 360 + 2 + + + INTERNATIONAL MONETARY FUND (IMF)  + SDR (Special Drawing Right) + XDR + 960 + N.A. + + + IRAN, ISLAMIC REPUBLIC OF + Iranian Rial + IRR + 364 + 2 + + + IRAQ + Iraqi Dinar + IQD + 368 + 3 + + + IRELAND + Euro + EUR + 978 + 2 + + + ISLE OF MAN + Pound Sterling + GBP + 826 + 2 + + + ISRAEL + New Israeli Sheqel + ILS + 376 + 2 + + + ITALY + Euro + EUR + 978 + 2 + + + JAMAICA + Jamaican Dollar + JMD + 388 + 2 + + + JAPAN + Yen + JPY + 392 + 0 + + + JERSEY + Pound Sterling + GBP + 826 + 2 + + + JORDAN + Jordanian Dinar + JOD + 400 + 3 + + + KAZAKHSTAN + Tenge + KZT + 398 + 2 + + + KENYA + Kenyan Shilling + KES + 404 + 2 + + + KIRIBATI + Australian Dollar + AUD + 036 + 2 + + + KOREA, DEMOCRATIC PEOPLE’S REPUBLIC OF + North Korean Won + KPW + 408 + 2 + + + KOREA, REPUBLIC OF + Won + KRW + 410 + 0 + + + KUWAIT + Kuwaiti Dinar + KWD + 414 + 3 + + + KYRGYZSTAN + Som + KGS + 417 + 2 + + + LAO PEOPLE’S DEMOCRATIC REPUBLIC + Kip + LAK + 418 + 2 + + + LATVIA + Euro + EUR + 978 + 2 + + + LEBANON + Lebanese Pound + LBP + 422 + 2 + + + LESOTHO + Loti + LSL + 426 + 2 + + + LESOTHO + Rand + ZAR + 710 + 2 + + + LIBERIA + Liberian Dollar + LRD + 430 + 2 + + + LIBYA + Libyan Dinar + LYD + 434 + 3 + + + LIECHTENSTEIN + Swiss Franc + CHF + 756 + 2 + + + LITHUANIA + Euro + EUR + 978 + 2 + + + LUXEMBOURG + Euro + EUR + 978 + 2 + + + MACAO + Pataca + MOP + 446 + 2 + + + MACEDONIA, THE FORMER +YUGOSLAV REPUBLIC OF + Denar + MKD + 807 + 2 + + + MADAGASCAR + Malagasy Ariary + MGA + 969 + 2 + + + MALAWI + Kwacha + MWK + 454 + 2 + + + MALAYSIA + Malaysian Ringgit + MYR + 458 + 2 + + + MALDIVES + Rufiyaa + MVR + 462 + 2 + + + MALI + CFA Franc BCEAO + XOF + 952 + 0 + + + MALTA + Euro + EUR + 978 + 2 + + + MARSHALL ISLANDS + US Dollar + USD + 840 + 2 + + + MARTINIQUE + Euro + EUR + 978 + 2 + + + MAURITANIA + Ouguiya + MRO + 478 + 2 + + + MAURITIUS + Mauritius Rupee + MUR + 480 + 2 + + + MAYOTTE + Euro + EUR + 978 + 2 + + + MEMBER COUNTRIES OF THE AFRICAN DEVELOPMENT BANK GROUP + ADB Unit of Account + XUA + 965 + N.A. + + + MEXICO + Mexican Peso + MXN + 484 + 2 + + + MEXICO + Mexican Unidad de Inversion (UDI) + MXV + 979 + 2 + + + MICRONESIA, FEDERATED STATES OF + US Dollar + USD + 840 + 2 + + + MOLDOVA, REPUBLIC OF + Moldovan Leu + MDL + 498 + 2 + + + MONACO + Euro + EUR + 978 + 2 + + + MONGOLIA + Tugrik + MNT + 496 + 2 + + + MONTENEGRO + Euro + EUR + 978 + 2 + + + MONTSERRAT + East Caribbean Dollar + XCD + 951 + 2 + + + MOROCCO + Moroccan Dirham + MAD + 504 + 2 + + + MOZAMBIQUE + Mozambique Metical + MZN + 943 + 2 + + + MYANMAR + Kyat + MMK + 104 + 2 + + + NAMIBIA + Namibia Dollar + NAD + 516 + 2 + + + NAMIBIA + Rand + ZAR + 710 + 2 + + + NAURU + Australian Dollar + AUD + 036 + 2 + + + NEPAL + Nepalese Rupee + NPR + 524 + 2 + + + NETHERLANDS + Euro + EUR + 978 + 2 + + + NEW CALEDONIA + CFP Franc + XPF + 953 + 0 + + + NEW ZEALAND + New Zealand Dollar + NZD + 554 + 2 + + + NICARAGUA + Cordoba Oro + NIO + 558 + 2 + + + NIGER + CFA Franc BCEAO + XOF + 952 + 0 + + + NIGERIA + Naira + NGN + 566 + 2 + + + NIUE + New Zealand Dollar + NZD + 554 + 2 + + + NORFOLK ISLAND + Australian Dollar + AUD + 036 + 2 + + + NORTHERN MARIANA ISLANDS + US Dollar + USD + 840 + 2 + + + NORWAY + Norwegian Krone + NOK + 578 + 2 + + + OMAN + Rial Omani + OMR + 512 + 3 + + + PAKISTAN + Pakistan Rupee + PKR + 586 + 2 + + + PALAU + US Dollar + USD + 840 + 2 + + + PALESTINE, STATE OF + No universal currency + + + PANAMA + Balboa + PAB + 590 + 2 + + + PANAMA + US Dollar + USD + 840 + 2 + + + PAPUA NEW GUINEA + Kina + PGK + 598 + 2 + + + PARAGUAY + Guarani + PYG + 600 + 0 + + + PERU + Nuevo Sol + PEN + 604 + 2 + + + PHILIPPINES + Philippine Peso + PHP + 608 + 2 + + + PITCAIRN + New Zealand Dollar + NZD + 554 + 2 + + + POLAND + Zloty + PLN + 985 + 2 + + + PORTUGAL + Euro + EUR + 978 + 2 + + + PUERTO RICO + US Dollar + USD + 840 + 2 + + + QATAR + Qatari Rial + QAR + 634 + 2 + + + RÉUNION + Euro + EUR + 978 + 2 + + + ROMANIA + New Romanian Leu + RON + 946 + 2 + + + RUSSIAN FEDERATION + Russian Ruble + RUB + 643 + 2 + + + RWANDA + Rwanda Franc + RWF + 646 + 0 + + + SAINT BARTHÉLEMY + Euro + EUR + 978 + 2 + + + SAINT HELENA, ASCENSION AND +TRISTAN DA CUNHA + Saint Helena Pound + SHP + 654 + 2 + + + SAINT KITTS AND NEVIS + East Caribbean Dollar + XCD + 951 + 2 + + + SAINT LUCIA + East Caribbean Dollar + XCD + 951 + 2 + + + SAINT MARTIN (FRENCH PART) + Euro + EUR + 978 + 2 + + + SAINT PIERRE AND MIQUELON + Euro + EUR + 978 + 2 + + + SAINT VINCENT AND THE GRENADINES + East Caribbean Dollar + XCD + 951 + 2 + + + SAMOA + Tala + WST + 882 + 2 + + + SAN MARINO + Euro + EUR + 978 + 2 + + + SAO TOME AND PRINCIPE + Dobra + STD + 678 + 2 + + + SAUDI ARABIA + Saudi Riyal + SAR + 682 + 2 + + + SENEGAL + CFA Franc BCEAO + XOF + 952 + 0 + + + SERBIA + Serbian Dinar + RSD + 941 + 2 + + + SEYCHELLES + Seychelles Rupee + SCR + 690 + 2 + + + SIERRA LEONE + Leone + SLL + 694 + 2 + + + SINGAPORE + Singapore Dollar + SGD + 702 + 2 + + + SINT MAARTEN (DUTCH PART) + Netherlands Antillean Guilder + ANG + 532 + 2 + + + SISTEMA UNITARIO DE COMPENSACION REGIONAL DE PAGOS "SUCRE" + Sucre + XSU + 994 + N.A. + + + SLOVAKIA + Euro + EUR + 978 + 2 + + + SLOVENIA + Euro + EUR + 978 + 2 + + + SOLOMON ISLANDS + Solomon Islands Dollar + SBD + 090 + 2 + + + SOMALIA + Somali Shilling + SOS + 706 + 2 + + + SOUTH AFRICA + Rand + ZAR + 710 + 2 + + + SOUTH GEORGIA AND THE SOUTH SANDWICH ISLANDS + No universal currency + + + SOUTH SUDAN + South Sudanese Pound + SSP + 728 + 2 + + + SPAIN + Euro + EUR + 978 + 2 + + + SRI LANKA + Sri Lanka Rupee + LKR + 144 + 2 + + + SUDAN + Sudanese Pound + SDG + 938 + 2 + + + SURINAME + Surinam Dollar + SRD + 968 + 2 + + + SVALBARD AND JAN MAYEN + Norwegian Krone + NOK + 578 + 2 + + + SWAZILAND + Lilangeni + SZL + 748 + 2 + + + SWEDEN + Swedish Krona + SEK + 752 + 2 + + + SWITZERLAND + WIR Euro + CHE + 947 + 2 + + + SWITZERLAND + Swiss Franc + CHF + 756 + 2 + + + SWITZERLAND + WIR Franc + CHW + 948 + 2 + + + SYRIAN ARAB REPUBLIC + Syrian Pound + SYP + 760 + 2 + + + TAIWAN, PROVINCE OF CHINA + New Taiwan Dollar + TWD + 901 + 2 + + + TAJIKISTAN + Somoni + TJS + 972 + 2 + + + TANZANIA, UNITED REPUBLIC OF + Tanzanian Shilling + TZS + 834 + 2 + + + THAILAND + Baht + THB + 764 + 2 + + + TIMOR-LESTE + US Dollar + USD + 840 + 2 + + + TOGO + CFA Franc BCEAO + XOF + 952 + 0 + + + TOKELAU + New Zealand Dollar + NZD + 554 + 2 + + + TONGA + Pa’anga + TOP + 776 + 2 + + + TRINIDAD AND TOBAGO + Trinidad and Tobago Dollar + TTD + 780 + 2 + + + TUNISIA + Tunisian Dinar + TND + 788 + 3 + + + TURKEY + Turkish Lira + TRY + 949 + 2 + + + TURKMENISTAN + Turkmenistan New Manat + TMT + 934 + 2 + + + TURKS AND CAICOS ISLANDS + US Dollar + USD + 840 + 2 + + + TUVALU + Australian Dollar + AUD + 036 + 2 + + + UGANDA + Uganda Shilling + UGX + 800 + 0 + + + UKRAINE + Hryvnia + UAH + 980 + 2 + + + UNITED ARAB EMIRATES + UAE Dirham + AED + 784 + 2 + + + UNITED KINGDOM + Pound Sterling + GBP + 826 + 2 + + + UNITED STATES + US Dollar + USD + 840 + 2 + + + UNITED STATES + US Dollar (Next day) + USN + 997 + 2 + + + UNITED STATES MINOR OUTLYING ISLANDS + US Dollar + USD + 840 + 2 + + + URUGUAY + Uruguay Peso en Unidades Indexadas (URUIURUI) + UYI + 940 + 0 + + + URUGUAY + Peso Uruguayo + UYU + 858 + 2 + + + UZBEKISTAN + Uzbekistan Sum + UZS + 860 + 2 + + + VANUATU + Vatu + VUV + 548 + 0 + + + VENEZUELA, BOLIVARIAN REPUBLIC OF + Bolivar + VEF + 937 + 2 + + + VIET NAM + Dong + VND + 704 + 0 + + + VIRGIN ISLANDS (BRITISH) + US Dollar + USD + 840 + 2 + + + VIRGIN ISLANDS (U.S.) + US Dollar + USD + 840 + 2 + + + WALLIS AND FUTUNA + CFP Franc + XPF + 953 + 0 + + + WESTERN SAHARA + Moroccan Dirham + MAD + 504 + 2 + + + YEMEN + Yemeni Rial + YER + 886 + 2 + + + ZAMBIA + Zambian Kwacha + ZMW + 967 + 2 + + + ZIMBABWE + Zimbabwe Dollar + ZWL + 932 + 2 + + + ZZ01_Bond Markets Unit European_EURCO + Bond Markets Unit European Composite Unit (EURCO) + XBA + 955 + N.A. + + + ZZ02_Bond Markets Unit European_EMU-6 + Bond Markets Unit European Monetary Unit (E.M.U.-6) + XBB + 956 + N.A. + + + ZZ03_Bond Markets Unit European_EUA-9 + Bond Markets Unit European Unit of Account 9 (E.U.A.-9) + XBC + 957 + N.A. + + + ZZ04_Bond Markets Unit European_EUA-17 + Bond Markets Unit European Unit of Account 17 (E.U.A.-17) + XBD + 958 + N.A. + + + ZZ06_Testing_Code + Codes specifically reserved for testing purposes + XTS + 963 + N.A. + + + ZZ07_No_Currency + The codes assigned for transactions where no currency is involved + XXX + 999 + N.A. + + + ZZ08_Gold + Gold + XAU + 959 + N.A. + + + ZZ09_Palladium + Palladium + XPD + 964 + N.A. + + + ZZ10_Platinum + Platinum + XPT + 962 + N.A. + + + ZZ11_Silver + Silver + XAG + 961 + N.A. + + + \ No newline at end of file diff --git a/teavm-tests/src/test/java/org/teavm/classlib/java/util/CurrencyTest.java b/teavm-tests/src/test/java/org/teavm/classlib/java/util/CurrencyTest.java new file mode 100644 index 000000000..2c34b36c4 --- /dev/null +++ b/teavm-tests/src/test/java/org/teavm/classlib/java/util/CurrencyTest.java @@ -0,0 +1,87 @@ +/* + * Copyright 2015 Alexey Andreev. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.teavm.classlib.java.util; + +import static org.junit.Assert.*; +import java.util.Currency; +import java.util.Locale; +import org.junit.Ignore; +import org.junit.Test; + +/** + * + * @author Alexey Andreev + */ +public class CurrencyTest { + @Test + public void findsByCode() { + Currency currency = Currency.getInstance("RUB"); + assertEquals("RUB", currency.getCurrencyCode()); + assertEquals(2, currency.getDefaultFractionDigits()); + assertEquals(643, currency.getNumericCode()); + } + + @Test + public void findsByLocale() { + Currency currency = Currency.getInstance(new Locale("ru", "RU")); + assertEquals("RUB", currency.getCurrencyCode()); + + currency = Currency.getInstance(new Locale("en", "US")); + assertEquals("USD", currency.getCurrencyCode()); + + currency = Currency.getInstance(new Locale("en", "GB")); + assertEquals("GBP", currency.getCurrencyCode()); + } + + @Test + @Ignore + // It seems that JDK can't translate currency names into Russian + public void getsDisplayName() { + Locale russian = new Locale("ru"); + Locale english = new Locale("en"); + + Currency currency = Currency.getInstance("USD"); + assertEquals("US Dollar", currency.getDisplayName(english)); + assertEquals("Доллар США", currency.getDisplayName(russian)); + + currency = Currency.getInstance("RUB"); + assertEquals("Russian Ruble", currency.getDisplayName(english)); + assertEquals("Российский рубль", currency.getDisplayName(russian)); + + assertEquals("CHF", Currency.getInstance("CHF").getDisplayName(new Locale("xx", "YY"))); + } + + @Test + @Ignore + // It seems that JDK does not know about currency symbols + public void getsSymbol() { + Locale russian = new Locale("ru"); + Locale english = new Locale("en"); + + Currency currency = Currency.getInstance("USD"); + assertEquals("$", currency.getSymbol(english)); + assertEquals("$", currency.getSymbol(russian)); + + currency = Currency.getInstance("RUB"); + assertEquals("RUB", currency.getSymbol(english)); + assertEquals("руб.", currency.getSymbol(russian)); + } + + @Test(expected = IllegalArgumentException.class) + public void rejectsWrongCode() { + Currency.getInstance("WWW"); + } +}