/** Return the sum of <code>money</code> */ public static Money sum(List<Money> money) { Money total = Money.dollars(0.00); for (Iterator<Money> i = money.iterator(); i.hasNext(); ) { total = total.plus(i.next()); } return total; }
public static Money sum(Collection<Money> monies) { // TODO Return Default Currency if (monies.isEmpty()) { return Money.dollars(0.00); } Iterator<Money> iterator = monies.iterator(); Money sum = iterator.next(); while (iterator.hasNext()) { Money each = iterator.next(); sum = sum.plus(each); } return sum; }
/** Return the min of <code>a</code> or <code>b</code> */ public static Money min(Money a, Money b) { if (a.isLessThan(b)) { return a; } else { return b; } }
/** Return the max of <code>a</code> or <code>b</code> */ public static Money max(Money a, Money b) { if (a.isGreaterThan(b)) { return a; } else { return b; } }
public OrderResponse copy() { OrderResponse dst = new OrderResponse(); dst.request = request == null ? null : request.copy(); dst.date = date == null ? null : date.copy(); dst.who = who == null ? null : who.copy(); dst.authority = authority == null ? null : authority.copy(); dst.cost = cost == null ? null : cost.copy(); dst.code = code == null ? null : code.copy(); dst.description = description == null ? null : description.copy(); dst.fulfillment = new ArrayList<ResourceReference>(); for (ResourceReference i : fulfillment) dst.fulfillment.add(i.copy()); return dst; }
public boolean isEmpty() { return super.isEmpty() && (identifier == null || identifier.isEmpty()) && (name == null || name.isEmpty()) && (type == null || type.isEmpty()) && (status == null || status.isEmpty()) && (activePeriod == null || activePeriod.isEmpty()) && (currency == null || currency.isEmpty()) && (balance == null || balance.isEmpty()) && (coveragePeriod == null || coveragePeriod.isEmpty()) && (subject == null || subject.isEmpty()) && (owner == null || owner.isEmpty()) && (description == null || description.isEmpty()); }
public Account copy() { Account dst = new Account(); copyValues(dst); if (identifier != null) { dst.identifier = new ArrayList<Identifier>(); for (Identifier i : identifier) dst.identifier.add(i.copy()); } ; dst.name = name == null ? null : name.copy(); dst.type = type == null ? null : type.copy(); dst.status = status == null ? null : status.copy(); dst.activePeriod = activePeriod == null ? null : activePeriod.copy(); dst.currency = currency == null ? null : currency.copy(); dst.balance = balance == null ? null : balance.copy(); dst.coveragePeriod = coveragePeriod == null ? null : coveragePeriod.copy(); dst.subject = subject == null ? null : subject.copy(); dst.owner = owner == null ? null : owner.copy(); dst.description = description == null ? null : description.copy(); return dst; }
/** * WARNING: Because of the indefinite precision of double, this method must round off the value. */ public static Money euros(double amount) { return Money.valueOf(amount, Money.EUR); }
/** * This creation method is safe to use. It will adjust scale, but will not round off the amount. */ public static Money valueOf(BigDecimal amount, Currency currency) { return Money.valueOf(amount, currency, Rounding.UNNECESSARY); }
/** * This creation method is safe to use. It will adjust scale, but will not round off the amount. */ public static Money dollars(BigDecimal amount) { return Money.valueOf(amount, Money.USD); }
/** * WARNING: Because of the indefinite precision of double, thismethod must round off the value. */ public static Money dollars(double amount) { return Money.valueOf(amount, Money.USD); }
public boolean isZero() { return equals(Money.valueOf(0.0, currency)); }
/** Return the max of <code>a</code> or <code>0</code> */ public static Money notBelowZero(Money a) { Money zero = Money.valueOf(0.00, a.getCurrency()); return Money.max(zero, a); }
/** * This probably should be Currency responsibility. Even then, it may need to be customized for * specialty apps because there are other cases, where the smallest increment is not the smallest * unit. */ Money minimumIncrement() { BigDecimal one = new BigDecimal(1); BigDecimal increment = one.movePointLeft(currency.getDefaultFractionDigits()); return Money.valueOf(increment, currency); }
/** * TODO: BigDecimal.multiply() scale is sum of scales of two multiplied numbers. So what is scale * of times? */ public Money times(BigDecimal factor, int roundingMode) { return Money.valueOf(amount.multiply(factor), currency, roundingMode); }
public Money applying(Ratio ratio, int scale, int roundingRule) { BigDecimal newAmount = ratio.times(amount).decimalValue(scale, roundingRule); return Money.valueOf(newAmount, currency); }
public Money dividedBy(BigDecimal divisor, int roundingMode) { BigDecimal newAmount = amount.divide(divisor, roundingMode); return Money.valueOf(newAmount, currency); }
public Money minus(Money other) { return plus(other.negated()); }
public Money plus(Money other) { assertHasSameCurrencyAs(other); return Money.valueOf(amount.add(other.amount), currency); }
/** * This creation method is safe to use. It will adjust scale, but will not round off the amount. */ public static Money euros(BigDecimal amount) { return Money.valueOf(amount, Money.EUR); }
public static Money zeroIfNull(Money money) { return money == null ? Money.dollars(0.00) : money; }
public Money negated() { return Money.valueOf(amount.negate(), currency); }
/** * WARNING: Because of the indefinite precision of double, this method must round off the value. */ public static Money valueOf(double dblAmount, Currency currency) { return Money.valueOf(dblAmount, currency, Money.DEFAULT_ROUNDING_MODE); }
/** * Because of the indefinite precision of double, this method must round off the value. This * method gives the client control of the rounding mode. */ public static Money valueOf(double dblAmount, Currency currency, int roundingMode) { BigDecimal rawAmount = new BigDecimal(dblAmount); return Money.valueOf(rawAmount, currency, roundingMode); }
private void assertHasSameCurrencyAs(Money aMoney) { if (!hasSameCurrencyAs(aMoney)) { throw new IllegalArgumentException( aMoney.toString() + " is not same currency as " + toString()); } }
public Money abs() { return Money.valueOf(amount.abs(), currency); }