Class SplitTotalRounder.SplitAmount

java.lang.Object
com.broadleafcommerce.orderoperation.service.split.SplitTotalRounder.SplitAmount
Enclosing class:
SplitTotalRounder

public static class SplitTotalRounder.SplitAmount extends Object
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

    Constructors
    Constructor
    Description
    SplitAmount(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 Type
    Method
    Description
    javax.money.MonetaryAmount
    The original total, which is the target which the contained amounts should sum to after rounding is complete.
    protected javax.money.MonetaryAmount
    getRemainder(javax.money.MonetaryAmount amount)
    Get the remainder of the amount compared to its rounded floor value.
    The scale to use when rounding the amounts
    List<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.MonetaryAmount
    The smallest unit of the currency.
    int
    The number of unitAmounts by which the current amount total deviates from the original total.
    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
    The scale to use when rounding the amounts
    protected void
    setSplitAmounts(List<javax.money.MonetaryAmount> splitAmounts)
    The amounts which were split.
    protected void
    setUnitsOffTotal(int unitsOffTotal)
    The number of unitAmounts by which the current amount total deviates from the original total.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • SplitAmount

      public SplitAmount(List<javax.money.MonetaryAmount> splitAmounts, javax.money.MonetaryAmount unitAmount)
    • SplitAmount

      public SplitAmount(List<javax.money.MonetaryAmount> splitAmounts, javax.money.MonetaryAmount originalTotal, javax.money.MonetaryAmount unitAmount)
  • 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

      public List<javax.money.MonetaryAmount> getSplitAmounts()
      The amounts which were split.
    • getSplitRemainders

      public List<javax.money.MonetaryAmount> 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 of unitAmounts by 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

      @Nullable public Integer getScale()
      The scale to use when rounding the amounts
    • setSplitAmounts

      protected void setSplitAmounts(List<javax.money.MonetaryAmount> splitAmounts)
      The amounts which were split.
    • setUnitsOffTotal

      protected void setUnitsOffTotal(int unitsOffTotal)
      The number of unitAmounts by 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

      protected void setScale(@Nullable Integer scale)
      The scale to use when rounding the amounts