下面列出了java.util.Currency#getCurrencyCode ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
private static void testCountryCurrency(String country, String currencyCode,
int digits) {
testCurrencyDefined(currencyCode, digits);
Currency currency = Currency.getInstance(new Locale("", country));
if (!currency.getCurrencyCode().equals(currencyCode)) {
throw new RuntimeException("[" + country
+ "] expected: " + currencyCode
+ "; got: " + currency.getCurrencyCode());
}
}
/**
* Get the currency string from the session.
* @param session HttpSession object to use for lookup
* @return String The ISO currency code
*/
public static String getCurrencyUom(HttpSession session, String appDefaultCurrencyUom) {
// session, should override all if set there
String iso = (String) session.getAttribute("currencyUom");
// check userLogin next, ie if nothing to override in the session
if (iso == null) {
Map<String, ?> userLogin = UtilGenerics.cast(session.getAttribute("userLogin"));
if (userLogin == null) {
userLogin = UtilGenerics.cast(session.getAttribute("autoUserLogin"));
}
if (userLogin != null) {
iso = (String) userLogin.get("lastCurrencyUom");
}
}
// no user currency? before global default try appDefaultCurrencyUom if specified
if (iso == null && UtilValidate.isNotEmpty(appDefaultCurrencyUom)) {
iso = appDefaultCurrencyUom;
}
// if none is set we will use the configured default
if (iso == null) {
try {
iso = UtilProperties.getPropertyValue("general", "currency.uom.id.default", "USD");
} catch (Exception e) {
Debug.logWarning("Error getting the general:currency.uom.id.default value: " + e.toString(), module);
}
}
// if still none we will use the default for whatever currency we can get...
if (iso == null) {
Currency cur = Currency.getInstance(getLocale(session));
iso = cur.getCurrencyCode();
}
return iso;
}
private static void testCountryCurrency(String country, String currencyCode,
int digits) {
testCurrencyDefined(currencyCode, digits);
Currency currency = Currency.getInstance(new Locale("", country));
if (!currency.getCurrencyCode().equals(currencyCode)) {
throw new RuntimeException("[" + country
+ "] expected: " + currencyCode
+ "; got: " + currency.getCurrencyCode());
}
}
static void checkCountryCurrency(String countryCode, String expected) {
Locale locale = new Locale("", countryCode);
Currency currency = Currency.getInstance(locale);
String code = (currency != null) ? currency.getCurrencyCode() : null;
if (!(expected == null ? code == null : expected.equals(code))) {
throw new RuntimeException("Wrong currency for " +
locale.getDisplayCountry() +
": expected " + expected + ", got " + code);
}
}
static void checkCountryCurrency(String countryCode, String expected) {
Locale locale = new Locale("", countryCode);
Currency currency = Currency.getInstance(locale);
String code = (currency != null) ? currency.getCurrencyCode() : null;
if (!(expected == null ? code == null : expected.equals(code))) {
throw new RuntimeException("Wrong currency for " +
locale.getDisplayCountry() +
": expected " + expected + ", got " + code);
}
}
private static void testCountryCurrency(String country, String currencyCode,
int digits) {
testCurrencyDefined(currencyCode, digits);
Currency currency = Currency.getInstance(new Locale("", country));
if (!currency.getCurrencyCode().equals(currencyCode)) {
throw new RuntimeException("[" + country
+ "] expected: " + currencyCode
+ "; got: " + currency.getCurrencyCode());
}
}
private static void testCountryCurrency(String country, String currencyCode,
int digits) {
testCurrencyDefined(currencyCode, digits);
Currency currency = Currency.getInstance(new Locale("", country));
if (!currency.getCurrencyCode().equals(currencyCode)) {
throw new RuntimeException("[" + country
+ "] expected: " + currencyCode
+ "; got: " + currency.getCurrencyCode());
}
}
@Override
public String toNonNullValue(Currency value) {
return value.getCurrencyCode();
}
@Override
public String getAsText() {
Currency value = (Currency) getValue();
return (value != null ? value.getCurrencyCode() : "");
}
@Override
public String convert(Currency source) {
return source.getCurrencyCode();
}
@Override
public String getAsText() {
Currency value = (Currency) getValue();
return (value != null ? value.getCurrencyCode() : "");
}
@Override
public String toString(Currency value) {
return value.getCurrencyCode();
}
/**
* Sets the currency of these DecimalFormatSymbols.
* This also sets the currency symbol attribute to the currency's symbol
* in the DecimalFormatSymbols' locale, and the international currency
* symbol attribute to the currency's ISO 4217 currency code.
*
* @param currency the new currency to be used
* @exception NullPointerException if <code>currency</code> is null
* @since 1.4
* @see #setCurrencySymbol
* @see #setInternationalCurrencySymbol
*/
public void setCurrency(Currency currency) {
if (currency == null) {
throw new NullPointerException();
}
this.currency = currency;
intlCurrencySymbol = currency.getCurrencyCode();
currencySymbol = currency.getSymbol(locale);
}
/**
* Sets the currency of these DecimalFormatSymbols.
* This also sets the currency symbol attribute to the currency's symbol
* in the DecimalFormatSymbols' locale, and the international currency
* symbol attribute to the currency's ISO 4217 currency code.
*
* @param currency the new currency to be used
* @exception NullPointerException if <code>currency</code> is null
* @since 1.4
* @see #setCurrencySymbol
* @see #setInternationalCurrencySymbol
*/
public void setCurrency(Currency currency) {
if (currency == null) {
throw new NullPointerException();
}
this.currency = currency;
intlCurrencySymbol = currency.getCurrencyCode();
currencySymbol = currency.getSymbol(locale);
}
/**
* Sets the currency of these DecimalFormatSymbols.
* This also sets the currency symbol attribute to the currency's symbol
* in the DecimalFormatSymbols' locale, and the international currency
* symbol attribute to the currency's ISO 4217 currency code.
*
* @param currency the new currency to be used
* @exception NullPointerException if <code>currency</code> is null
* @since 1.4
* @see #setCurrencySymbol
* @see #setInternationalCurrencySymbol
*/
public void setCurrency(Currency currency) {
if (currency == null) {
throw new NullPointerException();
}
this.currency = currency;
intlCurrencySymbol = currency.getCurrencyCode();
currencySymbol = currency.getSymbol(locale);
}
/**
* Sets the currency of these DecimalFormatSymbols.
* This also sets the currency symbol attribute to the currency's symbol
* in the DecimalFormatSymbols' locale, and the international currency
* symbol attribute to the currency's ISO 4217 currency code.
*
* @param currency the new currency to be used
* @exception NullPointerException if <code>currency</code> is null
* @since 1.4
* @see #setCurrencySymbol
* @see #setInternationalCurrencySymbol
*/
public void setCurrency(Currency currency) {
if (currency == null) {
throw new NullPointerException();
}
this.currency = currency;
intlCurrencySymbol = currency.getCurrencyCode();
currencySymbol = currency.getSymbol(locale);
}
/**
* Sets the currency of these DecimalFormatSymbols.
* This also sets the currency symbol attribute to the currency's symbol
* in the DecimalFormatSymbols' locale, and the international currency
* symbol attribute to the currency's ISO 4217 currency code.
*
* @param currency the new currency to be used
* @exception NullPointerException if <code>currency</code> is null
* @since 1.4
* @see #setCurrencySymbol
* @see #setInternationalCurrencySymbol
*/
public void setCurrency(Currency currency) {
if (currency == null) {
throw new NullPointerException();
}
this.currency = currency;
intlCurrencySymbol = currency.getCurrencyCode();
currencySymbol = currency.getSymbol(locale);
}
/**
* Sets the currency of these DecimalFormatSymbols.
* This also sets the currency symbol attribute to the currency's symbol
* in the DecimalFormatSymbols' locale, and the international currency
* symbol attribute to the currency's ISO 4217 currency code.
*
* @param currency the new currency to be used
* @exception NullPointerException if <code>currency</code> is null
* @since 1.4
* @see #setCurrencySymbol
* @see #setInternationalCurrencySymbol
*/
public void setCurrency(Currency currency) {
if (currency == null) {
throw new NullPointerException();
}
this.currency = currency;
intlCurrencySymbol = currency.getCurrencyCode();
currencySymbol = currency.getSymbol(locale);
}
/**
* Sets the currency of these DecimalFormatSymbols.
* This also sets the currency symbol attribute to the currency's symbol
* in the DecimalFormatSymbols' locale, and the international currency
* symbol attribute to the currency's ISO 4217 currency code.
*
* @param currency the new currency to be used
* @exception NullPointerException if <code>currency</code> is null
* @since 1.4
* @see #setCurrencySymbol
* @see #setInternationalCurrencySymbol
*/
public void setCurrency(Currency currency) {
if (currency == null) {
throw new NullPointerException();
}
this.currency = currency;
intlCurrencySymbol = currency.getCurrencyCode();
currencySymbol = currency.getSymbol(locale);
}
/**
* Sets the currency of these DecimalFormatSymbols.
* This also sets the currency symbol attribute to the currency's symbol
* in the DecimalFormatSymbols' locale, and the international currency
* symbol attribute to the currency's ISO 4217 currency code.
*
* @param currency the new currency to be used
* @exception NullPointerException if <code>currency</code> is null
* @since 1.4
* @see #setCurrencySymbol
* @see #setInternationalCurrencySymbol
*/
public void setCurrency(Currency currency) {
if (currency == null) {
throw new NullPointerException();
}
this.currency = currency;
intlCurrencySymbol = currency.getCurrencyCode();
currencySymbol = currency.getSymbol(locale);
//cachedIcuDFS = null;
}