ICU-7277 tag cleanup to APIs

X-SVN-Rev: 27151
This commit is contained in:
Doug Felt 2010-01-06 22:15:27 +00:00
parent 994193ba79
commit 01e49d7279
2 changed files with 121 additions and 62 deletions

View file

@ -1,6 +1,6 @@
/*
*******************************************************************************
* Copyright (C) 2009, International Business Machines Corporation and *
* Copyright (C) 2009-2010, International Business Machines Corporation and *
* others. All Rights Reserved. *
*******************************************************************************
*/
@ -10,65 +10,83 @@ import com.ibm.icu.util.ULocale;
import java.util.Map;
/**
* Returns information about currency display names in a locale.
* Returns currency names localized for a locale.
* @draft ICU 4.4
*/
public abstract class CurrencyDisplayNames {
/**
* Return an instance of CurrencyDisplayNames that provides information
* Return an instance of CurrencyDisplayNames that provides information
* localized for display in the provided locale.
* @param locale the locale into which to localize the names
* @return a CurrencyDisplayNames
* @draft ICU 4.4
*/
public static CurrencyDisplayNames getInstance(ULocale locale) {
return CurrencyData.provider.getInstance(locale, true);
}
/**
* Returns true if currency display name data is available.
* @return true if currency display name data is available.
* @return true if currency display name data is available
* @draft ICU 4.4
*/
public static boolean hasData() {
return CurrencyData.provider.hasData();
}
/**
* Returns the locale used to determine how to translate the currency names.
* This is not necessarily the same locale passed to {@link #getInstance(Ulocale)}.
* If hasData is false, returns {@link com.ibm.icu.util.ULocale#ROOT}.
* @return the display locale
* @draft ICU 4.4
*/
public abstract ULocale getLocale();
/**
* Returns the symbol for the currency with the provided ISO code.
* If hasData is false, returns the provided ISO code.
* @param isoCode the three-letter ISO code.
* @return the display name.
* @draft ICU 4.4
*/
public abstract String getSymbol(String isoCode);
/**
* Returns the 'long name' for the currency with the provided ISO code.
* If hasData is false, returns the provided ISO code.
* @param isoCode the three-letter ISO code
* @return the display name
* @draft ICU 4.4
*/
public abstract String getName(String isoCode);
/**
* Returns a 'plural name' for the currency with the provided ISO code corresponding to
* the pluralKey.
* the pluralKey. If hasData is false, returns the provided ISO code.
* @param isoCode the three-letter ISO code
* @param pluralKey the plural key, for example "one", "other"
* @return the display name
* @see com.ibm.icu.text.PluralRules
* @draft ICU 4.4
*/
public abstract String getPluralName(String isoCode, String pluralKey);
/**
* Returns a mapping from localized symbols and currency codes to currency codes.
* If hasData is false, returns an empty map.
* The returned map is unmodifiable.
* @return the map
* @draft ICU 4.4
*/
public abstract Map<String, String> symbolMap();
/**
* Returns a mapping from localized names (standard and plural) to currency codes.
* If hasData is false, returns an empty map.
* The returned map is unmodifiable.
* @return the map
* @draft ICU 4.4
*/
public abstract Map<String, String> nameMap();
}

View file

