- java.lang.Object
-
- java.lang.Enum<CurrencyUtils>
-
- com.erudika.para.core.i18n.CurrencyUtils
-
- All Implemented Interfaces:
Serializable,Comparable<CurrencyUtils>
public enum CurrencyUtils extends Enum<CurrencyUtils>
Helper utility class for currency operations.- Author:
- Alex Bogdanovski [alex@erudika.com]
-
-
Enum Constant Summary
Enum Constants Enum Constant Description INSTANCESingleton.
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description abstract StringformatPrice(Double price, String cur)Formats a price for its specific locale, depending on the currency code.abstract Map<String,String>getCurrenciesMap()Returns a map of all available currencies in the form: currency code - full currency name and symbol.abstract CurrencygetCurrency(String cur)Returns the currency instance for a given currency code.abstract CurrencygetCurrency(Locale loc)Returns the currency instance for a given locale.abstract StringgetCurrencyName(String cur, Locale locale)Returns the full name of the currency in the language of the given locale.static CurrencyUtilsgetInstance()Returns an instance of this class.abstract LocalegetLocaleForCountry(String countryCode)Returns the locale for a given country code.abstract booleanisValidCurrency(String cur)Validate the currency code.static CurrencyUtilsvalueOf(String name)Returns the enum constant of this type with the specified name.static CurrencyUtils[]values()Returns an array containing the constants of this enum type, in the order they are declared.
-
-
-
Enum Constant Detail
-
INSTANCE
public static final CurrencyUtils INSTANCE
Singleton.
-
-
Method Detail
-
values
public static CurrencyUtils[] values()
Returns an array containing the constants of this enum type, in the order they are declared. This method may be used to iterate over the constants as follows:for (CurrencyUtils c : CurrencyUtils.values()) System.out.println(c);
- Returns:
- an array containing the constants of this enum type, in the order they are declared
-
valueOf
public static CurrencyUtils valueOf(String name)
Returns the enum constant of this type with the specified name. The string must match exactly an identifier used to declare an enum constant in this type. (Extraneous whitespace characters are not permitted.)- Parameters:
name- the name of the enum constant to be returned.- Returns:
- the enum constant with the specified name
- Throws:
IllegalArgumentException- if this enum type has no constant with the specified nameNullPointerException- if the argument is null
-
formatPrice
public abstract String formatPrice(Double price, String cur)
Formats a price for its specific locale, depending on the currency code.- Parameters:
price- the amountcur- the 3-letter currency code- Returns:
- a formatted price with its currency symbol
-
getCurrencyName
public abstract String getCurrencyName(String cur, Locale locale)
Returns the full name of the currency in the language of the given locale. Defaults to English.- Parameters:
cur- the 3-letter currency codelocale- the locale- Returns:
- the currency name or "" if the currency is unknown
-
getLocaleForCountry
public abstract Locale getLocaleForCountry(String countryCode)
Returns the locale for a given country code.- Parameters:
countryCode- the 2-letter country code- Returns:
- a locale or null if countryCode is null
-
getCurrency
public abstract Currency getCurrency(String cur)
Returns the currency instance for a given currency code.- Parameters:
cur- the 3-letter currency code- Returns:
- the currency
-
getCurrency
public abstract Currency getCurrency(Locale loc)
Returns the currency instance for a given locale.- Parameters:
loc- locale- Returns:
- the currency instance or null if not found
-
getCurrenciesMap
public abstract Map<String,String> getCurrenciesMap()
Returns a map of all available currencies in the form: currency code - full currency name and symbol.- Returns:
- a map of known currencies
-
isValidCurrency
public abstract boolean isValidCurrency(String cur)
Validate the currency code.- Parameters:
cur- a 3-letter curency code- Returns:
- true if the code corresponds to a valid currency
-
getInstance
public static CurrencyUtils getInstance()
Returns an instance of this class.- Returns:
- an instance
-
-