Class SplitRoundingHelper
java.lang.Object
com.broadleafcommerce.orderoperation.service.split.SplitRoundingHelper
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionjavax.money.MonetaryAmountgetUnitAmount(javax.money.CurrencyUnit currency) Determines the smallest unit amount of money for theCurrencyUnit.javax.money.MonetaryAmountgetUnitAmount(javax.money.CurrencyUnit currency, Integer scale) Determines the smallest unit amount of money for theCurrencyUnitand scale.<T> voidperformObjectsRounding(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> voidperformObjectsRounding(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 specifiedSplitTotalRounder.SplitAmount.getOriginalTotal().List<javax.money.MonetaryAmount>roundIndependentSplitAmount(List<javax.money.MonetaryAmount> splitAmounts, javax.money.MonetaryAmount originalTotal, Integer scale) Round amounts which were split, with specifiedSplitTotalRounder.SplitAmount.getOriginalTotal().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.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.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.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.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.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.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 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 specifiedSplitTotalRounder.SplitAmount.getOriginalTotal().- Parameters:
splitAmounts- the amount which was leftover after splitting part offoriginalTotal- the totals which the amounts from each ofsplitsshould 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 specifiedSplitTotalRounder.SplitAmount.getOriginalTotal().- Parameters:
splitAmounts- the amount which was leftover after splitting part offoriginalTotal- the totals which the amounts from each ofsplitsshould sum toscale- 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 roundgetter- the getter for theMonetaryAmountfield to roundsetter- the setter for theMonetaryAmountfield to roundoriginalTotal- 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 roundgetter- the getter for theMonetaryAmountfield to roundsetter- the setter for theMonetaryAmountfield to roundoriginalTotal- the original totalscale- 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 splitgetters- functions to get the amounts which were splitsetters- functions to set the newly rounded amounts which were splitsplitTargetTotals- the totals which the amounts from each ofsplitsshould sum tocurrency- 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 splitgetters- functions to get the amounts which were splitsetters- functions to set the newly rounded amounts which were splitsplitTargetTotals- the totals which the amounts from each ofsplitsshould sum tooriginalFulfillment- 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 splitgetters- functions to get the amounts which were splitsetters- functions to set the newly rounded amounts which were splitsplitTargetTotals- the totals which the amounts from each ofsplitsshould sum tooriginalFulfillment- the original fulfillment which was split, if presentcurrency- 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 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 ordersplitTargetTotals- The split target totals, in ordercurrency- 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 elementsgetter- function to get the amount which was splitsetter- function to set the newly rounded amount which was splitsplitTargetTotals- the totals which the amounts from each element ofsplitsshould sum tocurrency- 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 elementsgetter- function to get the amount which was splitsetter- function to set the newly rounded amount which was splitsplitTargetTotals- the totals which the amounts from each element ofsplitsshould sum tooriginalFulfillment- 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 elementsgetter- function to get the amount which was splitsetter- function to set the newly rounded amount which was splitsplitTargetTotals- the totals which the amounts from each element ofsplitsshould sum tooriginalFulfillment- the original fulfillment which was split, if presentcurrency- 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 theCurrencyUnit.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 theCurrencyUnitand 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 forscale- 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
-