Class MoneyRoundingHelper


  • public class MoneyRoundingHelper
    extends Object
    Helper class to calculate rounding of monetary unit amounts from offer adjustments.
    Author:
    Marie Standeven (marieStandeven), Sunny Yu
    • Constructor Detail

      • MoneyRoundingHelper

        public MoneyRoundingHelper()
    • Method Detail

      • 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 return
        totalAmount - 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 given EnhancedProratedOfferAdjustments
        Parameters:
        proratedAdjustments - the EnhancedProratedOfferAdjustments to update
        proratedAdjustmentAmounts - a map of rounded adjustment amounts by item line numbers
        currency - 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 return
        totalAmount - the total adjustment amount
        unitAmount - 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 the CurrencyUnit.

        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