| Method from java.util.Currency Detail: |
public static Set<Currency> getAvailableCurrencies() {
synchronized(Currency.class) {
if (available == null) {
available = new HashSet< Currency >(256);
// Add simple currencies first
for (char c1 = 'A'; c1 < = 'Z'; c1 ++) {
for (char c2 = 'A'; c2 < = 'Z'; c2 ++) {
int tableEntry = getMainTableEntry(c1, c2);
if ((tableEntry & COUNTRY_TYPE_MASK) == SIMPLE_CASE_COUNTRY_MASK
&& tableEntry != INVALID_COUNTRY_ENTRY) {
char finalChar = (char) ((tableEntry & SIMPLE_CASE_COUNTRY_FINAL_CHAR_MASK) + 'A');
int defaultFractionDigits = (tableEntry & SIMPLE_CASE_COUNTRY_DEFAULT_DIGITS_MASK) > > SIMPLE_CASE_COUNTRY_DEFAULT_DIGITS_SHIFT;
int numericCode = (tableEntry & NUMERIC_CODE_MASK) > > NUMERIC_CODE_SHIFT;
StringBuilder sb = new StringBuilder();
sb.append(c1);
sb.append(c2);
sb.append(finalChar);
available.add(getInstance(sb.toString(), defaultFractionDigits, numericCode));
}
}
}
// Now add other currencies
StringTokenizer st = new StringTokenizer(otherCurrencies, "-");
while (st.hasMoreElements()) {
available.add(getInstance((String)st.nextElement()));
}
}
}
return (Set< Currency >) available.clone();
}
Gets the set of available currencies. The returned set of currencies
contains all of the available currencies, which may include currencies
that represent obsolete ISO 4217 codes. The set can be modified
without affecting the available currencies in the runtime. |
public String getCurrencyCode() {
return currencyCode;
}
Gets the ISO 4217 currency code of this currency. |
public int getDefaultFractionDigits() {
return defaultFractionDigits;
}
Gets the default number of fraction digits used with this currency.
For example, the default number of fraction digits for the Euro is 2,
while for the Japanese Yen it's 0.
In the case of pseudo-currencies, such as IMF Special Drawing Rights,
-1 is returned. |
public String getDisplayName() {
return getDisplayName(Locale.getDefault(Locale.Category.DISPLAY));
}
Gets the name that is suitable for displaying this currency for
the default locale. If there is no suitable display name found
for the default locale, the ISO 4217 currency code is returned. |
public String getDisplayName(Locale locale) {
try {
OpenListResourceBundle bundle = LocaleData.getCurrencyNames(locale);
String result = null;
String bundleKey = currencyCode.toLowerCase(Locale.ROOT);
// Check whether a provider can provide an implementation that's closer
// to the requested locale than what the Java runtime itself can provide.
LocaleServiceProviderPool pool =
LocaleServiceProviderPool.getPool(CurrencyNameProvider.class);
if (pool.hasProviders()) {
result = pool.getLocalizedObject(
CurrencyNameGetter.INSTANCE,
locale, bundleKey, bundle, currencyCode, DISPLAYNAME);
}
if (result == null) {
result = bundle.getString(bundleKey);
}
if (result != null) {
return result;
}
} catch (MissingResourceException e) {
// fall through
}
// use currency code as symbol of last resort
return currencyCode;
}
Gets the name that is suitable for displaying this currency for
the specified locale. If there is no suitable display name found
for the specified locale, the ISO 4217 currency code is returned. |
public static Currency getInstance(String currencyCode) {
return getInstance(currencyCode, Integer.MIN_VALUE, 0);
}
Returns the Currency instance for the given currency code. |
public static Currency getInstance(Locale locale) {
String country = locale.getCountry();
if (country == null) {
throw new NullPointerException();
}
if (country.length() != 2) {
throw new IllegalArgumentException();
}
char char1 = country.charAt(0);
char char2 = country.charAt(1);
int tableEntry = getMainTableEntry(char1, char2);
if ((tableEntry & COUNTRY_TYPE_MASK) == SIMPLE_CASE_COUNTRY_MASK
&& tableEntry != INVALID_COUNTRY_ENTRY) {
char finalChar = (char) ((tableEntry & SIMPLE_CASE_COUNTRY_FINAL_CHAR_MASK) + 'A');
int defaultFractionDigits = (tableEntry & SIMPLE_CASE_COUNTRY_DEFAULT_DIGITS_MASK) > > SIMPLE_CASE_COUNTRY_DEFAULT_DIGITS_SHIFT;
int numericCode = (tableEntry & NUMERIC_CODE_MASK) > > NUMERIC_CODE_SHIFT;
StringBuffer sb = new StringBuffer(country);
sb.append(finalChar);
return getInstance(sb.toString(), defaultFractionDigits, numericCode);
} else {
// special cases
if (tableEntry == INVALID_COUNTRY_ENTRY) {
throw new IllegalArgumentException();
}
if (tableEntry == COUNTRY_WITHOUT_CURRENCY_ENTRY) {
return null;
} else {
int index = (tableEntry & SPECIAL_CASE_COUNTRY_INDEX_MASK) - SPECIAL_CASE_COUNTRY_INDEX_DELTA;
if (scCutOverTimes[index] == Long.MAX_VALUE || System.currentTimeMillis() < scCutOverTimes[index]) {
return getInstance(scOldCurrencies[index], scOldCurrenciesDFD[index],
scOldCurrenciesNumericCode[index]);
} else {
return getInstance(scNewCurrencies[index], scNewCurrenciesDFD[index],
scNewCurrenciesNumericCode[index]);
}
}
}
}
Returns the Currency instance for the country of the
given locale. The language and variant components of the locale
are ignored. The result may vary over time, as countries change their
currencies. For example, for the original member countries of the
European Monetary Union, the method returns the old national currencies
until December 31, 2001, and the Euro from January 1, 2002, local time
of the respective countries.
The method returns null for territories that don't
have a currency, such as Antarctica. |
public int getNumericCode() {
return numericCode;
}
Returns the ISO 4217 numeric code of this currency. |
public String getSymbol() {
return getSymbol(Locale.getDefault(Locale.Category.DISPLAY));
}
Gets the symbol of this currency for the default locale.
For example, for the US Dollar, the symbol is "$" if the default
locale is the US, while for other locales it may be "US$". If no
symbol can be determined, the ISO 4217 currency code is returned. |
public String getSymbol(Locale locale) {
try {
// Check whether a provider can provide an implementation that's closer
// to the requested locale than what the Java runtime itself can provide.
LocaleServiceProviderPool pool =
LocaleServiceProviderPool.getPool(CurrencyNameProvider.class);
if (pool.hasProviders()) {
// Assuming that all the country locales include necessary currency
// symbols in the Java runtime's resources, so there is no need to
// examine whether Java runtime's currency resource bundle is missing
// names. Therefore, no resource bundle is provided for calling this
// method.
String symbol = pool.getLocalizedObject(
CurrencyNameGetter.INSTANCE,
locale, (OpenListResourceBundle)null,
currencyCode, SYMBOL);
if (symbol != null) {
return symbol;
}
}
ResourceBundle bundle = LocaleData.getCurrencyNames(locale);
return bundle.getString(currencyCode);
} catch (MissingResourceException e) {
// use currency code as symbol of last resort
return currencyCode;
}
}
Gets the symbol of this currency for the specified locale.
For example, for the US Dollar, the symbol is "$" if the specified
locale is the US, while for other locales it may be "US$". If no
symbol can be determined, the ISO 4217 currency code is returned. |
public String toString() {
return currencyCode;
}
Returns the ISO 4217 currency code of this currency. |