Class SplitRoundingHelper
- java.lang.Object
-
- com.broadleafcommerce.orderoperation.service.split.SplitRoundingHelper
-
public class SplitRoundingHelper extends Object
-
-
Constructor Summary
Constructors Constructor Description SplitRoundingHelper()
-
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 theCurrencyUnit
.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.
-
-
-
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 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 ofsplits
should 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 ofsplits
should 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 ofsplits
should 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 ofsplits
should 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 ofsplits
should 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 ofsplits
should 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
-
-