Example usage for java.util Currency getCurrencyCode

List of usage examples for java.util Currency getCurrencyCode

Introduction

In this page you can find the example usage for java.util Currency getCurrencyCode.

Prototype

public String getCurrencyCode() 

Source Link

Document

Gets the ISO 4217 currency code of this currency.

Usage

From source file:org.noerp.base.util.UtilHttp.java

/**
 * Get the currency string from the session.
 * @param session HttpSession object to use for lookup
 * @return String The ISO currency code/*  w w  w .j ava 2s.  c  o  m*/
 */
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.isEmpty(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 locale we can get...
    if (iso == null) {
        Currency cur = Currency.getInstance(getLocale(session));
        iso = cur.getCurrencyCode();
    }

    return iso;
}

From source file:ivl.android.moneybalance.CalculationEditorActivity.java

private void save() {
    String title = getCalculationTitle();
    Currency currency = (Currency) currencyField.getSelectedItem();
    List<String> personNames = getPersonNames();

    DataBaseHelper dbHelper = new DataBaseHelper(this);
    CalculationDataSource dataSource = new CalculationDataSource(dbHelper);
    Calculation calculation = dataSource.createCalculation(title, currency.getCurrencyCode(), personNames);
    dbHelper.close();// www.  j ava2  s  .co  m

    Intent intent = new Intent(this, ExpenseListActivity.class);
    intent.putExtra(ExpenseListActivity.PARAM_CALCULATION_ID, calculation.getId());
    startActivity(intent);
    finish();
}

From source file:net.sourceforge.eclipsetrader.core.CurrencyConverter.java

public void setExchangeRatio(Currency from, Currency to, double ratio) {
    if (from != null && to != null && !from.equals(to))
        setExchangeRatio(from.getCurrencyCode(), to.getCurrencyCode(), ratio);
}

From source file:org.orcid.frontend.web.controllers.WorkspaceController.java

@ModelAttribute("currencyCodeTypes")
public Map<String, String> retrieveCurrencyCodesTypesAsMap() {
    Map<String, String> currencyCodeTypes = new LinkedHashMap<String, String>();
    //Add an empty one
    currencyCodeTypes.put("", "");
    for (Currency currency : Currency.getAvailableCurrencies()) {
        currencyCodeTypes.put(currency.getCurrencyCode(), currency.getCurrencyCode());
    }/*from   w w  w .j a v a 2  s. c om*/
    return FunctionsOverCollections.sortMapsByValues(currencyCodeTypes);
}

From source file:org.apache.ofbiz.base.util.UtilHttp.java

/**
 * Get the currency string from the session.
 * @param session HttpSession object to use for lookup
 * @return String The ISO currency code/*from   w  ww .  j  a  v a  2  s. c o  m*/
 */
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;
}

From source file:net.sourceforge.eclipsetrader.core.CurrencyConverter.java

public double convert(double amount, Currency from, Currency to) {
    if (from == null || to == null || from.equals(to))
        return amount;
    return convert(null, amount, from.getCurrencyCode(), to.getCurrencyCode());
}

From source file:net.sourceforge.eclipsetrader.core.CurrencyConverter.java

public double convert(Date date, double amount, Currency from, Currency to) {
    if (from == null || to == null || from.equals(to))
        return amount;
    return convert(date, amount, from.getCurrencyCode(), to.getCurrencyCode());
}

From source file:net.sourceforge.eclipsetrader.core.CurrencyConverter.java

public double convert(Double amount, Currency from, Currency to) {
    if (from == null || to == null || from.equals(to))
        return amount.doubleValue();
    return convert(null, amount.doubleValue(), from.getCurrencyCode(), to.getCurrencyCode());
}

From source file:net.sourceforge.eclipsetrader.core.CurrencyConverter.java

public double convert(Date date, Double amount, Currency from, Currency to) {
    if (from == null || to == null || from.equals(to))
        return amount.doubleValue();
    return convert(date, amount.doubleValue(), from.getCurrencyCode(), to.getCurrencyCode());
}

From source file:de.javakaffee.web.msm.serializer.javolution.JavolutionTranscoderTest.java

/**
 * This is test for issue #34:/*from w  ww.j a va 2  s.  c  o  m*/
 * msm-javolution-serializer: java.util.Currency gets deserialized with ReflectionFormat
 *
 * See http://code.google.com/p/memcached-session-manager/issues/detail?id=34
 *
 * @throws Exception
 */
@Test(enabled = true)
public void testCurrency() throws Exception {
    final MemcachedBackupSession session = _manager.createEmptySession();
    session.setValid(true);

    final Currency orig = Currency.getInstance("EUR");
    session.setAttribute("currency1", orig);
    session.setAttribute("currency2", orig);

    final Map<String, Object> deserialized = _transcoder
            .deserializeAttributes(_transcoder.serializeAttributes(session, session.getAttributesInternal()));

    assertDeepEquals(deserialized, session.getAttributesInternal());

    // Check that the transient field defaultFractionDigits is initialized correctly (that was the bug)
    final Currency currency1 = (Currency) deserialized.get("currency1");
    Assert.assertEquals(currency1.getCurrencyCode(), orig.getCurrencyCode());
    Assert.assertEquals(currency1.getDefaultFractionDigits(), orig.getDefaultFractionDigits());

}