import com.ibm.icu.text.CurrencyMetaInfo;
import com.ibm.icu.text.CurrencyMetaInfo.CurrencyDigits;
import com.ibm.icu.text.CurrencyMetaInfo.CurrencyFilter;
+import com.ibm.icu.text.CurrencyMetaInfo.CurrencyInfo;
import com.ibm.icu.util.ULocale.Category;
/**
* @stable ICU 4.0
*/
public static String[] getAvailableCurrencyCodes(ULocale loc, Date d) {
- CurrencyMetaInfo info = CurrencyMetaInfo.getInstance();
CurrencyFilter filter = CurrencyFilter.onDate(d).withRegion(loc.getCountry());
- List<String> list = info.currencies(filter);
+ List<String> list = getTenderCurrencies(filter);
// Note: Prior to 4.4 the spec didn't say that we return null if there are no results, but
// the test assumed it did. Kept the behavior and amended the spec.
if (list.isEmpty()) {
return EMPTY_STRING_ARRAY;
}
- CurrencyMetaInfo info = CurrencyMetaInfo.getInstance();
if (!commonlyUsed) {
// Behavior change from 4.3.3, no longer sort the currencies
return getAvailableCurrencyCodes().toArray(new String[0]);
// currencies are in region's preferred order when we're filtering on region, which
// matches our spec
- List<String> result = info.currencies(filter);
+ List<String> result = getTenderCurrencies(filter);
// No fallback anymore (change from 4.3.3)
if (result.size() == 0) {
private static SoftReference<List<String>> ALL_CODES;
/*
- * Returns an unmodifiable String list including all known currency codes
+ * Returns an unmodifiable String list including all known tender currency codes.
*/
private static synchronized List<String> getAvailableCurrencyCodes() {
List<String> all = (ALL_CODES == null) ? null : ALL_CODES.get();
if (all == null) {
- CurrencyMetaInfo info = CurrencyMetaInfo.getInstance();
// Filter out non-tender currencies which have "from" date set to 9999-12-31
// CurrencyFilter has "to" value set to 9998-12-31 in order to exclude them
- CurrencyFilter filter = CurrencyFilter.onDateRange(null, new Date(253373299200000L));
- all = Collections.unmodifiableList(info.currencies(filter));
+ //CurrencyFilter filter = CurrencyFilter.onDateRange(null, new Date(253373299200000L));
+ CurrencyFilter filter = CurrencyFilter.all();
+ all = Collections.unmodifiableList(getTenderCurrencies(filter));
ALL_CODES = new SoftReference<List<String>>(all);
}
return all;
List<String> allActive = info.currencies(CurrencyFilter.onDateRange(from, to));
return allActive.contains(code);
}
+
+ /**
+ * Returns the list of remaining tender currencies after a filter is applied.
+ * @param filter the filter to apply to the tender currencies
+ * @return a list of tender currencies
+ */
+ private static List<String> getTenderCurrencies(CurrencyFilter filter) {
+ CurrencyMetaInfo info = CurrencyMetaInfo.getInstance();
+ List<CurrencyInfo> infoList = info.currencyInfo(filter);
+ List<String> list = new ArrayList<String>();
+ for (CurrencyInfo currencyInfo : infoList) {
+ // Non-tender currencies always have a from of MIN_VALUE and a to of MAX_VALUE, so
+ // exclude them.
+ if (currencyInfo.from != Long.MIN_VALUE || currencyInfo.to != Long.MAX_VALUE) {
+ list.add(currencyInfo.code);
+ }
+ }
+ return list;
+ }
}
//eof
return defaultValue;
}
int[] values = b.getIntVector();
- long time = ((long) values[0] << 32) | (((long) values[1]) & MASK);
-
- // TODO: remove once errors in CLDR data are fixed. Or push this into ICU data generation.
- // The CLDR data parses month as minutes. We should be getting minutes = 0, so if we detect
- // that the minute value is nonzero, this means we have bad data and the minute value is really
- // the month value.
- GregorianCalendar cal = new GregorianCalendar();
- cal.setTimeZone(TimeZone.getTimeZone("GMT"));
- cal.setTimeInMillis(time);
- int minute = cal.get(Calendar.MINUTE);
- if (minute != 0) {
- cal.set(Calendar.MINUTE, 0);
- cal.set(Calendar.MONTH, minute - 1); // months are 1-based
- time = cal.getTimeInMillis();
- }
- // TODO: generate in CLDR data rather than here, remove endOfDay flag.
- if (endOfDay) {
- cal.set(Calendar.HOUR_OF_DAY, 23);
- cal.set(Calendar.MINUTE, 59);
- cal.set(Calendar.SECOND, 59);
- cal.set(Calendar.MILLISECOND, 999);
- time = cal.getTimeInMillis();
- }
- return time;
+ return ((long) values[0] << 32) | (((long) values[1]) & MASK);
}
// Utility, just because I don't like the n^2 behavior of using list.contains to build a