Top Description Constructors Methods
org.joda.money

public final Class MoneyUtils

extends Object
Class Inheritance

Utilities for working with monetary values that handle null.

This utility class contains thread-safe static methods.

Constructor Summary

AccessConstructor and Description
private
MoneyUtils()

Private constructor.

Method Summary

Modifier and TypeMethod and Description
public static Money

Returns:

the total, where null is ignored, null if both inputs are null
add
(Money
the first money instance, null returns money2
money1
,
Money
the first money instance, null returns money1
money2
)

Adds two Money objects, handling null.

public static BigMoney

Returns:

the total, where null is ignored, null if both inputs are null
add
(BigMoney
the first money instance, null returns money2
money1
,
BigMoney
the first money instance, null returns money1
money2
)

Adds two BigMoney objects, handling null.

pack-priv static void
checkNotNull(Object
the object to check, not null
object
,
String message)

Validates that the object specified is not null.

public static boolean

Returns:

true if the money is non-null and negative
isNegative
(BigMoneyProvider
the money to check, null returns false
moneyProvider
)

Checks if the monetary value is negative and non-zero, treating null as zero.

public static boolean

Returns:

true if the money is null, zero or negative
isNegativeOrZero
(BigMoneyProvider
the money to check, null returns true
moneyProvider
)

Checks if the monetary value is negative or zero, treating null as zero.

public static boolean

Returns:

true if the money is non-null and positive
isPositive
(BigMoneyProvider
the money to check, null returns false
moneyProvider
)

Checks if the monetary value is positive and non-zero, treating null as zero.

public static boolean

Returns:

true if the money is null, zero or positive
isPositiveOrZero
(BigMoneyProvider
the money to check, null returns true
moneyProvider
)

Checks if the monetary value is positive or zero, treating null as zero.

public static boolean

Returns:

true if the money is null or zero
isZero
(BigMoneyProvider
the money to check, null returns zero
moneyProvider
)

Checks if the monetary value is zero, treating null as zero.

public static Money

Returns:

the maximum value, null if both inputs are null
max
(Money
the first money instance, null returns money2
money1
,
Money
the first money instance, null returns money1
money2
)

Finds the maximum Money value, handing null.

public static BigMoney

Returns:

the maximum value, null if both inputs are null
max
(BigMoney
the first money instance, null returns money2
money1
,
BigMoney
the first money instance, null returns money1
money2
)

Finds the maximum BigMoney value, handing null.

public static Money

Returns:

the minimum value, null if both inputs are null
min
(Money
the first money instance, null returns money2
money1
,
Money
the first money instance, null returns money1
money2
)

Finds the minimum Money value, handing null.

public static BigMoney

Returns:

the minimum value, null if both inputs are null
min
(BigMoney
the first money instance, null returns money2
money1
,
BigMoney
the first money instance, null returns money1
money2
)

Finds the minimum BigMoney value, handing null.

public static Money

Returns:

the total, where null is ignored, null if both inputs are null
subtract
(Money
the first money instance, null treated as zero
money1
,
Money
the first money instance, null returns money1
money2
)

Subtracts the second Money from the first, handling null.

public static BigMoney

Returns:

the total, where null is ignored, null if both inputs are null
subtract
(BigMoney
the first money instance, null treated as zero
money1
,
BigMoney
the first money instance, null returns money1
money2
)

Subtracts the second BigMoney from the first, handling null.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Constructor Detail

MoneyUtilsback to summary
private MoneyUtils()

Private constructor.

Method Detail

addback to summary
public static Money add(Money money1, Money money2)

Adds two Money objects, handling null.

This returns money1 + money2 where null is ignored. If both input values are null, then null is returned.

Parameters
money1:Money

the first money instance, null returns money2

money2:Money

the first money instance, null returns money1

Returns:Money

the total, where null is ignored, null if both inputs are null

Exceptions
CurrencyMismatchException:
if the currencies differ
addback to summary
public static BigMoney add(BigMoney money1, BigMoney money2)

Adds two BigMoney objects, handling null.

This returns money1 + money2 where null is ignored. If both input values are null, then null is returned.

Parameters
money1:BigMoney

the first money instance, null returns money2

money2:BigMoney

the first money instance, null returns money1

Returns:BigMoney

the total, where null is ignored, null if both inputs are null

Exceptions
CurrencyMismatchException:
if the currencies differ
checkNotNullback to summary
pack-priv static void checkNotNull(Object object, String message)

Validates that the object specified is not null.

Parameters
object:Object

the object to check, not null

Exceptions
NullPointerException:
if the input value is null
isNegativeback to summary
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:BigMoneyProvider

the money to check, null returns false

Returns:boolean

true if the money is non-null and negative

isNegativeOrZeroback to summary
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:BigMoneyProvider

the money to check, null returns true

Returns:boolean

true if the money is null, zero or negative

isPositiveback to summary
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:BigMoneyProvider

the money to check, null returns false

Returns:boolean

true if the money is non-null and positive

isPositiveOrZeroback to summary
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:BigMoneyProvider

the money to check, null returns true

Returns:boolean

true if the money is null, zero or positive

isZeroback to summary
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:BigMoneyProvider

the money to check, null returns zero

Returns:boolean

true if the money is null or zero

maxback to summary
public static Money max(Money money1, Money money2)

Finds the maximum Money value, 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:Money

the first money instance, null returns money2

money2:Money

the first money instance, null returns money1

Returns:Money

the maximum value, null if both inputs are null

Exceptions
CurrencyMismatchException:
if the currencies differ
maxback to summary
public static BigMoney max(BigMoney money1, BigMoney money2)

Finds the maximum BigMoney value, 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:BigMoney

the first money instance, null returns money2

money2:BigMoney

the first money instance, null returns money1

Returns:BigMoney

the maximum value, null if both inputs are null

Exceptions
CurrencyMismatchException:
if the currencies differ
minback to summary
public static Money min(Money money1, Money money2)

Finds the minimum Money value, 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:Money

the first money instance, null returns money2

money2:Money

the first money instance, null returns money1

Returns:Money

the minimum value, null if both inputs are null

Exceptions
CurrencyMismatchException:
if the currencies differ
minback to summary
public static BigMoney min(BigMoney money1, BigMoney money2)

Finds the minimum BigMoney value, 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:BigMoney

the first money instance, null returns money2

money2:BigMoney

the first money instance, null returns money1

Returns:BigMoney

the minimum value, null if both inputs are null

Exceptions
CurrencyMismatchException:
if the currencies differ
subtractback to summary
public static Money subtract(Money money1, Money money2)

Subtracts the second Money from the first, handling null.

This returns money1 - money2 where null is ignored. If both input values are null, then null is returned.

Parameters
money1:Money

the first money instance, null treated as zero

money2:Money

the first money instance, null returns money1

Returns:Money

the total, where null is ignored, null if both inputs are null

Exceptions
CurrencyMismatchException:
if the currencies differ
subtractback to summary
public static BigMoney subtract(BigMoney money1, BigMoney money2)

Subtracts the second BigMoney from the first, handling null.

This returns money1 - money2 where null is ignored. If both input values are null, then null is returned.

Parameters
money1:BigMoney

the first money instance, null treated as zero

money2:BigMoney

the first money instance, null returns money1

Returns:BigMoney

the total, where null is ignored, null if both inputs are null

Exceptions
CurrencyMismatchException:
if the currencies differ