mirror of
https://github.com/unicode-org/icu.git
synced 2025-04-08 06:53:45 +00:00
ICU-2826 Java API signature changes
X-SVN-Rev: 24048
This commit is contained in:
parent
3cdb54b89d
commit
4b09c0d1f0
2 changed files with 187 additions and 136 deletions
|
@ -176,131 +176,138 @@ public class CurrencyTest extends TestFmwk {
|
|||
}
|
||||
}
|
||||
|
||||
public void TestCurrencyByDate()
|
||||
public void TestAvailableCurrencyCodes()
|
||||
{
|
||||
// local Variables
|
||||
Currency currency;
|
||||
String result;
|
||||
|
||||
// Cycle through historical currencies
|
||||
currency = Currency.getInstance(new ULocale("eo_AM"), new Date(-630720000000L));
|
||||
result = currency.getCurrencyCode();
|
||||
if (!"AMD".equals(result))
|
||||
{
|
||||
errln("didn't return AMD for eo_AM returned: " + result);
|
||||
}
|
||||
String[] currency;
|
||||
|
||||
currency = Currency.getInstance(new ULocale("eo_AM"), new Date(0L));
|
||||
result = currency.getCurrencyCode();
|
||||
if (!"SUR".equals(result))
|
||||
{
|
||||
errln("didn't return SUR for eo_AM returned: " + result);
|
||||
}
|
||||
// Cycle through historical currencies
|
||||
currency = Currency.getAvailableCurrencyCodes(new ULocale("eo_AM"), new Date(-630720000000L));
|
||||
/*
|
||||
if (currency != null)
|
||||
{
|
||||
errln("got currency");
|
||||
}
|
||||
else
|
||||
{
|
||||
errln("no currency");
|
||||
}
|
||||
if (!"AMD".equals(currency[0]))
|
||||
{
|
||||
errln("didn't return AMD for eo_AM returned: " + currency);
|
||||
}
|
||||
currency = Currency.getInstance(new ULocale("eo_AM"), new Date(0L));
|
||||
result = currency.getCurrencyCode();
|
||||
if (!"SUR".equals(result))
|
||||
{
|
||||
errln("didn't return SUR for eo_AM returned: " + result);
|
||||
}
|
||||
|
||||
currency = Currency.getInstance(new ULocale("eo_AM"), new Date(693792000000L));
|
||||
result = currency.getCurrencyCode();
|
||||
if (!"RUR".equals(result))
|
||||
{
|
||||
errln("didn't return RUR for eo_AM returned: " + result);
|
||||
}
|
||||
currency = Currency.getInstance(new ULocale("eo_AM"), new Date(693792000000L));
|
||||
result = currency.getCurrencyCode();
|
||||
if (!"RUR".equals(result))
|
||||
{
|
||||
errln("didn't return RUR for eo_AM returned: " + result);
|
||||
}
|
||||
|
||||
currency = Currency.getInstance(new ULocale("eo_AM"), new Date(977616000000L));
|
||||
result = currency.getCurrencyCode();
|
||||
if (!"AMD".equals(result))
|
||||
{
|
||||
errln("didn't return AMD for eo_AM returned: " + result);
|
||||
}
|
||||
currency = Currency.getInstance(new ULocale("eo_AM"), new Date(977616000000L));
|
||||
result = currency.getCurrencyCode();
|
||||
if (!"AMD".equals(result))
|
||||
{
|
||||
errln("didn't return AMD for eo_AM returned: " + result);
|
||||
}
|
||||
|
||||
// Locale AD has multiple currencies at once
|
||||
currency = Currency.getInstance(new ULocale("eo_AD"), new Date(977616000000L));
|
||||
result = currency.getCurrencyCode();
|
||||
if (!"EUR".equals(result))
|
||||
{
|
||||
errln("didn't return EUR for eo_AD returned: " + result);
|
||||
}
|
||||
// Locale AD has multiple currencies at once
|
||||
currency = Currency.getInstance(new ULocale("eo_AD"), new Date(977616000000L));
|
||||
result = currency.getCurrencyCode();
|
||||
if (!"EUR".equals(result))
|
||||
{
|
||||
errln("didn't return EUR for eo_AD returned: " + result);
|
||||
}
|
||||
|
||||
currency = Currency.getInstance(new ULocale("eo_AD"), new Date(0L));
|
||||
result = currency.getCurrencyCode();
|
||||
if (!"ESP".equals(result))
|
||||
{
|
||||
errln("didn't return ESP for eo_AD returned: " + result);
|
||||
}
|
||||
currency = Currency.getInstance(new ULocale("eo_AD"), new Date(0L));
|
||||
result = currency.getCurrencyCode();
|
||||
if (!"ESP".equals(result))
|
||||
{
|
||||
errln("didn't return ESP for eo_AD returned: " + result);
|
||||
}
|
||||
|
||||
// Locale UA has gap between years 1994 - 1996
|
||||
currency = Currency.getInstance(new ULocale("eo_UA"), new Date(788400000000L));
|
||||
result = currency.getCurrencyCode();
|
||||
if (!"UAH".equals(result))
|
||||
{
|
||||
errln("didn't return UAH for eo_UA returned: " + result);
|
||||
}
|
||||
// Locale UA has gap between years 1994 - 1996
|
||||
currency = Currency.getInstance(new ULocale("eo_UA"), new Date(788400000000L));
|
||||
result = currency.getCurrencyCode();
|
||||
if (!"UAH".equals(result))
|
||||
{
|
||||
errln("didn't return UAH for eo_UA returned: " + result);
|
||||
}
|
||||
|
||||
// Cycle through historical currencies
|
||||
currency = Currency.getInstance(new ULocale("eo_AO"), new Date(977616000000L));
|
||||
result = currency.getCurrencyCode();
|
||||
if (!"AOA".equals(result))
|
||||
{
|
||||
errln("didn't return AOA for eo_AO returned: " + result);
|
||||
}
|
||||
// Cycle through historical currencies
|
||||
currency = Currency.getInstance(new ULocale("eo_AO"), new Date(977616000000L));
|
||||
result = currency.getCurrencyCode();
|
||||
if (!"AOA".equals(result))
|
||||
{
|
||||
errln("didn't return AOA for eo_AO returned: " + result);
|
||||
}
|
||||
|
||||
currency = Currency.getInstance(new ULocale("eo_AO"), new Date(819936000000L));
|
||||
result = currency.getCurrencyCode();
|
||||
if (!"AOR".equals(result))
|
||||
{
|
||||
errln("didn't return AOR for eo_AO returned: " + result);
|
||||
}
|
||||
currency = Currency.getInstance(new ULocale("eo_AO"), new Date(819936000000L));
|
||||
result = currency.getCurrencyCode();
|
||||
if (!"AOR".equals(result))
|
||||
{
|
||||
errln("didn't return AOR for eo_AO returned: " + result);
|
||||
}
|
||||
|
||||
currency = Currency.getInstance(new ULocale("eo_AO"), new Date(662256000000L));
|
||||
result = currency.getCurrencyCode();
|
||||
if (!"AON".equals(result))
|
||||
{
|
||||
errln("didn't return AON for eo_AO returned: " + result);
|
||||
}
|
||||
currency = Currency.getInstance(new ULocale("eo_AO"), new Date(662256000000L));
|
||||
result = currency.getCurrencyCode();
|
||||
if (!"AON".equals(result))
|
||||
{
|
||||
errln("didn't return AON for eo_AO returned: " + result);
|
||||
}
|
||||
|
||||
currency = Currency.getInstance(new ULocale("eo_AO"), new Date(315360000000L));
|
||||
result = currency.getCurrencyCode();
|
||||
if (!"AOK".equals(result))
|
||||
{
|
||||
errln("didn't return AOK for eo_AO returned: " + result);
|
||||
}
|
||||
currency = Currency.getInstance(new ULocale("eo_AO"), new Date(315360000000L));
|
||||
result = currency.getCurrencyCode();
|
||||
if (!"AOK".equals(result))
|
||||
{
|
||||
errln("didn't return AOK for eo_AO returned: " + result);
|
||||
}
|
||||
|
||||
currency = Currency.getInstance(new ULocale("eo_AO"), new Date(0L));
|
||||
result = currency.getCurrencyCode();
|
||||
if (!"AOA".equals(result))
|
||||
{
|
||||
errln("didn't return AOA for eo_AO returned: " + result);
|
||||
}
|
||||
currency = Currency.getInstance(new ULocale("eo_AO"), new Date(0L));
|
||||
result = currency.getCurrencyCode();
|
||||
if (!"AOA".equals(result))
|
||||
{
|
||||
errln("didn't return AOA for eo_AO returned: " + result);
|
||||
}
|
||||
|
||||
// Test EURO support
|
||||
currency = Currency.getInstance(new ULocale("en_US"), new Date(System.currentTimeMillis()));
|
||||
result = currency.getCurrencyCode();
|
||||
if (!"USD".equals(result))
|
||||
{
|
||||
errln("didn't return USD for en_US returned: " + result);
|
||||
}
|
||||
// Test EURO support
|
||||
currency = Currency.getInstance(new ULocale("en_US"), new Date(System.currentTimeMillis()));
|
||||
result = currency.getCurrencyCode();
|
||||
if (!"USD".equals(result))
|
||||
{
|
||||
errln("didn't return USD for en_US returned: " + result);
|
||||
}
|
||||
|
||||
currency = Currency.getInstance(new ULocale("en_US_PREEURO"), new Date(System.currentTimeMillis()));
|
||||
result = currency.getCurrencyCode();
|
||||
if (!"USD".equals(result))
|
||||
{
|
||||
errln("didn't return USD for en_US_PREEURO returned: " + result);
|
||||
}
|
||||
currency = Currency.getInstance(new ULocale("en_US_PREEURO"), new Date(System.currentTimeMillis()));
|
||||
result = currency.getCurrencyCode();
|
||||
if (!"USD".equals(result))
|
||||
{
|
||||
errln("didn't return USD for en_US_PREEURO returned: " + result);
|
||||
}
|
||||
|
||||
currency = Currency.getInstance(new ULocale("en_US_Q"), new Date(System.currentTimeMillis()));
|
||||
result = currency.getCurrencyCode();
|
||||
if (!"USD".equals(result))
|
||||
{
|
||||
errln("didn't return USD for en_US_Q returned: " + result);
|
||||
}
|
||||
|
||||
// non-existant locale
|
||||
currency = Currency.getInstance(new ULocale("en_QQ"), new Date(System.currentTimeMillis()));
|
||||
if (currency != null)
|
||||
{
|
||||
errln("didn't return NULL for en_QQ");
|
||||
}
|
||||
currency = Currency.getInstance(new ULocale("en_US_Q"), new Date(System.currentTimeMillis()));
|
||||
result = currency.getCurrencyCode();
|
||||
if (!"USD".equals(result))
|
||||
{
|
||||
errln("didn't return USD for en_US_Q returned: " + result);
|
||||
}
|
||||
|
||||
// non-existant locale
|
||||
currency = Currency.getAvailableCurrencyCodes(new ULocale("en_QQ"), new Date(System.currentTimeMillis()));
|
||||
if (currency != null)
|
||||
{
|
||||
errln("didn't return NULL for en_QQ");
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
|
||||
public void TestDeprecatedCurrencyFormat() {
|
||||
// bug 5952
|
||||
Locale locale = new Locale("sr", "QQ");
|
||||
|
|
|
@ -121,19 +121,19 @@ public class Currency extends MeasureUnit implements Serializable {
|
|||
}
|
||||
|
||||
/**
|
||||
* Returns a currency object for the currency in the given
|
||||
* locale for the givne date.
|
||||
* Returns an array of Strings which contain the currency
|
||||
* identifiers which are valid for the given locale on the
|
||||
* given date.
|
||||
*
|
||||
* @draft ICU 4.0
|
||||
*/
|
||||
public static Currency getInstance(ULocale locale, Date date)
|
||||
public static String[] getAvailableCurrencyCodes(ULocale loc, Date d)
|
||||
{
|
||||
// local variables
|
||||
String country = locale.getCountry();
|
||||
String variant = locale.getVariant();
|
||||
boolean isPreEuro = variant.equals("PREEURO");
|
||||
boolean isEuro = variant.equals("EURO");
|
||||
long mask = 4294967295L;
|
||||
long dateL = date.getTime();
|
||||
String country = loc.getCountry();
|
||||
String variant = loc.getVariant();
|
||||
long dateL = d.getTime();
|
||||
long mask = 4294967295L;
|
||||
|
||||
// Get supplementalData
|
||||
ICUResourceBundle bundle = (ICUResourceBundle)ICUResourceBundle.getBundleInstance(ICUResourceBundle.ICU_BASE_NAME,
|
||||
|
@ -141,22 +141,68 @@ public class Currency extends MeasureUnit implements Serializable {
|
|||
ICUResourceBundle.ICU_DATA_CLASS_LOADER);
|
||||
if (bundle == null)
|
||||
{
|
||||
//throw new MissingResourceException()
|
||||
// no data
|
||||
return null;
|
||||
}
|
||||
|
||||
// Work with the supplementalData
|
||||
try
|
||||
{
|
||||
// Process each currency to see which one is valid for the given date.
|
||||
// Some regions can have more than one current currency in use for
|
||||
// a given date.
|
||||
UResourceBundle cm = bundle.get("CurrencyMap");
|
||||
UResourceBundle countryArray = cm.get(country);
|
||||
boolean matchFound = false;
|
||||
|
||||
// First pass, get a count of valid currencies
|
||||
int currCount = 0;
|
||||
for (int i = 0; i < countryArray.getSize(); i++)
|
||||
{
|
||||
// get the currency resource
|
||||
UResourceBundle currencyReq = countryArray.get(i);
|
||||
|
||||
// process each currency to see which one is valid for the given date.
|
||||
// Some regions can have more than one current currency in use for
|
||||
// a given date. In such a case, latest default currency is returned.
|
||||
int foo = countryArray.getSize();
|
||||
for (int i = 0; i < foo; i++)
|
||||
// get the from date
|
||||
long fromDate = 0;
|
||||
UResourceBundle fromRes = currencyReq.get("from");
|
||||
int[] fromArray = fromRes.getIntVector();
|
||||
fromDate = (long)fromArray[0] << 32;
|
||||
fromDate |= ((long)fromArray[1] & mask);
|
||||
|
||||
// get the to date and check the date range
|
||||
if (currencyReq.getSize() > 2)
|
||||
{
|
||||
long toDate = 0;
|
||||
UResourceBundle toRes = currencyReq.get("to");
|
||||
int[] toArray = toRes.getIntVector();
|
||||
toDate = (long)toArray[0] << 32;
|
||||
toDate |= ((long)toArray[1] & mask);
|
||||
|
||||
if ((fromDate <= dateL) && (dateL < toDate))
|
||||
{
|
||||
currCount++;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (fromDate <= dateL)
|
||||
{
|
||||
currCount++;
|
||||
}
|
||||
}
|
||||
|
||||
} // end For loop
|
||||
|
||||
// Allocate array to return
|
||||
if (currCount == 0)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
String[] currCodes = new String[currCount];
|
||||
int currIndex = 0;
|
||||
|
||||
// Second pass, get the actual currency codes
|
||||
for (int i = 0; i < countryArray.getSize(); i++)
|
||||
{
|
||||
// get the currency resource
|
||||
UResourceBundle currencyReq = countryArray.get(i);
|
||||
|
@ -179,31 +225,28 @@ public class Currency extends MeasureUnit implements Serializable {
|
|||
toDate = (long)toArray[0] << 32;
|
||||
toDate |= ((long)toArray[1] & mask);
|
||||
|
||||
if ((fromDate <= dateL) && (dateL < toDate))
|
||||
if ((fromDate <= dateL) && (dateL < toDate))
|
||||
{
|
||||
matchFound = true;
|
||||
currCodes[currIndex] = new String(curriso);
|
||||
currIndex++;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (fromDate <= dateL)
|
||||
{
|
||||
matchFound = true;
|
||||
currCodes[currIndex] = new String(curriso);
|
||||
currIndex++;
|
||||
}
|
||||
}
|
||||
|
||||
// return a match if we got it
|
||||
if ((curriso != null) && (matchFound))
|
||||
{
|
||||
return new Currency(curriso);
|
||||
}
|
||||
|
||||
} // end For loop
|
||||
|
||||
// Due to gaps in the windows of time for valid currencies,
|
||||
// it is possible that no currency is valid for the given time.
|
||||
// In such a case, use the most current value
|
||||
return getInstance(locale);
|
||||
// Process the matching ids. Due to gaps in the windows of time
|
||||
// for valid currencies, it is possible that no currency is valid
|
||||
// for the given time. It is possible that we will return multiple
|
||||
// currencies for the given time.
|
||||
return currCodes;
|
||||
}
|
||||
catch (MissingResourceException ex)
|
||||
{
|
||||
|
@ -674,7 +717,8 @@ public class Currency extends MeasureUnit implements Serializable {
|
|||
* code. This constructor assumes that the code is valid.
|
||||
*
|
||||
* @param theISOCode The iso code used to construct the currency.
|
||||
* @stable ICU 3.4
|
||||
* @draft ICU 3.4
|
||||
* @provisional This API might change or be removed in a future release.
|
||||
*/
|
||||
protected Currency(String theISOCode) {
|
||||
isoCode = theISOCode;
|
||||
|
|
Loading…
Add table
Reference in a new issue