public class Currency extends MeasureUnit implements Serializable
Note: This class deliberately resembles java.util.Currency but it has a completely independent implementation, and adds features not present in the JDK.
Modifier and Type | Field and Description |
---|---|
static int |
LONG_NAME
Selector for ucurr_getName indicating the long name for a
currency, such as "US Dollar" for USD.
|
static int |
PLURAL_LONG_NAME
Selector for getName() indicating the plural long name for a
currency, such as "US dollar" for USD in "1 US dollar",
and "US dollars" for USD in "2 US dollars".
|
static int |
SYMBOL_NAME
Selector for getName() indicating a symbolic name for a
currency, such as "$" for USD.
|
Modifier | Constructor and Description |
---|---|
protected |
Currency(String theISOCode)
Constructs a currency object for the given ISO 4217 3-letter
code.
|
Modifier and Type | Method and Description |
---|---|
boolean |
equals(Object rhs)
Return true if rhs is a Currency instance,
is non-null, and has the same currency code.
|
static String[] |
getAvailableCurrencyCodes(ULocale loc,
Date d)
Returns an array of Strings which contain the currency
identifiers that are valid for the given locale on the
given date.
|
static Locale[] |
getAvailableLocales()
Return an array of the locales for which a currency
is defined.
|
static ULocale[] |
getAvailableULocales()
Return an array of the ulocales for which a currency
is defined.
|
String |
getCurrencyCode()
Returns the ISO 4217 3-letter code for this currency object.
|
int |
getDefaultFractionDigits()
Returns the number of the number of fraction digits that should
be displayed for this currency.
|
static Currency |
getInstance(Locale locale)
Returns a currency object for the default currency in the given
locale.
|
static Currency |
getInstance(String theISOCode)
Returns a currency object given an ISO 4217 3-letter code.
|
static Currency |
getInstance(ULocale locale)
Returns a currency object for the default currency in the given
locale.
|
static String[] |
getKeywordValuesForLocale(String key,
ULocale locale,
boolean commonlyUsed)
Given a key and a locale, returns an array of values for the key for which data
exists.
|
ULocale |
getLocale(ULocale.Type type)
Deprecated.
This API is obsolete.
|
String |
getName(Locale locale,
int nameStyle,
boolean[] isChoiceFormat)
Returns the display name for the given currency in the
given locale.
|
String |
getName(Locale locale,
int nameStyle,
String pluralCount,
boolean[] isChoiceFormat)
Returns the display name for the given currency in the given locale.
|
String |
getName(ULocale locale,
int nameStyle,
boolean[] isChoiceFormat)
Returns the display name for the given currency in the
given locale.
|
String |
getName(ULocale locale,
int nameStyle,
String pluralCount,
boolean[] isChoiceFormat)
Returns the display name for the given currency in the
given locale.
|
double |
getRoundingIncrement()
Returns the rounding increment for this currency, or 0.0 if no
rounding is done by this currency.
|
String |
getSymbol()
Convenience and compatibility override of getName that
requests the symbol name for the default
DISPLAY locale. |
String |
getSymbol(Locale loc)
Convenience and compatibility override of getName that
requests the symbol name.
|
String |
getSymbol(ULocale uloc)
Convenience and compatibility override of getName that
requests the symbol name.
|
int |
hashCode()
Return a hashcode for this currency.
|
static String |
parse(ULocale locale,
String text,
int type,
ParsePosition pos)
Deprecated.
This API is ICU internal only.
|
static Object |
registerInstance(Currency currency,
ULocale locale)
Registers a new currency for the provided locale.
|
String |
toString()
Returns the ISO 4217 code for this currency.
|
static boolean |
unregister(Object registryKey)
Unregister the currency associated with this key (obtained from
registerInstance).
|
public static final int SYMBOL_NAME
public static final int LONG_NAME
public static final int PLURAL_LONG_NAME
protected Currency(String theISOCode)
theISOCode
- The iso code used to construct the currency.public static Currency getInstance(Locale locale)
locale
- the localepublic static Currency getInstance(ULocale locale)
public static String[] getAvailableCurrencyCodes(ULocale loc, Date d)
loc
- the locale for which to retrieve currency codes.d
- the date for which to retrieve currency codes for the given locale.public static Currency getInstance(String theISOCode)
theISOCode
- the iso codeNullPointerException
- if theISOCode
is null.IllegalArgumentException
- if theISOCode
is not a
3-letter alpha code.public static Object registerInstance(Currency currency, ULocale locale)
currency
- the currency to registerlocale
- the ulocale under which to register the currencyunregister(java.lang.Object)
public static boolean unregister(Object registryKey)
registryKey
- the registry key returned from registerInstanceregisterInstance(com.ibm.icu.util.Currency, com.ibm.icu.util.ULocale)
public static Locale[] getAvailableLocales()
public static ULocale[] getAvailableULocales()
public static final String[] getKeywordValuesForLocale(String key, ULocale locale, boolean commonlyUsed)
The only supported key is "currency", other values return an empty array.
Currency information is based on the region of the locale. If the locale does not
indicate a region, ULocale.addLikelySubtags(ULocale)
is used to infer a region,
except for the 'und' locale.
If commonlyUsed is true, only the currencies known to be in use as of the current date are returned. When there are more than one, these are returned in preference order (typically, this occurs when a country is transitioning to a new currency, and the newer currency is preferred), see Unicode TR#35 Sec. C1. If commonlyUsed is false, all currencies ever used in any locale are returned, in no particular order.
key
- key whose values to look up. the only recognized key is "currency"locale
- the localecommonlyUsed
- if true, return only values that are currently used in the locale.
Otherwise returns all values.public int hashCode()
public boolean equals(Object rhs)
public String getCurrencyCode()
public String getSymbol()
DISPLAY
locale.getName(java.util.Locale, int, boolean[])
,
ULocale.Category.DISPLAY
public String getSymbol(Locale loc)
loc
- the Locale for the symbolgetName(java.util.Locale, int, boolean[])
public String getSymbol(ULocale uloc)
uloc
- the ULocale for the symbolgetName(java.util.Locale, int, boolean[])
public String getName(Locale locale, int nameStyle, boolean[] isChoiceFormat)
public String getName(ULocale locale, int nameStyle, boolean[] isChoiceFormat)
locale
- locale in which to display currencynameStyle
- selector for which kind of name to return.
The nameStyle should be either SYMBOL_NAME or
LONG_NAME. Otherwise, throw IllegalArgumentException.isChoiceFormat
- fill-in; isChoiceFormat[0] is set to true
if the returned value is a ChoiceFormat pattern; otherwise it
is set to falseIllegalArgumentException
- if the nameStyle is not SYMBOL_NAME
or LONG_NAME.getName(ULocale, int, String, boolean[])
public String getName(Locale locale, int nameStyle, String pluralCount, boolean[] isChoiceFormat)
public String getName(ULocale locale, int nameStyle, String pluralCount, boolean[] isChoiceFormat)
locale
- locale in which to display currencynameStyle
- selector for which kind of name to returnpluralCount
- plural count string for this localeisChoiceFormat
- fill-in; isChoiceFormat[0] is set to true
if the returned value is a ChoiceFormat pattern; otherwise it
is set to falseIllegalArgumentException
- if the nameStyle is not SYMBOL_NAME,
LONG_NAME, or PLURAL_LONG_NAME.public static String parse(ULocale locale, String text, int type, ParsePosition pos)
locale
- the locale of the display names to matchtext
- the text to parsetype
- parse against currency type: LONG_NAME only or notpos
- input-output position; on input, the position within
text to match; must have 0 <= pos.getIndex() < text.length();
on output, the position after the last matched character. If
the parse fails, the position in unchanged upon output.public int getDefaultFractionDigits()
public double getRoundingIncrement()
public String toString()
public final ULocale getLocale(ULocale.Type type)
Note: This method will be obsoleted. The implementation is no longer locale-specific and so there is no longer a valid or actual locale associated with the Currency object. Until it is removed, this method will return the root locale.
type
- type of information requested, either ULocale.VALID_LOCALE
or ULocale.ACTUAL_LOCALE
.ULocale
,
ULocale.VALID_LOCALE
,
ULocale.ACTUAL_LOCALE
Copyright (c) 2011 IBM Corporation and others.