/** * Returns a copy of this monetary value with the amount negated. * <p> * This instance is immutable and unaffected by this method. * * @return the new instance with the amount negated, never null */ public Money negated() { return with(money.negated()); }
/** * Returns a copy of this monetary value multiplied by the specified value. * <p> * This takes this amount and multiplies it by the specified value. * <p> * This instance is immutable and unaffected by this method. * * @param valueToMultiplyBy the scalar value to multiply by, not null * @return the new multiplied instance, never null */ public Money multipliedBy(long valueToMultiplyBy) { return with(money.multipliedBy(valueToMultiplyBy)); }
/** * Returns a copy of this monetary value with a collection of monetary amounts added. * <p> * This adds the specified amounts to this monetary amount, returning a new object. * The amounts must be in the same currency. * <p> * This instance is immutable and unaffected by this method. * * @param moniesToAdd the monetary values to add, no null elements, not null * @return the new instance with the input amounts added, never null * @throws CurrencyMismatchException if the currencies differ */ public Money plus(Iterable<Money> moniesToAdd) { return with(money.plus(moniesToAdd)); }
/** * Returns a copy of this monetary value with the amount in major units added. * <p> * This adds an amount in major units, leaving the minor units untouched. * For example, USD 23.45 plus 138 gives USD 161.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 */ public Money plusMajor(long amountToAdd) { return with(money.plusMajor(amountToAdd)); }
/** * Returns a copy of this monetary value with the amount in minor units added. * <p> * This adds an amount in minor units. * For example, USD 23.45 plus 138 gives USD 24.83. * <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 */ public Money plusMinor(long amountToAdd) { return with(money.plusMinor(amountToAdd)); }
/** * Returns a copy of this monetary value with the amount in major units subtracted. * <p> * This subtracts an amount in major units, leaving the minor units untouched. * For example, USD 23.45 minus 138 gives USD -114.55. * <p> * This instance is immutable and unaffected by this method. * * @param amountToSubtract the monetary value to subtract, not null * @return the new instance with the input amount subtracted, never null */ public Money minusMajor(long amountToSubtract) { return with(money.minusMajor(amountToSubtract)); }
/** * Returns a copy of this monetary value with the amount in minor units subtracted. * <p> * This subtracts an amount in minor units. * For example, USD 23.45 minus 138 gives USD 22.07. * <p> * This instance is immutable and unaffected by this method. * * @param amountToSubtract the monetary value to subtract, not null * @return the new instance with the input amount subtracted, never null */ public Money minusMinor(long amountToSubtract) { return with(money.minusMinor(amountToSubtract)); }
/** * Returns a copy of this monetary value multiplied by the specified value. * <p> * This takes this amount and multiplies it by the specified value, rounding * the result is rounded as specified. * <p> * This instance is immutable and unaffected by this method. * * @param valueToMultiplyBy the scalar value to multiply by, not null * @param roundingMode the rounding mode to use to bring the decimal places back in line, not null * @return the new multiplied instance, never null * @throws ArithmeticException if the rounding fails */ public Money multipliedBy(BigDecimal valueToMultiplyBy, RoundingMode roundingMode) { return with(money.multiplyRetainScale(valueToMultiplyBy, roundingMode)); }
/** * Returns a copy of this monetary value with a collection of monetary amounts subtracted. * <p> * This subtracts the specified amounts from this monetary amount, returning a new object. * The amounts must be in the same currency. * <p> * This instance is immutable and unaffected by this method. * * @param moniesToSubtract the monetary values to subtract, no null elements, not null * @return the new instance with the input amounts subtracted, never null * @throws CurrencyMismatchException if the currencies differ */ public Money minus(Iterable<Money> moniesToSubtract) { return with(money.minus(moniesToSubtract)); }
/** * Returns a copy of this monetary value divided by the specified value. * <p> * This takes this amount and divides it by the specified value, rounding * the result is rounded as specified. * <p> * This instance is immutable and unaffected by this method. * * @param valueToDivideBy the scalar value to divide by, not null * @param roundingMode the rounding mode to use, not null * @return the new divided instance, never null * @throws ArithmeticException if dividing by zero * @throws ArithmeticException if the rounding fails */ public Money dividedBy(BigDecimal valueToDivideBy, RoundingMode roundingMode) { return with(money.dividedBy(valueToDivideBy, roundingMode)); }
/** * 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. * If the amount to add exceeds the scale of the currency, then the * rounding mode will be used to adjust the result. * <p> * This instance is immutable and unaffected by this method. * * @param amountToAdd the monetary value to add, not null * @param roundingMode the rounding mode to use, not null * @return the new instance with the input amount added, never null */ public Money plus(BigDecimal amountToAdd, RoundingMode roundingMode) { return with(money.plusRetainScale(amountToAdd, roundingMode)); }
/** * Returns a copy of this monetary value with the amount subtracted. * <p> * This subtracts the specified amount from this monetary amount, returning a new object. * If the amount to subtract exceeds the scale of the currency, then the * rounding mode will be used to adjust the result. * <p> * This instance is immutable and unaffected by this method. * * @param amountToSubtract the monetary value to subtract, not null * @param roundingMode the rounding mode to use, not null * @return the new instance with the input amount subtracted, never null */ public Money minus(BigDecimal amountToSubtract, RoundingMode roundingMode) { return with(money.minusRetainScale(amountToSubtract, roundingMode)); }
/** * Returns a copy of this monetary value divided by the specified value. * <p> * This takes this amount and divides it by the specified value, rounding * the result is rounded as specified. * <p> * This instance is immutable and unaffected by this method. * * @param valueToDivideBy the scalar value to divide by, not null * @param roundingMode the rounding mode to use, not null * @return the new divided instance, never null * @throws ArithmeticException if dividing by zero * @throws ArithmeticException if the rounding fails */ public Money dividedBy(long valueToDivideBy, RoundingMode roundingMode) { return with(money.dividedBy(valueToDivideBy, roundingMode)); }
/** * Returns a copy of this monetary value with the amount subtracted. * <p> * This subtracts the specified amount from this monetary amount, returning a new object. * The amount subtracted must be in the same currency. * <p> * The subtraction has no rounding issues and is always accurate. * For example,'USD 25.95' minus 'USD 3.02' will 'USD 22.93'. * <p> * This instance is immutable and unaffected by this method. * * @param moneyToSubtract the monetary value to subtract, not null * @return the new instance with the input amount subtracted, never null * @throws CurrencyMismatchException if the currencies differ */ public Money minus(Money moneyToSubtract) { return with(money.minus(moneyToSubtract)); }
/** * 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. * If the amount to add exceeds the scale of the currency, then the * rounding mode will be used to adjust the result. * <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 * @param roundingMode the rounding mode to use, not null * @return the new instance with the input amount added, never null */ public Money plus(double amountToAdd, RoundingMode roundingMode) { return with(money.plusRetainScale(amountToAdd, roundingMode)); }
/** * Returns a copy of this monetary value with the amount subtracted. * <p> * This subtracts the specified amount from this monetary amount, returning a new object. * If the amount to subtract exceeds the scale of the currency, then the * rounding mode will be used to adjust the result. * <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 amountToSubtract the monetary value to subtract, not null * @param roundingMode the rounding mode to use, not null * @return the new instance with the input amount subtracted, never null */ public Money minus(double amountToSubtract, RoundingMode roundingMode) { return with(money.minusRetainScale(amountToSubtract, roundingMode)); }
/** * 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. * The amount added must be in the same currency. * <p> * The addition has no rounding issues and is always accurate. * For example,'USD 25.95' plus 'USD 3.02' will 'USD 28.97'. * <p> * This instance is immutable and unaffected by this method. * * @param moneyToAdd the monetary value to add, not null * @return the new instance with the input amount added, never null * @throws CurrencyMismatchException if the currencies differ */ public Money plus(Money moneyToAdd) { return with(money.plus(moneyToAdd)); }
/** * Returns a copy of this monetary value with the specified amount. * <p> * The returned instance will have this currency and the new amount. * If the scale of the {@code BigDecimal} needs to be adjusted, then * it will be rounded using the specified mode. * <p> * This instance is immutable and unaffected by this method. * * @param amount the monetary amount to set in the returned instance, not null * @param roundingMode the rounding mode to adjust the scale, not null * @return the new instance with the input amount set, never null */ public Money withAmount(BigDecimal amount, RoundingMode roundingMode) { return with(money.withAmount(amount).withCurrencyScale(roundingMode)); }
/** * Returns a copy of this monetary value with the specified currency. * <p> * The returned instance will have the specified currency and the amount * from this instance. If the number of decimal places differs between the * currencies, then the amount may be rounded. * <p> * This instance is immutable and unaffected by this method. * * @param currency the currency to use, not null * @param roundingMode the rounding mode to use to bring the decimal places back in line, not null * @return the new instance with the input currency set, never null * @throws ArithmeticException if the rounding fails */ public Money withCurrencyUnit(CurrencyUnit currency, RoundingMode roundingMode) { return with(money.withCurrencyUnit(currency).withCurrencyScale(roundingMode)); }
/** * Returns a copy of this monetary value converted into another currency * using the specified conversion rate, with a rounding mode used to adjust * the decimal places in the result. * <p> * This instance is immutable and unaffected by this method. * * @param currency the new currency, not null * @param conversionMultipler the conversion factor between the currencies, not null * @param roundingMode the rounding mode to use to bring the decimal places back in line, not null * @return the new multiplied instance, never null * @throws IllegalArgumentException if the currency is the same as this currency * @throws IllegalArgumentException if the conversion multiplier is negative * @throws ArithmeticException if the rounding fails */ public Money convertedTo(CurrencyUnit currency, BigDecimal conversionMultipler, RoundingMode roundingMode) { return with(money.convertedTo(currency, conversionMultipler).withCurrencyScale(roundingMode)); }