use of android.icu.text.CurrencyMetaInfo in project j2objc by google.
the class Currency method getRoundingIncrement.
/**
* Returns the rounding increment for this currency, or 0.0 if no
* rounding is done by this currency with the Usage.
* @param Usage the usage of currency(Standard or Cash)
* @return the non-negative rounding increment, or 0.0 if none
*/
public double getRoundingIncrement(CurrencyUsage Usage) {
CurrencyMetaInfo info = CurrencyMetaInfo.getInstance();
CurrencyDigits digits = info.currencyDigits(subType, Usage);
int data1 = digits.roundingIncrement;
// This is the high-runner case, by far.
if (data1 == 0) {
return 0.0;
}
int data0 = digits.fractionDigits;
// If the meta data is invalid, return 0.0 to indicate no rounding.
if (data0 < 0 || data0 >= POW10.length) {
return 0.0;
}
// as of this writing, is CHF { 2, 25 }.
return (double) data1 / POW10[data0];
}
use of android.icu.text.CurrencyMetaInfo in project j2objc by google.
the class Currency method getAvailableCurrencies.
/**
* Returns the set of available currencies. The returned set of currencies contains all of the
* available currencies, including obsolete ones. The result set can be modified without
* affecting the available currencies in the runtime.
*
* @return The set of available currencies. The returned set could be empty if there is no
* currency data available.
*/
public static Set<Currency> getAvailableCurrencies() {
CurrencyMetaInfo info = CurrencyMetaInfo.getInstance();
List<String> list = info.currencies(CurrencyFilter.all());
HashSet<Currency> resultSet = new HashSet<Currency>(list.size());
for (String code : list) {
resultSet.add(getInstance(code));
}
return resultSet;
}
use of android.icu.text.CurrencyMetaInfo in project j2objc by google.
the class Currency method loadCurrency.
private static Currency loadCurrency(String key) {
String region;
boolean isPreEuro;
if (key.endsWith("-")) {
region = key.substring(0, key.length() - 1);
isPreEuro = true;
} else {
region = key;
isPreEuro = false;
}
CurrencyMetaInfo info = CurrencyMetaInfo.getInstance();
List<String> list = info.currencies(CurrencyFilter.onRegion(region));
if (!list.isEmpty()) {
String code = list.get(0);
if (isPreEuro && EUR_STR.equals(code)) {
if (list.size() < 2) {
return null;
}
code = list.get(1);
}
return getInstance(code);
}
return null;
}
use of android.icu.text.CurrencyMetaInfo in project j2objc by google.
the class CurrencyTest method testCurrencyMetaInfoRanges.
// A real test of CurrencyMetaInfo.
@Test
public void testCurrencyMetaInfoRanges() {
CurrencyMetaInfo metainfo = CurrencyMetaInfo.getInstance(true);
assertNotNull("have metainfo", metainfo);
// must be capitalized
CurrencyFilter filter = CurrencyFilter.onRegion("DE");
List<CurrencyInfo> currenciesInGermany = metainfo.currencyInfo(filter);
logln("currencies: " + currenciesInGermany.size());
DateFormat fmt = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS z");
fmt.setTimeZone(TimeZone.getTimeZone("GMT"));
Date demLastDate = new Date(Long.MAX_VALUE);
Date eurFirstDate = new Date(Long.MIN_VALUE);
for (CurrencyInfo info : currenciesInGermany) {
logln(info.toString());
logln("from: " + fmt.format(info.from) + Long.toHexString(info.from));
logln(" to: " + fmt.format(info.to) + Long.toHexString(info.to));
if (info.code.equals("DEM")) {
demLastDate = new Date(info.to);
} else if (info.code.equals("EUR")) {
eurFirstDate = new Date(info.from);
}
}
// the Euro and Deutschmark overlapped for several years
assertEquals("DEM available at last date", 2, metainfo.currencyInfo(filter.withDate(demLastDate)).size());
// demLastDate + 1 millisecond is not the start of the last day, we consider it the next day, so...
Date demLastDatePlus1ms = new Date(demLastDate.getTime() + 1);
assertEquals("DEM not available after very start of last date", 1, metainfo.currencyInfo(filter.withDate(demLastDatePlus1ms)).size());
// both available for start of euro
assertEquals("EUR available on start of first date", 2, metainfo.currencyInfo(filter.withDate(eurFirstDate)).size());
// but not one millisecond before the start of the first day
Date eurFirstDateMinus1ms = new Date(eurFirstDate.getTime() - 1);
assertEquals("EUR not avilable before very start of first date", 1, metainfo.currencyInfo(filter.withDate(eurFirstDateMinus1ms)).size());
// end time is last millisecond of day
GregorianCalendar cal = new GregorianCalendar();
cal.setTimeZone(TimeZone.getTimeZone("GMT"));
cal.setTime(demLastDate);
assertEquals("hour is 23", 23, cal.get(GregorianCalendar.HOUR_OF_DAY));
assertEquals("minute is 59", 59, cal.get(GregorianCalendar.MINUTE));
assertEquals("second is 59", 59, cal.get(GregorianCalendar.SECOND));
assertEquals("millisecond is 999", 999, cal.get(GregorianCalendar.MILLISECOND));
// start time is first millisecond of day
cal.setTime(eurFirstDate);
assertEquals("hour is 0", 0, cal.get(GregorianCalendar.HOUR_OF_DAY));
assertEquals("minute is 0", 0, cal.get(GregorianCalendar.MINUTE));
assertEquals("second is 0", 0, cal.get(GregorianCalendar.SECOND));
assertEquals("millisecond is 0", 0, cal.get(GregorianCalendar.MILLISECOND));
}
use of android.icu.text.CurrencyMetaInfo in project j2objc by google.
the class CurrencyTest method TestCurrencyMetaInfo.
// Coverage-only test of the CurrencyMetaInfo class
@Test
public void TestCurrencyMetaInfo() {
CurrencyMetaInfo metainfo = CurrencyMetaInfo.getInstance();
if (metainfo == null) {
errln("Unable to get CurrencyMetaInfo instance.");
return;
}
if (!CurrencyMetaInfo.hasData()) {
errln("hasData() should note return false.");
return;
}
CurrencyMetaInfo.CurrencyFilter filter;
CurrencyMetaInfo.CurrencyInfo info;
CurrencyMetaInfo.CurrencyDigits digits;
{
// CurrencyFilter
filter = CurrencyMetaInfo.CurrencyFilter.onCurrency("currency");
CurrencyMetaInfo.CurrencyFilter filter2 = CurrencyMetaInfo.CurrencyFilter.onCurrency("test");
if (filter == null) {
errln("Unable to create CurrencyFilter.");
return;
}
if (filter.equals(new Object())) {
errln("filter should not equal to Object");
return;
}
if (filter.equals(filter2)) {
errln("filter should not equal filter2");
return;
}
if (filter.hashCode() == 0) {
errln("Error getting filter hashcode");
return;
}
if (filter.toString() == null) {
errln("Error calling toString()");
return;
}
}
{
// CurrencyInfo
info = new CurrencyMetaInfo.CurrencyInfo("region", "code", 0, 1, 1, false);
if (info == null) {
errln("Error creating CurrencyInfo.");
return;
}
if (info.toString() == null) {
errln("Error calling toString()");
return;
}
}
{
// CurrencyDigits
digits = metainfo.currencyDigits("isoCode");
if (digits == null) {
errln("Unable to get CurrencyDigits.");
return;
}
if (digits.toString() == null) {
errln("Error calling toString()");
return;
}
}
}
Aggregations