Class MoneyExpressionVariable
java.lang.Object
com.broadleafcommerce.rulesengine.expression.util.MoneyExpressionVariable
- All Implemented Interfaces:
ExpressionVariable
Common, null-safe, operations for the
MonetaryAmount
fields.- Author:
- Dima Myroniuk (dmyroniuk)
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionjavax.money.MonetaryAmount
Resolves a monetary amount from an object map.getName()
double
Converts the object map into a monetary amount and returns the double value of that amount.double
toDouble
(javax.money.MonetaryAmount field) Returns the double value of theMonetaryAmount
field.double
toDouble
(javax.money.MonetaryAmount field, double defaultValue) Returns the double value of theMonetaryAmount
field.
-
Field Details
-
NAME
- See Also:
-
-
Constructor Details
-
MoneyExpressionVariable
public MoneyExpressionVariable()
-
-
Method Details
-
getName
- Specified by:
getName
in interfaceExpressionVariable
- Returns:
- Name of the variable, must not be null
-
toDouble
public double toDouble(@Nullable javax.money.MonetaryAmount field) - Parameters:
field
- MonetaryAmount to convert to double.- Returns:
- the double value of the
MonetaryAmount
field orDouble.MIN_VALUE
if null.
-
toDouble
Converts the object map into a monetary amount and returns the double value of that amount. If the monetary amount cannot be resolved, returnsDouble.MIN_VALUE
.- Parameters:
objectMap
- the map of the monetary amount object to get the double value of- Returns:
- the double value of the object map, or
Double.MIN_VALUE
if it cannot be resolved
-
toDouble
public double toDouble(@Nullable javax.money.MonetaryAmount field, double defaultValue) Returns the double value of theMonetaryAmount
field. Iffield
is null, returnsdefaultValue
.- Parameters:
field
- MonetaryAmount to convert to double.defaultValue
- Value to default to iffield
is null- Returns:
- the double value of the
MonetaryAmount
field ordefaultValue
if null.
-
fromMap
Resolves a monetary amount from an object map. This is necessary for cases when JSON has been deserialized as a simple map (i.e.Map<String, Object>
), and a monetary amount needs to be retrieved from that object.- Parameters:
objectMap
- the object map to convert the monetary amount from- Returns:
- the monetary amount, or null if the required information is not present or correct
-