public Money add(Money addend) throws UnifyException { this.checkCurrency(addend); return new Money(this.currencyCode, this.amount.add(addend.getAmount())); }
private void checkCurrency(Money money) throws UnifyException { if (this.currencyCode == null || !this.currencyCode.equals(money.getCurrencyCode())) { throw new UnifyException(UnifyCoreErrorConstants.INCOMPATIBLE_MONEY_CURRENCY, this.currencyCode, money.getCurrencyCode()); } } }
StringBuilder sb = new StringBuilder(); Money money = (Money) value; if (money.getCurrencyCode() != null) { sb.append(money.getCurrencyCode()).append(" "); if (money.getAmount() != null) { sb.append(((Formatter<BigDecimal>) formatter).format(money.getAmount()));
@SuppressWarnings("unchecked") @Override public String getFacadeStringValue() throws UnifyException { Money money = getValue(Money.class); if (money != null) { StringBuilder sb = new StringBuilder(); Formatter<BigDecimal> formatter = getUplAttribute(Formatter.class, "formatter"); if (money.getAmount() != null) { sb.append(formatter.format(money.getAmount())); } return sb.toString(); } return DataUtils.EMPTY_STRING; }
@Override protected Money doConvert(Object value, Formatter<?> formatter) throws Exception { if (value instanceof Money) { return new Money((Money) value); } if (value instanceof String) { String string = ((String) value).trim(); if (!string.isEmpty()) { String currencyCode = string.substring(0, 3); String amtPart = string.substring(3).trim(); BigDecimal amount = null; if (formatter == null) { amount = new BigDecimal(amtPart); } else { DecimalFormatter decimalFormatter = (DecimalFormatter) formatter; amount = new BigDecimal((decimalFormatter.parse(amtPart)).toString()); } return new Money(currencyCode, amount); } } return null; }
public Money multiply(Money multiplicand) throws UnifyException { this.checkCurrency(multiplicand); return new Money(this.currencyCode, this.amount.multiply(multiplicand.getAmount())); }
private String getCurrencyCode(MoneyField moneyField) throws UnifyException { String currencyCode = moneyField.getCurrencyCode(); Money money = moneyField.getValue(Money.class); if (money != null && money.getCurrencyCode() != null) { currencyCode = money.getCurrencyCode(); } return currencyCode; } }
public Money subtract(Money subtrahend) throws UnifyException { this.checkCurrency(subtrahend); return new Money(this.currencyCode, this.amount.subtract(subtrahend.getAmount())); }
public Money divide(Money divisor) throws UnifyException { this.checkCurrency(divisor); return new Money(this.currencyCode, this.amount.divide(divisor.getAmount())); }