Class SplitTotalRounder.SplitAmount
java.lang.Object
com.broadleafcommerce.orderoperation.service.split.SplitTotalRounder.SplitAmount
- Enclosing class:
- SplitTotalRounder
Represents an amount value that has been split into multiple new amounts.
Tracks the original value of the amount, to allow adjusting the split amounts so that they sum to that total once rounded.
-
Constructor Summary
ConstructorsConstructorDescriptionSplitAmount(List<javax.money.MonetaryAmount> splitAmounts, javax.money.MonetaryAmount unitAmount) SplitAmount(List<javax.money.MonetaryAmount> splitAmounts, javax.money.MonetaryAmount originalTotal, javax.money.MonetaryAmount unitAmount) -
Method Summary
Modifier and TypeMethodDescriptionjavax.money.MonetaryAmountThe original total, which is the target which the contained amounts should sum to after rounding is complete.protected javax.money.MonetaryAmountgetRemainder(javax.money.MonetaryAmount amount) Get the remainder of the amount compared to its rounded floor value.getScale()The scale to use when rounding the amountsList<javax.money.MonetaryAmount>The amounts which were split.List<javax.money.MonetaryAmount>The fractional components of the split amounts, for any amount which is smaller than the smallest currency unit.javax.money.MonetaryAmountThe smallest unit of the currency.intThe number ofunitAmountsby which the current amount total deviates from the original total.voidincrement(int index) Adds a unit to the amount at a certain index.voidRounds the contained amounts so that the split amounts sum to the original total.voidRound the contained amounts to the floor, and calculates how many units the new sum of rounded amounts is off from the original total.protected javax.money.MonetaryAmountroundFloor(javax.money.MonetaryAmount amount) protected voidThe scale to use when rounding the amountsprotected voidsetSplitAmounts(List<javax.money.MonetaryAmount> splitAmounts) The amounts which were split.protected voidsetUnitsOffTotal(int unitsOffTotal) The number ofunitAmountsby which the current amount total deviates from the original total.
-
Constructor Details
-
Method Details
-
getRemainder
protected javax.money.MonetaryAmount getRemainder(javax.money.MonetaryAmount amount) Get the remainder of the amount compared to its rounded floor value.- Parameters:
amount- the amount to get the remainder for compared to its floor value- Returns:
- the positive amount lost when then value is rounded to floor
-
roundFloor
public void roundFloor()Round the contained amounts to the floor, and calculates how many units the new sum of rounded amounts is off from the original total.This is a prerequisite step to take prior to rounding.
-
roundFloor
protected javax.money.MonetaryAmount roundFloor(javax.money.MonetaryAmount amount) -
increment
public void increment(int index) Adds a unit to the amount at a certain index. -
roundAmounts
public void roundAmounts()Rounds the contained amounts so that the split amounts sum to the original total.All amounts are first rounded to floor, and then units are distributed for each side of the split.
Does not account for each split amount adding up to any other totals. See
SplitTotalRounder.roundAmounts()for that functionality. -
getOriginalTotal
public javax.money.MonetaryAmount getOriginalTotal()The original total, which is the target which the contained amounts should sum to after rounding is complete. -
getUnitAmount
public javax.money.MonetaryAmount getUnitAmount()The smallest unit of the currency. -
getSplitAmounts
The amounts which were split. -
getSplitRemainders
The fractional components of the split amounts, for any amount which is smaller than the smallest currency unit.The amount with the highest remainder is the one which should have the highest precedence for being rounded up.
-
getUnitsOffTotal
public int getUnitsOffTotal()The number ofunitAmountsby which the current amount total deviates from the original total.This is the number of times which a contained amount should be incremented in order to complete rounding.
-
getScale
The scale to use when rounding the amounts -
setSplitAmounts
The amounts which were split. -
setUnitsOffTotal
protected void setUnitsOffTotal(int unitsOffTotal) The number ofunitAmountsby which the current amount total deviates from the original total.This is the number of times which a contained amount should be incremented in order to complete rounding.
-
setScale
The scale to use when rounding the amounts
-