/*
*******************************************************************************
- * Copyright (C) 2009-2010, International Business Machines Corporation and *
+ * Copyright (C) 2009-2013, International Business Machines Corporation and *
* others. All Rights Reserved. *
*******************************************************************************
*/
if (filter.from != Long.MIN_VALUE || filter.to != Long.MAX_VALUE) {
needed |= Date;
}
+ if (filter.tenderOnly) {
+ needed |= Tender;
+ }
if (needed != 0) {
if (filter.region != null) {
int needed, ICUResourceBundle b) {
String region = b.getKey();
- if ((needed & nonRegion) == 0) {
- collector.collect(b.getKey(), null, 0, 0, -1);
+ if (needed == Region) {
+ collector.collect(b.getKey(), null, 0, 0, -1, false);
return;
}
String currency = null;
long from = Long.MIN_VALUE;
long to = Long.MAX_VALUE;
+ boolean tender = true;
if ((needed & Currency) != 0) {
ICUResourceBundle currBundle = r.at("id");
}
if ((needed & Date) != 0) {
- from = getDate(r.at("from"), Long.MIN_VALUE);
- to = getDate(r.at("to"), Long.MAX_VALUE);
+ from = getDate(r.at("from"), Long.MIN_VALUE, false);
+ to = getDate(r.at("to"), Long.MAX_VALUE, true);
// In the data, to is always > from. This means that when we have a range
// from == to, the comparisons below will always do the right thing, despite
// the range being technically empty. It really should be [from, from+1) but
// this way we don't need to fiddle with it.
- if (filter.from >= to) {
+ if (filter.from > to) {
continue;
}
- if (filter.to <= from) {
+ if (filter.to < from) {
+ continue;
+ }
+ }
+ if ((needed & Tender) != 0) {
+ ICUResourceBundle tenderBundle = r.at("tender");
+ tender = tenderBundle == null || "true".equals(tenderBundle.getString());
+ if (filter.tenderOnly && !tender) {
continue;
}
}
// data lists elements in priority order, so 'i' suffices
- collector.collect(region, currency, from, to, i);
+ collector.collect(region, currency, from, to, i, tender);
}
}
private static final long MASK = 4294967295L;
- private long getDate(ICUResourceBundle b, long defaultValue) {
+ private long getDate(ICUResourceBundle b, long defaultValue, boolean endOfDay) {
if (b == null) {
return defaultValue;
}
int[] values = b.getIntVector();
- return ((long) values[0] << 32) | ((long) values[1] & MASK);
+ 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
// about duplicates.
private List<CurrencyInfo> result = new ArrayList<CurrencyInfo>();
- public void collect(String region, String currency, long from, long to, int priority) {
- result.add(new CurrencyInfo(region, currency, from, to, priority));
+ public void collect(String region, String currency, long from, long to, int priority, boolean tender) {
+ result.add(new CurrencyInfo(region, currency, from, to, priority, tender));
}
public List<CurrencyInfo> getList() {
}
public int collects() {
- return Region | Currency | Date;
+ return Everything;
}
}
private static class RegionCollector implements Collector<String> {
private final UniqueList<String> result = UniqueList.create();
- public void collect(String region, String currency, long from, long to, int priority) {
+ public void collect(
+ String region, String currency, long from, long to, int priority, boolean tender) {
result.add(region);
}
private static class CurrencyCollector implements Collector<String> {
private final UniqueList<String> result = UniqueList.create();
- public void collect(String region, String currency, long from, long to, int priority) {
+ public void collect(
+ String region, String currency, long from, long to, int priority, boolean tender) {
result.add(currency);
}
private static final int Region = 1;
private static final int Currency = 2;
private static final int Date = 4;
-
- private static final int nonRegion = Currency | Date;
+ private static final int Tender = 8;
+ private static final int Everything = Integer.MAX_VALUE;
private static interface Collector<T> {
/**
* @param from start time (0 if ignored)
* @param to end time (0 if ignored)
* @param priority priority (-1 if ignored)
+ * @param tender true if currency is legal tender.
*/
- void collect(String region, String currency, long from, long to, int priority);
+ void collect(String region, String currency, long from, long to, int priority, boolean tender);
/**
* Return the list of unique items in the order in which we encountered them for the