Class CartPricingRoundingHelper
- java.lang.Object
-
- com.broadleafcommerce.cartoperation.service.pricing.CartPricingRoundingHelper
-
public class CartPricingRoundingHelper extends Object
Helper class to calculate rounding of monetary unit amounts for cart pricing.- Author:
- Marie Standeven (marieStandeven)
-
-
Constructor Summary
Constructors Constructor Description CartPricingRoundingHelper()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected javax.money.MonetaryAmount
getUnitAmount(javax.money.CurrencyUnit currency)
Determines the smallest unit amount of money for theCurrencyUnit
.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.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.void
roundProratedFulfillmentGroupAdjustments(@NonNull com.broadleafcommerce.cart.client.domain.FulfillmentGroup group, @NonNull javax.money.CurrencyUnit currency)
Rounds prorated amounts for prorated fulfillment group adjustments on fulfillment items and group.<D extends com.broadleafcommerce.cart.client.domain.FulfillmentItem>
voidroundProratedOrderAdjustmentsAcrossFulfillmentItems(Collection<D> fulfillmentItems, javax.money.MonetaryAmount orderAdjustmentsTotal, javax.money.CurrencyUnit currency)
Rounds prorated amounts for prorated order adjustments on fulfillment items.protected <D extends com.broadleafcommerce.cart.client.domain.FulfillmentItem>
voidupdateFulfillmentItemsWithRoundedAdjustments(Collection<D> fulfillmentItems, Map<String,javax.money.MonetaryAmount> proratedOrderAdjustmentAmounts, javax.money.CurrencyUnit currency)
Sets the new rounded adjustment values on the fulfillment items.
-
-
-
Method Detail
-
roundProratedOrderAdjustmentsAcrossFulfillmentItems
public <D extends com.broadleafcommerce.cart.client.domain.FulfillmentItem> void roundProratedOrderAdjustmentsAcrossFulfillmentItems(Collection<D> fulfillmentItems, javax.money.MonetaryAmount orderAdjustmentsTotal, javax.money.CurrencyUnit currency)
Rounds prorated amounts for prorated order adjustments on fulfillment items.- Parameters:
fulfillmentItems
- the collection of fulfillment itemsorderAdjustmentsTotal
- the total adjustment amountcurrency
- the currency of the amounts to round
-
roundProratedFulfillmentGroupAdjustments
public void roundProratedFulfillmentGroupAdjustments(@NonNull @NonNull com.broadleafcommerce.cart.client.domain.FulfillmentGroup group, @NonNull @NonNull javax.money.CurrencyUnit currency)
Rounds prorated amounts for prorated fulfillment group adjustments on fulfillment items and group.- Parameters:
group
- theFulfillmentGroup
with prices to be roundedcurrency
- 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
-
updateFulfillmentItemsWithRoundedAdjustments
protected <D extends com.broadleafcommerce.cart.client.domain.FulfillmentItem> void updateFulfillmentItemsWithRoundedAdjustments(Collection<D> fulfillmentItems, Map<String,javax.money.MonetaryAmount> proratedOrderAdjustmentAmounts, javax.money.CurrencyUnit currency)
Sets the new rounded adjustment values on the fulfillment items.- Parameters:
fulfillmentItems
- the collection of fulfillment itemsproratedOrderAdjustmentAmounts
- a mapping of fulfillment item reference numbers to the rounded adjustment amountcurrency
- 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.- 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
-
-