Class MoneyExpressionVariable
- java.lang.Object
-
- com.broadleafcommerce.rulesengine.expression.util.MoneyExpressionVariable
-
- All Implemented Interfaces:
ExpressionVariable
public class MoneyExpressionVariable extends Object implements ExpressionVariable
Common, null-safe, operations for theMonetaryAmount
fields.- Author:
- Dima Myroniuk (dmyroniuk)
-
-
Constructor Summary
Constructors Constructor Description MoneyExpressionVariable()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description javax.money.MonetaryAmount
fromMap(Map<String,Object> objectMap)
Resolves a monetary amount from an object map.String
getName()
double
toDouble(Map<String,Object> objectMap)
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 Detail
-
NAME
public static final String NAME
- See Also:
- Constant Field Values
-
-
Method Detail
-
getName
public String 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
public double toDouble(@Nullable Map<String,Object> objectMap)
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
@Nullable public javax.money.MonetaryAmount fromMap(@Nullable Map<String,Object> objectMap)
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
-
-