@ -1,6 +1,6 @@
/*
*******************************************************************************
* Copyright (C) 2009, International Business Machines Corporation and *
* Copyright (C) 2009-2010, International Business Machines Corporation and *
* others. All Rights Reserved. *
*******************************************************************************
*/
@ -15,120 +15,135 @@ import com.ibm.icu.util.Calendar;
import com.ibm.icu.util.GregorianCalendar;
/**
* Represents information about currencies common to all locales.
* Provides information about currencies that is not specific to a locale.
* @draft ICU 4.4
*/
public class CurrencyMetaInfo {
private static final CurrencyMetaInfo impl;
private static final boolean hasData;
/**
* Returns the unique instance of the currency meta info. This information is shared
* across locales.
* Returns the unique instance of the currency meta info.
* @return the meta info
* @draft ICU 4.4
*/
public static CurrencyMetaInfo getInstance() {
return impl;
}
/**
* Returns true if there is actual data for the currency meta info, false if the info
* is not available (values returned will be defaults).
* Returns true if there is data for the currency meta info.
* @return true if there is actual data
* @draft ICU 4.4
*/
public static boolean hasData() {
return hasData;
}
/**
* Subclass constructor.
* @internal
*/
protected CurrencyMetaInfo() {
}
/**
* A filter used to select which currency info is returned, and the ordering of the info.
* A filter used to select which currency info is returned.
* @draft ICU 4.4
*/
public static final class CurrencyFilter {
/**
* The region to filter on. If null, accepts any region.
* @draft ICU 4.4
*/
public final String region;
/**
* The currency to filter on. If null, accepts any currency.
* @draft ICU 4.4
*/
public final String currency;
/**
* The from date to filter on (milliseconds). Accepts any currency on or after this date.
* @draft ICU 4.4
*/
public final long from;
/**
* The to date to filter on (milliseconds). Accepts any currency on or before this date.
* @draft ICU 4.4
*/
public final long to;
private CurrencyFilter (String region, String currency, long from, long to) {
private CurrencyFilter(String region, String currency, long from, long to) {
this.region = region;
this.currency = currency;
this.from = from;
this.to = to;
}
private CurrencyFilter (String region, String currency, Date dateFrom, Date dateTo) {
private CurrencyFilter(String region, String currency, Date dateFrom, Date dateTo) {
this.region = region;
this.currency = currency;
this.from = dateFrom == null ? Long.MIN_VALUE : dateFrom.getTime();
this.to = dateTo == null ? Long.MAX_VALUE : dateTo.getTime();
}
private static CurrencyFilter ALL = new CurrencyFilter(null, null, null, null);
private static final CurrencyFilter ALL = new CurrencyFilter(null, null, null, null);
/**
* Returns a filter that accepts all currency data.
* @return a filter
* @draft ICU 4.4
*/
public static CurrencyFilter all() {
return ALL;
}
/**
* Returns a filter that accepts all currencies in use as of the current date.
* @return a filter
* @see #withDate(Date)
* @draft ICU 4.4
*/
public static CurrencyFilter now() {
return ALL.withDate(new Date());
}
/**
* Returns a filter that accepts all currencies ever used in the given region.
* @param region the region code
* @return a filter
* @see #withRegion(String)
* @draft ICU 4.4
*/
public static CurrencyFilter onRegion(String region) {
return ALL.withRegion(region);
}
/**
* Returns a filter that accepts the given currency.
* @param currency the currency code
* @return a filter
* @see #withCurrency(String)
* @draft ICU 4.4
*/
public static CurrencyFilter onCurrency(String currency) {
return ALL.withCurrency(currency);
}
/**
* Returns a filter that accepts all currencies in use on the given date.
* @param date the date
* @return a filter
* @see #withDate(Date)
* @draft ICU 4.4
*/
public static CurrencyFilter onDate(Date date) {
return ALL.withDate(date);
}
/**
* Returns a filter that accepts all currencies that were in use at some point between
* the given dates, or if dates are equal, currencies in use on that date.
@ -137,73 +152,79 @@ public class CurrencyMetaInfo {
* the date on which a currency must have been in use
* @return a filter
* @see #withRange(Date, Date)
* @draft ICU 4.4
*/
public static CurrencyFilter onRange(Date from, Date to) {
return ALL.withRange(from, to);
}
/**
* Returns a copy of this filter, with the specified region. Region can be null to
* indicate no filter on region.
* @param region the region code
* @return the filter
* @see #onRegion(String)
* @draft ICU 4.4
*/
public CurrencyFilter withRegion(String region) {
return new CurrencyFilter(region, this.currency, this.from, this.to);
}
/**
* Returns a copy of this filter, with the specified currency. Currency can be null to
* indicate no filter on currency.
* @param currency the currency code
* @return the filter
* @see #onCurrency(String)
* @draft ICU 4.4
*/
public CurrencyFilter withCurrency(String currency) {
return new CurrencyFilter(this.region, currency, this.from, this.to);
}
/**
* Returns a copy of this filter, with from and to set to the given date.
* @param date the date on which the currency must have been in use
* @return the filter
* @see #onDate(Date)
* @draft ICU 4.4
*/
public CurrencyFilter withDate(Date date) {
return new CurrencyFilter(this.region, this.currency, date, date);
}
/**
* Returns a copy of this filter, with from and to set to the given dates.
* @param from date on or after which the currency must have been in use
* @param to date before which the currency must have been in use
* @return the filter
* @see #onRange(Date, Date)
* @draft ICU 4.4
*/
public CurrencyFilter withRange(Date from, Date to) {
return new CurrencyFilter(this.region, this.currency, from, to);
}
@Override
public boolean equals(Object rhs) {
return rhs instanceof CurrencyFilter &&
equals((CurrencyFilter) rhs);
}
/**
* Type-safe override of {@link #equals(Object)}.
* @param rhs the currency filter to compare to
* @return true if the filters are equal
* @draft ICU 4.4
*/
public boolean equals(CurrencyFilter rhs) {
return this == rhs || (rhs != null &&
return this == rhs || (rhs != null &&
equals(this.region, rhs.region) &&
equals(this.currency, rhs.currency) &&
this.from == rhs.from &&
this.to == rhs.to);
}
@Override
public int hashCode() {
int hc = 0;
@ -219,7 +240,7 @@ public class CurrencyMetaInfo {
hc = hc * 31 + (int) (to >>> 32);
return hc;
}
/**
* Return a string representing the filter, for debugging.
*/
@ -227,22 +248,25 @@ public class CurrencyMetaInfo {
public String toString() {
return debugString(this);
}
private static boolean equals(String lhs, String rhs) {
return lhs == rhs || (lhs != null && lhs.equals(rhs));
}
}
/**
/**
* Represents the raw information about fraction digits and rounding increment.
* @draft ICU 4.4
*/
public static final class CurrencyDigits {
/**
* Number of fraction digits used to display this currency.
* @draft ICU 4.4
*/
public final byte fractionDigits;
/**
* Rounding increment used when displaying this currency.
* @draft ICU 4.4
*/
public final byte roundingIncrement;
@ -250,12 +274,13 @@ public class CurrencyMetaInfo {
* Constructor for CurrencyDigits.
* @param fractionDigits the fraction digits
* @param roundingIncrement the rounding increment
* @draft ICU 4.4
*/
public CurrencyDigits(int fractionDigits, int roundingIncrement) {
this.fractionDigits = (byte) fractionDigits;
this.roundingIncrement = (byte) roundingIncrement;
}
/**
* Returns a string representing the currency digits, for debugging.
*/
@ -264,37 +289,47 @@ public class CurrencyMetaInfo {
return debugString(this);
}
}
/**
* Represents a complete currency info record listing the region, currency, from and to dates,
* and priority.
* @draft ICU 4.4
*/
public static final class CurrencyInfo {
/**
* Region code where currency is used.
* @draft ICU 4.4
*/
public final String region;
/**
* The three-letter ISO currency code.
* @draft ICU 4.4
*/
public final String code;
/**
* Date on which the currency was first officially used in the region. If there is no
* date, this is Long.MIN_VALUE;
* @draft ICU 4.4
*/
public final long from;
/**
* Date at which the currency stopped being officially used in the region. If there is
* no date, this is Long.MAX_VALUE;
* @draft ICU 4.4
*/
public final long to;
/**
* Preference order of currencies being used at the same time in the region. Lower
* values are preferred (generally, this is a transition from an older to a newer
* values are preferred (generally, this is a transition from an older to a newer
* currency). Priorities within a single country are unique.
* @draft ICU 4.4
*/
public final short priority;
/**
* Constructs a currency info.
* @param region region code
@ -302,6 +337,7 @@ public class CurrencyMetaInfo {
* @param from start date in milliseconds
* @param to end date in milliseconds
* @param priority priority value, 0 is highest priority, increasing values are lower
* @draft ICU 4.4
*/
public CurrencyInfo(String region, String code, long from, long to, int priority) {
this.region = region;
@ -310,7 +346,7 @@ public class CurrencyMetaInfo {
this.to = to;
this.priority = (short) priority;
}
/**
* Returns a string useful for debugging.
*/
@ -319,18 +355,19 @@ public class CurrencyMetaInfo {
return debugString(this);
}
}
/**
* Returns the list of CurrencyInfos matching the provided filter. Results
* Returns the list of CurrencyInfos matching the provided filter. Results
* are ordered by country code, then by highest to lowest priority (0 is highest).
* The returned list is unmodifiable.
* @param filter the filter to control which currency info to return
* @return the matching information
* @draft ICU 4.4
*/
public List<CurrencyInfo> currencyInfo(CurrencyFilter filter) {
return Collections.emptyList();
}
/**
* Returns the list of currency codes matching the provided filter.
* Results are ordered as in {@link #currencyInfo(CurrencyFilter)}.
@ -338,11 +375,12 @@ public class CurrencyMetaInfo {
* @param filter the filter to control which currencies to return. If filter is null,
* returns all currencies for which information is available.
* @return the matching currency codes
* @draft ICU 4.4
*/
public List<String> currencies(CurrencyFilter filter) {
return Collections.emptyList();
}
/**
* Returns the list of region codes matching the provided filter.
* Results are ordered as in {@link #currencyInfo(CurrencyFilter)}.
@ -350,22 +388,25 @@ public class CurrencyMetaInfo {
* @param filter the filter to control which regions to return. If filter is null,
* returns all regions for which information is available.
* @return the matching region codes
* @draft ICU 4.4
*/
public List<String> regions(CurrencyFilter filter) {
return Collections.emptyList();
}
/**
* Returns the CurrencyDigits for the currency code.
* @param isoCode the currency code
* @return the CurrencyDigits
* @draft ICU 4.4
*/
public CurrencyDigits currencyDigits(String isoCode) {
return defaultDigits;
}
/** @internal */
protected static final CurrencyDigits defaultDigits = new CurrencyDigits(2, 0);
static {
CurrencyMetaInfo temp = null;
boolean tempHasData = false;
@ -379,17 +420,17 @@ public class CurrencyMetaInfo {
impl = temp;
hasData = tempHasData;
}
private static String dateString(long date) {
if (date == Long.MAX_VALUE || date == Long.MIN_VALUE) {
return null;
}
GregorianCalendar gc = new GregorianCalendar();
gc.setTimeInMillis(date);
return "" + gc.get(Calendar.YEAR) + '-' + (gc.get(Calendar.MONTH) + 1) + '-' +
return "" + gc.get(Calendar.YEAR) + '-' + (gc.get(Calendar.MONTH) + 1) + '-' +
gc.get(Calendar.DAY_OF_MONTH);
}
private static String debugString(Object o) {
StringBuilder sb = new StringBuilder();
try {