mirror of
https://github.com/Eaglercraft-TeaVM-Fork/eagler-teavm.git
synced 2024-12-22 16:14:10 -08:00
Merge branch 'currency'
This commit is contained in:
commit
d7065bed8e
|
@ -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<StringResource> readIso3166(MetadataGeneratorContext context, BufferedReader reader)
|
||||
throws IOException {
|
||||
ResourceMap<StringResource> 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<String> 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()]);
|
||||
}
|
||||
}
|
|
@ -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<CurrencyResource> 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<CurrencyResource> 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<Element> childElements(final Element parent) {
|
||||
return new Iterable<Element>() {
|
||||
NodeList nodes = parent.getChildNodes();
|
||||
@Override
|
||||
public Iterator<Element> iterator() {
|
||||
return new Iterator<Element>() {
|
||||
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();
|
||||
}
|
||||
}
|
|
@ -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<CurrencyResource> getCurrencies();
|
||||
|
||||
@MetadataProvider(CountriesGenerator.class)
|
||||
public static native ResourceMap<StringResource> getCountryToCurrencyMap();
|
||||
}
|
|
@ -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);
|
||||
}
|
|
@ -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;
|
||||
}
|
||||
}
|
|
@ -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<StringResource> getLikelySubtagsMap();
|
||||
|
||||
|
@ -199,4 +208,25 @@ public class CLDRHelper {
|
|||
}
|
||||
|
||||
private static native ResourceMap<CLDRDecimalData> getDecimalDataMap();
|
||||
|
||||
public static CurrencyLocalization resolveCurrency(String language, String country, String currency) {
|
||||
String localeCode = getCode(language, country);
|
||||
ResourceMap<ResourceMap<CurrencyLocalization>> map = getCurrencyMap();
|
||||
if (map.has(localeCode)) {
|
||||
ResourceMap<CurrencyLocalization> currencies = map.get(localeCode);
|
||||
if (currencies.has(currency)) {
|
||||
return currencies.get(currency);
|
||||
}
|
||||
}
|
||||
if (map.has(language)) {
|
||||
ResourceMap<CurrencyLocalization> currencies = map.get(language);
|
||||
if (currencies.has(currency)) {
|
||||
return currencies.get(currency);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@MetadataProvider(CurrencyLocalizationMetadataGenerator.class)
|
||||
private static native ResourceMap<ResourceMap<CurrencyLocalization>> getCurrencyMap();
|
||||
}
|
||||
|
|
|
@ -27,6 +27,7 @@ import java.util.Map;
|
|||
public class CLDRLocale {
|
||||
final Map<String, String> languages = new LinkedHashMap<>();
|
||||
final Map<String, String> territories = new LinkedHashMap<>();
|
||||
final Map<String, CLDRCurrency> currencies = new LinkedHashMap<>();
|
||||
String[] eras;
|
||||
String[] dayPeriods;
|
||||
String[] months;
|
||||
|
@ -46,6 +47,10 @@ public class CLDRLocale {
|
|||
return Collections.unmodifiableMap(territories);
|
||||
}
|
||||
|
||||
public Map<String, CLDRCurrency> getCurrencies() {
|
||||
return Collections.unmodifiableMap(currencies);
|
||||
}
|
||||
|
||||
public String[] getEras() {
|
||||
return Arrays.copyOf(eras, eras.length);
|
||||
}
|
||||
|
|
|
@ -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<String, JsonElement> 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()
|
||||
|
|
|
@ -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);
|
||||
}
|
|
@ -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<ResourceMap<CurrencyLocalization>> map = context.createResourceMap();
|
||||
for (Map.Entry<String, CLDRLocale> localeEntry : reader.getKnownLocales().entrySet()) {
|
||||
CLDRLocale locale = localeEntry.getValue();
|
||||
ResourceMap<CurrencyLocalization> currencies = context.createResourceMap();
|
||||
map.put(localeEntry.getKey(), currencies);
|
||||
for (Map.Entry<String, CLDRCurrency> 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;
|
||||
}
|
||||
}
|
|
@ -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<IntResource> 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<IntResource> dayMap = CLDRHelper.getMinimalDaysInFirstWeek();
|
||||
minimalDaysInFirstWeekCache = dayMap.has(country) ? dayMap.get(country).getValue() :
|
||||
dayMap.get("001").getValue();
|
||||
|
|
|
@ -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<String, TCurrency> currencies;
|
||||
private CurrencyResource resource;
|
||||
|
||||
private TCurrency(CurrencyResource resource) {
|
||||
this.resource = resource;
|
||||
}
|
||||
|
||||
private static void initCurrencies() {
|
||||
if (currencies != null) {
|
||||
return;
|
||||
}
|
||||
currencies = new HashMap<>();
|
||||
ResourceArray<CurrencyResource> 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<StringResource> countryMap = CurrencyHelper.getCountryToCurrencyMap();
|
||||
if (!countryMap.has(coutry)) {
|
||||
return null;
|
||||
}
|
||||
return getInstance(countryMap.get(coutry).getValue());
|
||||
}
|
||||
|
||||
public static Set<TCurrency> 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();
|
||||
}
|
||||
}
|
|
@ -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
|
|
File diff suppressed because it is too large
Load Diff
|
@ -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");
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user