Class MoneyRoundingHelper
java.lang.Object
com.broadleafcommerce.promotion.offer.service.engine.proration.MoneyRoundingHelper
Helper class to calculate rounding of monetary unit amounts from offer adjustments.
- Author:
- Marie Standeven (marieStandeven), Sunny Yu
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionprotected OfferServiceProperties
protected javax.money.MonetaryAmount
getUnitAmount
(javax.money.CurrencyUnit currency) Determines the smallest unit amount of money for theCurrencyUnit
.roundListOfMonetaryAmounts
(Map<String, javax.money.MonetaryAmount> amounts, javax.money.MonetaryAmount totalAmount, javax.money.CurrencyUnit currency) Given a list of amounts that should round to the provided total, calculates and performs the rounding logic to add the remainder unit amounts.roundListOfMonetaryAmounts
(Map<String, javax.money.MonetaryAmount> amounts, javax.money.MonetaryAmount totalAmount, javax.money.MonetaryAmount unitAmount) Given a list of amounts that should round to the provided total, calculates and performs the rounding logic to add the remainder unit amounts.<D extends EnhancedProratedOfferAdjustment>
voidroundProratedAdjustments
(Collection<D> proratedOfferAdjustments, javax.money.MonetaryAmount adjustmentsTotal, javax.money.CurrencyUnit currency) Rounds the givenEnhancedProratedOfferAdjustments
.<D extends EnhancedProratedOfferAdjustment>
voidroundProratedFulfillmentGroupAdjustments
(EnhancedFulfillmentGroup group, Collection<D> proratedOfferAdjustments, javax.money.MonetaryAmount adjustmentsTotal, javax.money.CurrencyUnit currency) Rounds the givenEnhancedFulfillmentGroup.getProratedFulfillmentAdjustments()
andEnhancedProratedOfferAdjustments
.void
setOfferServiceProperties
(OfferServiceProperties offerServiceProperties) protected <D extends EnhancedProratedOfferAdjustment>
voidupdateProratedAdjustmentsWithRoundedAdjustments
(Collection<D> proratedAdjustments, Map<String, javax.money.MonetaryAmount> proratedAdjustmentAmounts, javax.money.CurrencyUnit currency) Sets the new rounded adjustment values on the givenEnhancedProratedOfferAdjustments
-
Constructor Details
-
MoneyRoundingHelper
public MoneyRoundingHelper()
-
-
Method Details
-
roundProratedAdjustments
public <D extends EnhancedProratedOfferAdjustment> void roundProratedAdjustments(Collection<D> proratedOfferAdjustments, javax.money.MonetaryAmount adjustmentsTotal, javax.money.CurrencyUnit currency) Rounds the givenEnhancedProratedOfferAdjustments
.- Parameters:
proratedOfferAdjustments
- theEnhancedProratedOfferAdjustments
to roundadjustmentsTotal
- the total adjustment amountcurrency
- the currency of the amounts to round
-
roundProratedFulfillmentGroupAdjustments
public <D extends EnhancedProratedOfferAdjustment> void roundProratedFulfillmentGroupAdjustments(EnhancedFulfillmentGroup group, Collection<D> proratedOfferAdjustments, javax.money.MonetaryAmount adjustmentsTotal, javax.money.CurrencyUnit currency) Rounds the givenEnhancedFulfillmentGroup.getProratedFulfillmentAdjustments()
andEnhancedProratedOfferAdjustments
.- Parameters:
group
- theEnhancedFulfillmentGroup
to round theEnhancedFulfillmentGroup.getProratedFulfillmentAdjustments()
forproratedOfferAdjustments
- theEnhancedProratedOfferAdjustments
to roundadjustmentsTotal
- the total adjustment amountcurrency
- the currency of the amounts to round
-
roundListOfMonetaryAmounts
public Map<String,javax.money.MonetaryAmount> roundListOfMonetaryAmounts(Map<String, javax.money.MonetaryAmount> amounts, javax.money.MonetaryAmount totalAmount, javax.money.CurrencyUnit currency) Given a list of amounts that should round to the provided total, calculates and performs the rounding logic to add the remainder unit amounts.- Parameters:
amounts
- list of amounts to round, mapped to a key for lookup on returntotalAmount
- the total adjustment amount
-
updateProratedAdjustmentsWithRoundedAdjustments
protected <D extends EnhancedProratedOfferAdjustment> void updateProratedAdjustmentsWithRoundedAdjustments(Collection<D> proratedAdjustments, Map<String, javax.money.MonetaryAmount> proratedAdjustmentAmounts, javax.money.CurrencyUnit currency) Sets the new rounded adjustment values on the givenEnhancedProratedOfferAdjustments
- Parameters:
proratedAdjustments
- theEnhancedProratedOfferAdjustments
to updateproratedAdjustmentAmounts
- a map of rounded adjustment amounts by item line numberscurrency
- the currency of the amounts to round
-
roundListOfMonetaryAmounts
protected Map<String,javax.money.MonetaryAmount> roundListOfMonetaryAmounts(Map<String, javax.money.MonetaryAmount> amounts, javax.money.MonetaryAmount totalAmount, javax.money.MonetaryAmount unitAmount) Given a list of amounts that should round to the provided total, calculates and performs the rounding logic to add the remainder unit amounts.If
OfferServiceProperties.isDistributeRoundedRemainders()
istrue
, the rounded remainders are distributed across all the amounts. For example, rounding 7 of $0.71428 with the total of $5 would result in 4 of $0.71 and 3 of $0.72. If set tofalse
, the remainders would be added to one single amount, resulting 6 of $0.71 and 1 of $0.74.- Parameters:
amounts
- list of amounts to round, mapped to a key for lookup on returntotalAmount
- the total adjustment amountunitAmount
- the smallest unit amount of money for the currency
-
getUnitAmount
protected javax.money.MonetaryAmount getUnitAmount(javax.money.CurrencyUnit currency) Determines the smallest unit amount of money for theCurrencyUnit
.For example, a currency with 2 fraction digits (like USD) will provide the amount "0.01".
- Parameters:
currency
- the currency to get the smallest unit amount for- Returns:
- the smallest unit amount of money for the currency
-
getOfferServiceProperties
-
setOfferServiceProperties
-