Class MoneyUtils
- java.lang.Object
-
- org.joda.money.MoneyUtils
-
public final class MoneyUtils extends java.lang.ObjectUtilities for working with monetary values that handle null.This utility class contains thread-safe static methods.
-
-
Constructor Summary
Constructors Modifier Constructor Description privateMoneyUtils()Private constructor.
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static BigMoneyadd(BigMoney money1, BigMoney money2)Adds twoBigMoneyobjects, handling null.static Moneyadd(Money money1, Money money2)Adds twoMoneyobjects, handling null.(package private) static voidcheckNotNull(java.lang.Object object, java.lang.String message)Validates that the object specified is not null.static booleanisNegative(BigMoneyProvider moneyProvider)Checks if the monetary value is negative and non-zero, treating null as zero.static booleanisNegativeOrZero(BigMoneyProvider moneyProvider)Checks if the monetary value is negative or zero, treating null as zero.static booleanisPositive(BigMoneyProvider moneyProvider)Checks if the monetary value is positive and non-zero, treating null as zero.static booleanisPositiveOrZero(BigMoneyProvider moneyProvider)Checks if the monetary value is positive or zero, treating null as zero.static booleanisZero(BigMoneyProvider moneyProvider)Checks if the monetary value is zero, treating null as zero.static BigMoneymax(BigMoney money1, BigMoney money2)Finds the maximumBigMoneyvalue, handing null.static Moneymax(Money money1, Money money2)Finds the maximumMoneyvalue, handing null.static BigMoneymin(BigMoney money1, BigMoney money2)Finds the minimumBigMoneyvalue, handing null.static Moneymin(Money money1, Money money2)Finds the minimumMoneyvalue, handing null.static BigMoneysubtract(BigMoney money1, BigMoney money2)Subtracts the secondBigMoneyfrom the first, handling null.static Moneysubtract(Money money1, Money money2)Subtracts the secondMoneyfrom the first, handling null.
-
-
-
Method Detail
-
checkNotNull
static void checkNotNull(java.lang.Object object, java.lang.String message)Validates that the object specified is not null.- Parameters:
object- the object to check, not null- Throws:
java.lang.NullPointerException- if the input value is null
-
isZero
public static boolean isZero(BigMoneyProvider moneyProvider)
Checks if the monetary value is zero, treating null as zero.This method accepts any implementation of
BigMoneyProvider.- Parameters:
moneyProvider- the money to check, null returns zero- Returns:
- true if the money is null or zero
-
isPositive
public static boolean isPositive(BigMoneyProvider moneyProvider)
Checks if the monetary value is positive and non-zero, treating null as zero.This method accepts any implementation of
BigMoneyProvider.- Parameters:
moneyProvider- the money to check, null returns false- Returns:
- true if the money is non-null and positive
-
isPositiveOrZero
public static boolean isPositiveOrZero(BigMoneyProvider moneyProvider)
Checks if the monetary value is positive or zero, treating null as zero.This method accepts any implementation of
BigMoneyProvider.- Parameters:
moneyProvider- the money to check, null returns true- Returns:
- true if the money is null, zero or positive
-
isNegative
public static boolean isNegative(BigMoneyProvider moneyProvider)
Checks if the monetary value is negative and non-zero, treating null as zero.This method accepts any implementation of
BigMoneyProvider.- Parameters:
moneyProvider- the money to check, null returns false- Returns:
- true if the money is non-null and negative
-
isNegativeOrZero
public static boolean isNegativeOrZero(BigMoneyProvider moneyProvider)
Checks if the monetary value is negative or zero, treating null as zero.This method accepts any implementation of
BigMoneyProvider.- Parameters:
moneyProvider- the money to check, null returns true- Returns:
- true if the money is null, zero or negative
-
max
public static Money max(Money money1, Money money2)
Finds the maximumMoneyvalue, handing null.This returns the greater of money1 or money2 where null is ignored. If both input values are null, then null is returned.
- Parameters:
money1- the first money instance, null returns money2money2- the first money instance, null returns money1- Returns:
- the maximum value, null if both inputs are null
- Throws:
CurrencyMismatchException- if the currencies differ
-
min
public static Money min(Money money1, Money money2)
Finds the minimumMoneyvalue, handing null.This returns the greater of money1 or money2 where null is ignored. If both input values are null, then null is returned.
- Parameters:
money1- the first money instance, null returns money2money2- the first money instance, null returns money1- Returns:
- the minimum value, null if both inputs are null
- Throws:
CurrencyMismatchException- if the currencies differ
-
add
public static Money add(Money money1, Money money2)
Adds twoMoneyobjects, handling null.This returns
money1 + money2where null is ignored. If both input values are null, then null is returned.- Parameters:
money1- the first money instance, null returns money2money2- the first money instance, null returns money1- Returns:
- the total, where null is ignored, null if both inputs are null
- Throws:
CurrencyMismatchException- if the currencies differ
-
subtract
public static Money subtract(Money money1, Money money2)
Subtracts the secondMoneyfrom the first, handling null.This returns
money1 - money2where null is ignored. If both input values are null, then null is returned.- Parameters:
money1- the first money instance, null treated as zeromoney2- the first money instance, null returns money1- Returns:
- the total, where null is ignored, null if both inputs are null
- Throws:
CurrencyMismatchException- if the currencies differ
-
max
public static BigMoney max(BigMoney money1, BigMoney money2)
Finds the maximumBigMoneyvalue, handing null.This returns the greater of money1 or money2 where null is ignored. If both input values are null, then null is returned.
- Parameters:
money1- the first money instance, null returns money2money2- the first money instance, null returns money1- Returns:
- the maximum value, null if both inputs are null
- Throws:
CurrencyMismatchException- if the currencies differ
-
min
public static BigMoney min(BigMoney money1, BigMoney money2)
Finds the minimumBigMoneyvalue, handing null.This returns the greater of money1 or money2 where null is ignored. If both input values are null, then null is returned.
- Parameters:
money1- the first money instance, null returns money2money2- the first money instance, null returns money1- Returns:
- the minimum value, null if both inputs are null
- Throws:
CurrencyMismatchException- if the currencies differ
-
add
public static BigMoney add(BigMoney money1, BigMoney money2)
Adds twoBigMoneyobjects, handling null.This returns
money1 + money2where null is ignored. If both input values are null, then null is returned.- Parameters:
money1- the first money instance, null returns money2money2- the first money instance, null returns money1- Returns:
- the total, where null is ignored, null if both inputs are null
- Throws:
CurrencyMismatchException- if the currencies differ
-
subtract
public static BigMoney subtract(BigMoney money1, BigMoney money2)
Subtracts the secondBigMoneyfrom the first, handling null.This returns
money1 - money2where null is ignored. If both input values are null, then null is returned.- Parameters:
money1- the first money instance, null treated as zeromoney2- the first money instance, null returns money1- Returns:
- the total, where null is ignored, null if both inputs are null
- Throws:
CurrencyMismatchException- if the currencies differ
-
-