Example usage for java.util Currency getInstance

List of usage examples for java.util Currency getInstance

Introduction

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

Prototype

public static Currency getInstance(Locale locale) 

Source Link

Document

Returns the Currency instance for the country of the given locale.

Usage

From source file:org.codehaus.groovy.grails.web.binding.CurrencyEditor.java

@Override
public void setAsText(String text) throws IllegalArgumentException {
    if (StringUtils.isBlank(text)) {
        setValue(null);// w w  w  .ja  v  a2 s .  com
    }
    try {
        setValue(Currency.getInstance(text));
    } catch (IllegalArgumentException e) {
        // ignore and just set to null
        setValue(null);
    }
}

From source file:ShowCurrencies.java

public ShowCurrencies() {
    setDefaultCloseOperation(EXIT_ON_CLOSE);
    final Locale[] locales = Locale.getAvailableLocales();
    TableModel model = new AbstractTableModel() {
        public int getColumnCount() {
            return 3;
        }/*  ww  w  .j  a  v  a 2s  .c  o  m*/

        public String getColumnName(int column) {
            if (column == 0)
                return "Locale";
            else if (column == 1)
                return "Currency Code";
            else
                return "Currency Symbol";
        }

        public int getRowCount() {
            return locales.length;
        }

        public Object getValueAt(int row, int col) {
            if (col == 0)
                return locales[row];
            else
                try {
                    if (col == 1)
                        return Currency.getInstance(locales[row]).getCurrencyCode();
                    else
                        return Currency.getInstance(locales[row]).getSymbol(locales[row]);
                } catch (IllegalArgumentException iae) {
                    return null;
                }
        }
    };

    JTable table = new JTable(model);
    JScrollPane sp = new JScrollPane(table);
    getContentPane().add(sp);
    pack();
    setVisible(true);
}

From source file:com.springapp.mvc.mappers.PriceRowMapper.java

@Override
public PriceRow mapRow(ResultSet resultSet, int i) throws SQLException {
    PriceRow priceRow = new PriceRow();

    priceRow.setCode(resultSet.getInt("code"));
    priceRow.setAmount(resultSet.getDouble("amount"));
    priceRow.setStartDate(resultSet.getDate("startdate"));
    priceRow.setEndDate(resultSet.getDate("enddate"));
    priceRow.setCurrency(Currency.getInstance(resultSet.getString("currency")));

    return priceRow;

}

From source file:org.zalando.jackson.datatype.money.CurrencyDeserializer.java

@Override
public Currency deserialize(final JsonParser parser, final DeserializationContext context) throws IOException {
    final String currencyCode = parser.getValueAsString();
    return Currency.getInstance(currencyCode);
}

From source file:groovyx.gaelyk.graelyk.cast.CurrencyEditor.java

public void setAsText(String text) throws IllegalArgumentException {
    if (StringUtils.isBlank(text)) {
        setValue(null);/*from  w  w  w  . ja v a2s . com*/
    }
    try {
        setValue(Currency.getInstance(text));
    } catch (IllegalArgumentException e) {
        // ignore and just set to null
        setValue(null);
    }
}

From source file:org.zalando.jackson.datatype.money.CurrencyDeserializerTest.java

@Test
public void shouldDeserialize() throws IOException {
    final Currency actual = mapper.readValue("\"EUR\"", Currency.class);
    final Currency expected = Currency.getInstance("EUR");

    assertThat(actual, is(expected));/* www  .  j av  a 2  s  .c  o  m*/
}

From source file:org.zalando.jackson.datatype.money.CurrencySerializerTest.java

@Test
public void shouldSerialize() throws JsonProcessingException {
    final String expected = "EUR";
    final Currency currency = Currency.getInstance(expected);

    final String actual = mapper.writeValueAsString(currency);

    assertThat(actual, is('"' + expected + '"'));
}

From source file:com.trenako.entities.Profile.java

/**
 * Returns the currency.
 *
 * @return the currency
 */
public Currency getCurrency() {
    return Currency.getInstance(getCurrencyCode());
}

From source file:org.openmrs.module.hospitalcore.HospitalCoreActivator.java

public void started() {
    // TODO Auto-generated method stub
    log.info("Started HOSPITALCORE Module");
    Money.init(Currency.getInstance("INR"), RoundingMode.HALF_EVEN);
}

From source file:org.mayocat.shop.billing.store.jdbi.mapper.AbstractOrderMapper.java

protected void fillOrderSummary(ResultSet resultSet, OrderSummary order) throws SQLException {
    order.setId((UUID) resultSet.getObject("id"));
    order.setSlug(resultSet.getString("slug"));

    order.setBillingAddressId((UUID) resultSet.getObject("billing_address_id"));
    order.setDeliveryAddressId((UUID) resultSet.getObject("delivery_address_id"));
    order.setCustomerId((UUID) resultSet.getObject("customer_id"));

    order.setCreationDate(resultSet.getTimestamp("creation_date"));
    order.setUpdateDate(resultSet.getTimestamp("update_date"));

    order.setNumberOfItems(resultSet.getLong("number_of_items"));
    order.setCurrency(Currency.getInstance(resultSet.getString("currency")));

    order.setItemsTotal(resultSet.getBigDecimal("items_total"));
    order.setItemsTotalExcl(resultSet.getBigDecimal("items_total_excl"));
    order.setShipping(resultSet.getBigDecimal("shipping"));
    order.setShippingExcl(resultSet.getBigDecimal("shipping_excl"));
    order.setGrandTotal(resultSet.getBigDecimal("grand_total"));
    order.setGrandTotalExcl(resultSet.getBigDecimal("grand_total_excl"));

    order.setStatus(OrderSummary.Status.valueOf(resultSet.getString("status")));
    order.setAdditionalInformation(resultSet.getString("additional_information"));

    ObjectMapper mapper = new ObjectMapper();
    mapper.registerModule(new GuavaModule());
    try {// w  ww  .ja v a  2 s . c o  m
        Map<String, Object> data = mapper.readValue(resultSet.getString("order_data"),
                new TypeReference<Map<String, Object>>() {
                });
        order.setOrderData(data);
    } catch (IOException e) {
        logger.error("Failed to deserialize order data", e);
    }
}