Class SplitRoundingHelper


  • public class SplitRoundingHelper
    extends Object
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      javax.money.MonetaryAmount getUnitAmount​(javax.money.CurrencyUnit currency)
      Determines the smallest unit amount of money for the CurrencyUnit.
      List<javax.money.MonetaryAmount> roundIndependentSplitAmount​(List<javax.money.MonetaryAmount> splitAmounts)
      Round amounts which were split.
      <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.
    • Constructor Detail

      • SplitRoundingHelper

        public SplitRoundingHelper()
    • Method Detail

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