private void assertSameCurrency(final Money money) { if (!money.getCurrency().equals(getCurrency())) { throw new IllegalArgumentException("Not the same currency: " + getCurrency() + " & " + money.getCurrency()); } }
@Override protected String doEncode(final Object object) { final Money money = (Money) object; final String value = String.valueOf(money.doubleValue()) + " " + money.getCurrency(); return value; }
public Object getPropertyValue(final Object component, final int property) { Money monetaryAmount = (Money) component; if (property == 0) return monetaryAmount.getAmount(); else return monetaryAmount.getCurrency(); }
@Override protected String doEncode(final Object object) { final Money money = (Money) object; final String value = String.valueOf(money.doubleValue()) + " " + money.getCurrency(); return value; }
public String getCurrencyCode(final NakedObject object) { final Money money = (Money) object.getObject(); if (money == null) { return ""; } else { return money.getCurrency(); } }
public String getCurrencyCode(final NakedObject object) { final Money money = (Money) object.getObject(); if (money == null) { return ""; } else { return money.getCurrency(); } }
protected String checkCurrency(final Money newAmount) { if (newAmount == null || newAmount.getCurrency().equalsIgnoreCase(getClaim().currencyCode())) { return null; } return CURRENCY_NOT_VALID_FOR_THIS_CLAIM + ": " + newAmount.getCurrency(); }
@Override public String titleString(final Object object) { if (object == null) { return ""; } final Money money = (Money) object; final boolean localCurrency = LOCAL_CURRENCY_CODE.equals(money.getCurrency()); if (localCurrency) { return DEFAULT_CURRENCY_FORMAT.format(money.doubleValue()); } else { return DEFAULT_NUMBER_FORMAT.format(money.doubleValue()) + " " + money.getCurrency(); } }
@Override public String titleString(final Object object) { if (object == null) { return ""; } final Money money = (Money) object; final boolean localCurrency = LOCAL_CURRENCY_CODE.equals(money.getCurrency()); if (localCurrency) { return DEFAULT_CURRENCY_FORMAT.format(money.doubleValue()); } else { return DEFAULT_NUMBER_FORMAT.format(money.doubleValue()) + " " + money.getCurrency(); } }
private Object parseDerivedValue(final Object original, final String entry) { Money money = (Money) original; if (money == null || money.getCurrency().equals(LOCAL_CURRENCY_CODE)) { try { final double value = DEFAULT_CURRENCY_FORMAT.parse(entry).doubleValue(); money = new Money(value, LOCAL_CURRENCY_CODE); return money; } catch (final ParseException ignore) { } } try { final double value = DEFAULT_NUMBER_FORMAT.parse(entry).doubleValue(); final String currencyCode = money == null ? defaultCurrencyCode : money.getCurrency(); money = new Money(value, currencyCode); return money; } catch (final ParseException ex) { throw new TextEntryParseException("Not a distinguishable money value " + entry, ex); } }
public void nullSafeSet(final PreparedStatement statement, final Object value, final int index, final SessionImplementor session) throws SQLException { if (value==null) { statement.setNull(index, Hibernate.BIG_DECIMAL.sqlType()); statement.setNull(index+1, Hibernate.STRING.sqlType()); } else { Money amount = (Money) value; statement.setBigDecimal( index, amount.getAmount() ); statement.setString( index+1, amount.getCurrency() ); } }
private Object parseDerivedValue(final Object original, final String entry) { Money money = (Money) original; if (money == null || money.getCurrency().equals(LOCAL_CURRENCY_CODE)) { try { final double value = DEFAULT_CURRENCY_FORMAT.parse(entry).doubleValue(); money = new Money(value, LOCAL_CURRENCY_CODE); return money; } catch (final ParseException e) { if (money == null) { throw new TextEntryParseException("Not a distinguishable money value " + entry, e); } } } try { final double value = DEFAULT_NUMBER_FORMAT.parse(entry).doubleValue(); final String currencyCode = money == null ? defaultCurrencyCode : money.getCurrency(); money = new Money(value, currencyCode); return money; } catch (final ParseException ex) { throw new TextEntryParseException("Not a distinguishable money value " + entry, ex); } }
protected void copyAllFieldsFromAbstractExpenseItem(final ExpenseItem otherItem) { if (amount == null || amount.isZero()) { // Guard against different currency if (otherItem.getAmount().getCurrency().equals(getAmount().getCurrency())) { // TODO: Use // hasSameCurrencyAs // on Money when // implemented modifyAmount(otherItem.getAmount()); } } if (description == null || description.equals("")) { modifyDescription(otherItem.getDescription()); } if (projectCode == null) { modifyProjectCode(otherItem.getProjectCode()); } }