Class SplitRoundingHelper

java.lang.Object
com.broadleafcommerce.orderoperation.service.split.SplitRoundingHelper

public class SplitRoundingHelper extends Object
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    javax.money.MonetaryAmount
    getUnitAmount(javax.money.CurrencyUnit currency)
    Determines the smallest unit amount of money for the CurrencyUnit.
    javax.money.MonetaryAmount
    getUnitAmount(javax.money.CurrencyUnit currency, Integer scale)
    Determines the smallest unit amount of money for the CurrencyUnit and scale.
    <T> void
    performObjectsRounding(List<T> objects, Function<T,javax.money.MonetaryAmount> getter, BiConsumer<T,javax.money.MonetaryAmount> setter, javax.money.MonetaryAmount originalTotal)
    Rounds the amounts of the given objects based on the amount getter and setter.
    <T> void
    performObjectsRounding(List<T> objects, Function<T,javax.money.MonetaryAmount> getter, BiConsumer<T,javax.money.MonetaryAmount> setter, javax.money.MonetaryAmount originalTotal, Integer scale)
    Rounds the amounts of the given objects based on the amount getter and setter.
    List<javax.money.MonetaryAmount>
    roundIndependentSplitAmount(List<javax.money.MonetaryAmount> splitAmounts)
    Round amounts which were split.
    List<javax.money.MonetaryAmount>
    roundIndependentSplitAmount(List<javax.money.MonetaryAmount> splitAmounts, javax.money.MonetaryAmount originalTotal)
    Round amounts which were split, with specified SplitTotalRounder.SplitAmount.getOriginalTotal().
    List<javax.money.MonetaryAmount>
    roundIndependentSplitAmount(List<javax.money.MonetaryAmount> splitAmounts, javax.money.MonetaryAmount originalTotal, Integer scale)
    Round amounts which were split, with specified SplitTotalRounder.SplitAmount.getOriginalTotal().
    <T> List<List<javax.money.MonetaryAmount>>
    roundListPartsOfTotal(List<List<T>> splits, Function<T,javax.money.MonetaryAmount> getter, BiConsumer<T,javax.money.MonetaryAmount> setter, List<javax.money.MonetaryAmount> splitTargetTotals, com.broadleafcommerce.order.client.domain.OrderFulfillment originalFulfillment)
    Round split amounts from lists of objects which need to add up to a given target total.
    <T> List<List<javax.money.MonetaryAmount>>
    roundListPartsOfTotal(List<List<T>> splits, Function<T,javax.money.MonetaryAmount> getter, BiConsumer<T,javax.money.MonetaryAmount> setter, List<javax.money.MonetaryAmount> splitTargetTotals, com.broadleafcommerce.order.client.domain.OrderFulfillment originalFulfillment, javax.money.CurrencyUnit currency)
    Round split amounts from lists of objects which need to add up to a given target total.
    <T> List<List<javax.money.MonetaryAmount>>
    roundListPartsOfTotal(List<List<T>> splits, Function<T,javax.money.MonetaryAmount> getter, BiConsumer<T,javax.money.MonetaryAmount> setter, List<javax.money.MonetaryAmount> splitTargetTotals, javax.money.CurrencyUnit currency)
    Round split amounts from lists of objects which need to add up to a given target total.
    List<List<javax.money.MonetaryAmount>>
    roundPartsOfTotal(List<javax.money.MonetaryAmount> splitTargetTotals, List<List<javax.money.MonetaryAmount>> splitAmounts, javax.money.CurrencyUnit currency)
    Round monetary amounts which need to match up to a list of given target totals.
    <T> List<List<javax.money.MonetaryAmount>>
    roundPartsOfTotal(List<T> splits, List<Function<T,javax.money.MonetaryAmount>> getters, List<BiConsumer<T,javax.money.MonetaryAmount>> setters, List<javax.money.MonetaryAmount> splitTargetTotals, com.broadleafcommerce.order.client.domain.OrderFulfillment originalFulfillment)
    Round split amounts on some object which need to add up to a given target total.
    <T> List<List<javax.money.MonetaryAmount>>
    roundPartsOfTotal(List<T> splits, List<Function<T,javax.money.MonetaryAmount>> getters, List<BiConsumer<T,javax.money.MonetaryAmount>> setters, List<javax.money.MonetaryAmount> splitTargetTotals, com.broadleafcommerce.order.client.domain.OrderFulfillment originalFulfillment, javax.money.CurrencyUnit currency)
    Round split amounts on some object which need to add up to a given target total.
    <T> List<List<javax.money.MonetaryAmount>>
    roundPartsOfTotal(List<T> splits, List<Function<T,javax.money.MonetaryAmount>> getters, List<BiConsumer<T,javax.money.MonetaryAmount>> setters, List<javax.money.MonetaryAmount> splitTargetTotals, javax.money.CurrencyUnit currency)
    Round split amounts on some object which need to add up to a given target total.

    Methods inherited from class java.lang.Object

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

    • SplitRoundingHelper

      public SplitRoundingHelper()
  • Method Details

    • roundIndependentSplitAmount

      public List<javax.money.MonetaryAmount> roundIndependentSplitAmount(List<javax.money.MonetaryAmount> splitAmounts)
      Round amounts which were split.

      To be used only for amounts which don't add in to some other total.

      Parameters:
      splitAmounts - the amount which was leftover after splitting part off
      Returns:
      a list of the rounded versions of the given amounts
    • roundIndependentSplitAmount

      public List<javax.money.MonetaryAmount> roundIndependentSplitAmount(List<javax.money.MonetaryAmount> splitAmounts, javax.money.MonetaryAmount originalTotal)
      Round amounts which were split, with specified SplitTotalRounder.SplitAmount.getOriginalTotal().
      Parameters:
      splitAmounts - the amount which was leftover after splitting part off
      originalTotal - the totals which the amounts from each of splits should sum to
      Returns:
      a list of the rounded versions of the given amounts
    • roundIndependentSplitAmount

      public List<javax.money.MonetaryAmount> roundIndependentSplitAmount(List<javax.money.MonetaryAmount> splitAmounts, javax.money.MonetaryAmount originalTotal, @Nullable Integer scale)
      Round amounts which were split, with specified SplitTotalRounder.SplitAmount.getOriginalTotal().
      Parameters:
      splitAmounts - the amount which was leftover after splitting part off
      originalTotal - the totals which the amounts from each of splits should sum to
      scale - the scale to use when rounding the amounts
      Returns:
      a list of the rounded versions of the given amounts
    • performObjectsRounding

      public <T> void performObjectsRounding(List<T> objects, Function<T,javax.money.MonetaryAmount> getter, BiConsumer<T,javax.money.MonetaryAmount> setter, javax.money.MonetaryAmount originalTotal)
      Rounds the amounts of the given objects based on the amount getter and setter.
      Parameters:
      objects - the objects to round
      getter - the getter for the MonetaryAmount field to round
      setter - the setter for the MonetaryAmount field to round
      originalTotal - the original total
    • performObjectsRounding

      public <T> void performObjectsRounding(List<T> objects, Function<T,javax.money.MonetaryAmount> getter, BiConsumer<T,javax.money.MonetaryAmount> setter, javax.money.MonetaryAmount originalTotal, @Nullable Integer scale)
      Rounds the amounts of the given objects based on the amount getter and setter.
      Parameters:
      objects - the objects to round
      getter - the getter for the MonetaryAmount field to round
      setter - the setter for the MonetaryAmount field to round
      originalTotal - the original total
      scale - the scale to use when rounding the amounts
    • roundPartsOfTotal

      public <T> List<List<javax.money.MonetaryAmount>> roundPartsOfTotal(List<T> splits, List<Function<T,javax.money.MonetaryAmount>> getters, List<BiConsumer<T,javax.money.MonetaryAmount>> setters, List<javax.money.MonetaryAmount> splitTargetTotals, javax.money.CurrencyUnit currency)
      Round split amounts on some object which need to add up to a given target total.
      Type Parameters:
      T - the type of the domain which contains the amounts
      Parameters:
      splits - the objects which were split
      getters - functions to get the amounts which were split
      setters - functions to set the newly rounded amounts which were split
      splitTargetTotals - the totals which the amounts from each of splits should sum to
      currency - the currency of the amounts to round
      Returns:
      a list containing the lists of rounded parts
    • roundPartsOfTotal

      public <T> List<List<javax.money.MonetaryAmount>> roundPartsOfTotal(List<T> splits, List<Function<T,javax.money.MonetaryAmount>> getters, List<BiConsumer<T,javax.money.MonetaryAmount>> setters, List<javax.money.MonetaryAmount> splitTargetTotals, com.broadleafcommerce.order.client.domain.OrderFulfillment originalFulfillment)
      Round split amounts on some object which need to add up to a given target total.
      Type Parameters:
      T - the type of the domain which contains the amounts
      Parameters:
      splits - the objects which were split
      getters - functions to get the amounts which were split
      setters - functions to set the newly rounded amounts which were split
      splitTargetTotals - the totals which the amounts from each of splits should sum to
      originalFulfillment - the original fulfillment which was split
      Returns:
      a list containing the lists of rounded parts
    • roundPartsOfTotal

      public <T> List<List<javax.money.MonetaryAmount>> roundPartsOfTotal(List<T> splits, List<Function<T,javax.money.MonetaryAmount>> getters, List<BiConsumer<T,javax.money.MonetaryAmount>> setters, List<javax.money.MonetaryAmount> splitTargetTotals, @Nullable com.broadleafcommerce.order.client.domain.OrderFulfillment originalFulfillment, javax.money.CurrencyUnit currency)
      Round split amounts on some object which need to add up to a given target total.
      Type Parameters:
      T - the type of the domain which contains the amounts
      Parameters:
      splits - the objects which were split
      getters - functions to get the amounts which were split
      setters - functions to set the newly rounded amounts which were split
      splitTargetTotals - the totals which the amounts from each of splits should sum to
      originalFulfillment - the original fulfillment which was split, if present
      currency - the currency of the amounts to round
      Returns:
      a list containing the lists of rounded parts
    • roundPartsOfTotal

      public List<List<javax.money.MonetaryAmount>> roundPartsOfTotal(List<javax.money.MonetaryAmount> splitTargetTotals, List<List<javax.money.MonetaryAmount>> splitAmounts, javax.money.CurrencyUnit currency)
      Round monetary amounts which need to match up to a list of given target totals.

      An explanation of the arguments:

      • splitTargetTotals: The target totals.
      • splitAmounts: A list of lists. Contains split amounts that are not rounded.
      For splitTargetTotals, this is the desired total for a particular list in splitAmounts.

      For example, if splitTargetTotals at index 0 is 1.00, then the list of monetary amounts in splitAmounts at index 0 should add up to 1.00. The splitAmounts should not be rounded yet, so they could three items with 0.333333... that add up to ~1.00.

      Parameters:
      splitAmounts - The split amounts, in order
      splitTargetTotals - The split target totals, in order
      currency - The currency
      Returns:
      A list of lists of monetary amounts. These will be in the same order as the splitAmounts list.
    • roundListPartsOfTotal

      public <T> List<List<javax.money.MonetaryAmount>> roundListPartsOfTotal(List<List<T>> splits, Function<T,javax.money.MonetaryAmount> getter, BiConsumer<T,javax.money.MonetaryAmount> setter, List<javax.money.MonetaryAmount> splitTargetTotals, javax.money.CurrencyUnit currency)
      Round split amounts from lists of objects which need to add up to a given target total.
      Type Parameters:
      T - the type of the domain which contains the amount
      Parameters:
      splits - list of domains which were split, containing lists of their split elements
      getter - function to get the amount which was split
      setter - function to set the newly rounded amount which was split
      splitTargetTotals - the totals which the amounts from each element of splits should sum to
      currency - the currency of the amounts to round
      Returns:
      a list containing the list of rounded amounts for each split part
    • roundListPartsOfTotal

      public <T> List<List<javax.money.MonetaryAmount>> roundListPartsOfTotal(List<List<T>> splits, Function<T,javax.money.MonetaryAmount> getter, BiConsumer<T,javax.money.MonetaryAmount> setter, List<javax.money.MonetaryAmount> splitTargetTotals, com.broadleafcommerce.order.client.domain.OrderFulfillment originalFulfillment)
      Round split amounts from lists of objects which need to add up to a given target total.
      Type Parameters:
      T - the type of the domain which contains the amount
      Parameters:
      splits - list of domains which were split, containing lists of their split elements
      getter - function to get the amount which was split
      setter - function to set the newly rounded amount which was split
      splitTargetTotals - the totals which the amounts from each element of splits should sum to
      originalFulfillment - the original fulfillment which was split
      Returns:
      a list containing the list of rounded amounts for each split part
    • roundListPartsOfTotal

      public <T> List<List<javax.money.MonetaryAmount>> roundListPartsOfTotal(List<List<T>> splits, Function<T,javax.money.MonetaryAmount> getter, BiConsumer<T,javax.money.MonetaryAmount> setter, List<javax.money.MonetaryAmount> splitTargetTotals, @Nullable com.broadleafcommerce.order.client.domain.OrderFulfillment originalFulfillment, javax.money.CurrencyUnit currency)
      Round split amounts from lists of objects which need to add up to a given target total.
      Type Parameters:
      T - the type of the domain which contains the amount
      Parameters:
      splits - list of domains which were split, containing lists of their split elements
      getter - function to get the amount which was split
      setter - function to set the newly rounded amount which was split
      splitTargetTotals - the totals which the amounts from each element of splits should sum to
      originalFulfillment - the original fulfillment which was split, if present
      currency - the currency of the amounts to round
      Returns:
      a list containing the list of rounded amounts for each split part
    • getUnitAmount

      public 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
    • getUnitAmount

      public javax.money.MonetaryAmount getUnitAmount(javax.money.CurrencyUnit currency, @Nullable Integer scale)
      Determines the smallest unit amount of money for the CurrencyUnit and scale.

      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
      scale - the scale to use when rounding the amounts, CurrencyUnit.getDefaultFractionDigits() is used if null is provided
      Returns:
      the smallest unit amount of money for the currency