This utility class contains thread-safe static methods.
-
Method Summary
Modifier and TypeMethodDescriptionstatic BigMoneyAdds twoBigMoneyobjects, handling null.static MoneyAdds twoMoneyobjects, handling 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 BigMoneyFinds the maximumBigMoneyvalue, handing null.static MoneyFinds the maximumMoneyvalue, handing null.static BigMoneyFinds the minimumBigMoneyvalue, handing null.static MoneyFinds the minimumMoneyvalue, handing null.static BigMoneySubtracts the secondBigMoneyfrom the first, handling null.static MoneySubtracts the secondMoneyfrom the first, handling null.
-
Method Details
-
isZero
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
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
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
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
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
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
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
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
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
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
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
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
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
-