Class 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 Detail

      • SplitAmount

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

      • 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.

      • 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

        public List<javax.money.MonetaryAmount> getSplitAmounts()
      • getSplitRemainders

        public List<javax.money.MonetaryAmount> getSplitRemainders()
      • getUnitsOffTotal

        public int getUnitsOffTotal()
      • setSplitAmounts

        protected void setSplitAmounts​(List<javax.money.MonetaryAmount> splitAmounts)
      • setUnitsOffTotal

        protected void setUnitsOffTotal​(int unitsOffTotal)