public Objective credit(Money amount) { savings = savings.plus(amount); return this; }
public void credit(Money amount) { savings = savings.plus(amount); }
public void credit(Money amount) { savings.plus(amount); }
public void credit(Money amount) { savings.plus(amount); }
public void credit(Money amount) { savings.plus(amount); }
public void credit(Money amount) { savings.plus(amount); }
public void credit(Money amount) { savings.plus(amount); }
/** * Returns a copy of this monetary value with the amount added. * <p> * This adds the specified amount to this monetary amount, returning a new object. * No rounding is performed on the amount to be added, so it must have a * scale compatible with the currency. * <p> * This instance is immutable and unaffected by this method. * * @param amountToAdd the monetary value to add, not null * @return the new instance with the input amount added, never null * @throws ArithmeticException if the scale of the amount is too large */ public Money plus(BigDecimal amountToAdd) { return plus(amountToAdd, RoundingMode.UNNECESSARY); }
/** * Adds two {@code Money} objects, handling null. * <p> * This returns {@code money1 + money2} where null is ignored. * If both input values are null, then null is returned. * * @param money1 the first money instance, null returns money2 * @param money2 the first money instance, null returns money1 * @return the total, where null is ignored, null if both inputs are null * @throws CurrencyMismatchException if the currencies differ */ public static Money add(Money money1, Money money2) { if (money1 == null) { return money2; } if (money2 == null) { return money1; } return money1.plus(money2); }
/** * Returns a copy of this monetary value with the amount added. * <p> * This adds the specified amount to this monetary amount, returning a new object. * No rounding is performed on the amount to be added, so it must have a * scale compatible with the currency. * <p> * The amount is converted via {@link BigDecimal#valueOf(double)} which yields * the most expected answer for most programming scenarios. * Any {@code double} literal in code will be converted to * exactly the same BigDecimal with the same scale. * For example, the literal '1.45d' will be converted to '1.45'. * <p> * This instance is immutable and unaffected by this method. * * @param amountToAdd the monetary value to add, not null * @return the new instance with the input amount added, never null * @throws ArithmeticException if the scale of the amount is too large */ public Money plus(double amountToAdd) { return plus(amountToAdd, RoundingMode.UNNECESSARY); }
/** * Obtains an instance of {@code Money} as the total value of * a possibly empty collection. * <p> * The amounts are added as though using {@link #plus(Money)} starting * from zero in the specified currency. * All amounts must be in the same currency. * * @param currency the currency to total in, not null * @param monies the monetary values to total, no null elements, not null * @return the total, never null * @throws CurrencyMismatchException if the currencies differ */ public static Money total(CurrencyUnit currency, Iterable<Money> monies) { return Money.zero(currency).plus(monies); }
/** * Obtains an instance of {@code Money} as the total value of * a possibly empty array. * <p> * The amounts are added as though using {@link #plus(Money)} starting * from zero in the specified currency. * All amounts must be in the same currency. * * @param currency the currency to total in, not null * @param monies the monetary values to total, no null elements, not null * @return the total, never null * @throws CurrencyMismatchException if the currencies differ */ public static Money total(CurrencyUnit currency, Money... monies) { return Money.zero(currency).plus(Arrays.asList(monies)); }
/** * Obtains an instance of {@code Money} as the total value of a collection. * <p> * The iterable must provide at least one monetary value. * Subsequent amounts are added as though using {@link #plus(Money)}. * All amounts must be in the same currency. * * @param monies the monetary values to total, not empty, no null elements, not null * @return the total, never null * @throws IllegalArgumentException if the iterable is empty * @throws CurrencyMismatchException if the currencies differ */ public static Money total(Iterable<Money> monies) { MoneyUtils.checkNotNull(monies, "Money iterator must not be null"); Iterator<Money> it = monies.iterator(); if (it.hasNext() == false) { throw new IllegalArgumentException("Money iterator must not be empty"); } Money total = it.next(); MoneyUtils.checkNotNull(total, "Money iterator must not contain null entries"); while (it.hasNext()) { total = total.plus(it.next()); } return total; }
/** * Obtains an instance of {@code Money} as the total value of an array. * <p> * The array must contain at least one monetary value. * Subsequent amounts are added as though using {@link #plus(Money)}. * All amounts must be in the same currency. * * @param monies the monetary values to total, not empty, no null elements, not null * @return the total, never null * @throws IllegalArgumentException if the array is empty * @throws CurrencyMismatchException if the currencies differ */ public static Money total(Money... monies) { MoneyUtils.checkNotNull(monies, "Money array must not be null"); if (monies.length == 0) { throw new IllegalArgumentException("Money array must not be empty"); } Money total = monies[0]; MoneyUtils.checkNotNull(total, "Money arary must not contain null entries"); for (int i = 1; i < monies.length; i++) { total = total.plus(monies[i]); } return total; }