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
ConstructorDescriptionSplitAmount
(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.MonetaryAmount
protected javax.money.MonetaryAmount
getRemainder
(javax.money.MonetaryAmount amount) Get the remainder of the amount compared to its rounded floor value.getScale()
List<javax.money.MonetaryAmount>
List<javax.money.MonetaryAmount>
javax.money.MonetaryAmount
int
void
increment
(int index) Adds a unit to the amount at a certain index.void
Rounds the contained amounts so that the split amounts sum to the original total.void
Round 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.MonetaryAmount
roundFloor
(javax.money.MonetaryAmount amount) protected void
protected void
setSplitAmounts
(List<javax.money.MonetaryAmount> splitAmounts) protected void
setUnitsOffTotal
(int unitsOffTotal)
-
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() -
getUnitAmount
public javax.money.MonetaryAmount getUnitAmount() -
getSplitAmounts
-
getSplitRemainders
-
getUnitsOffTotal
public int getUnitsOffTotal() -
getScale
-
setSplitAmounts
-
setUnitsOffTotal
protected void setUnitsOffTotal(int unitsOffTotal) -
setScale
-