Class DefaultWeightCalculationService
java.lang.Object
com.broadleafcommerce.shipping.service.DefaultWeightCalculationService
- All Implemented Interfaces:
WeightCalculationService
Utilizes the Indriya project
(Github) to support weight
calculations with different units of measurement.
-
Constructor Summary
ConstructorDescriptionDefaultWeightCalculationService
(MathContext shippingWeightMathContext, com.fasterxml.jackson.databind.ObjectMapper mapper, MeasurementProperties measurementProperties) -
Method Summary
Modifier and TypeMethodDescriptionprotected void
addUnitLabels
(Map<String, List<String>> unitAliases) Reads unit aliases from properties and registers them with theSimpleUnitFormat
singleton instance.protected void
int
compare
(com.broadleafcommerce.shipping.domain.Weight weight1, com.broadleafcommerce.shipping.domain.Weight weight2) Convert given weights toMass
and compare.protected tech.units.indriya.ComparableQuantity<?>
convertToComparableQuantity
(com.broadleafcommerce.shipping.domain.Weight weight) Convert a BroadlefWeight
into an IndriyaComparableQuantity
.protected List<com.broadleafcommerce.shipping.domain.Weight>
getAllItemWeights
(com.broadleafcommerce.order.client.domain.OrderFulfillment orderFulfillment) Returns a list with aWeight
for each item in the givenOrderFulfillment
.protected List<com.broadleafcommerce.shipping.domain.Weight>
getAllItemWeights
(com.broadleafcommerce.shipping.domain.FulfillmentPricingRequest fulfillmentPricingRequest) Returns a list with aWeight
for each item in the givenFulfillmentPricingRequest
.protected com.fasterxml.jackson.databind.ObjectMapper
protected MeasurementProperties
protected MathContext
com.broadleafcommerce.shipping.domain.Weight
getTotalPackageWeight
(com.broadleafcommerce.order.client.domain.OrderFulfillment orderFulfillment) Calculate the total combined weight of anOrderFulfillment
.com.broadleafcommerce.shipping.domain.Weight
getTotalPackageWeight
(com.broadleafcommerce.shipping.domain.FulfillmentPricingRequest fulfillmentPricingRequest) Calculate the total combined weight of aFulfillmentPricingRequest
.protected com.broadleafcommerce.shipping.domain.Weight
sumWeights
(List<com.broadleafcommerce.shipping.domain.Weight> itemWeights) Sum the given list ofWeight
s.
-
Constructor Details
-
DefaultWeightCalculationService
public DefaultWeightCalculationService(MathContext shippingWeightMathContext, com.fasterxml.jackson.databind.ObjectMapper mapper, MeasurementProperties measurementProperties)
-
-
Method Details
-
alternativeWeightUnitSetup
@PostConstruct protected void alternativeWeightUnitSetup() -
compare
public int compare(com.broadleafcommerce.shipping.domain.Weight weight1, com.broadleafcommerce.shipping.domain.Weight weight2) Convert given weights toMass
and compare.- Specified by:
compare
in interfaceWeightCalculationService
- Parameters:
weight1
- The reference weight.weight2
- The weight to compare against the reference weight.- Returns:
- -1, 0, or 1, according to whether weight1 is less than, equal to, or greater than weight2.
- See Also:
-
getTotalPackageWeight
public com.broadleafcommerce.shipping.domain.Weight getTotalPackageWeight(com.broadleafcommerce.shipping.domain.FulfillmentPricingRequest fulfillmentPricingRequest) Description copied from interface:WeightCalculationService
Calculate the total combined weight of aFulfillmentPricingRequest
.- Specified by:
getTotalPackageWeight
in interfaceWeightCalculationService
- Parameters:
fulfillmentPricingRequest
- The fulfillment being shipped.- Returns:
- A
Weight
representing the total weight of all items in the fulfillment.
-
getTotalPackageWeight
public com.broadleafcommerce.shipping.domain.Weight getTotalPackageWeight(com.broadleafcommerce.order.client.domain.OrderFulfillment orderFulfillment) Description copied from interface:WeightCalculationService
Calculate the total combined weight of anOrderFulfillment
.- Specified by:
getTotalPackageWeight
in interfaceWeightCalculationService
- Parameters:
orderFulfillment
- The fulfillment being shipped.- Returns:
- A
Weight
representing the total weight of all items in the fulfillment.
-
getAllItemWeights
protected List<com.broadleafcommerce.shipping.domain.Weight> getAllItemWeights(com.broadleafcommerce.shipping.domain.FulfillmentPricingRequest fulfillmentPricingRequest) Returns a list with aWeight
for each item in the givenFulfillmentPricingRequest
. Weight objects will not be created for items that do not have a weight value or weight unit.- Parameters:
fulfillmentPricingRequest
- The fulfillment being shipped.- Returns:
- A
List
with aWeight
for each item in the given request.
-
getAllItemWeights
protected List<com.broadleafcommerce.shipping.domain.Weight> getAllItemWeights(com.broadleafcommerce.order.client.domain.OrderFulfillment orderFulfillment) Returns a list with aWeight
for each item in the givenOrderFulfillment
. Weight objects will not be created for items that do not have a weight value or weight unit.- Parameters:
orderFulfillment
- The fulfillment being shipped.- Returns:
- A
List
with aWeight
for each item in the given request.
-
sumWeights
protected com.broadleafcommerce.shipping.domain.Weight sumWeights(List<com.broadleafcommerce.shipping.domain.Weight> itemWeights) Sum the given list ofWeight
s. Weights can be in different units.- Parameters:
itemWeights
- The list to sum.- Returns:
- A
Weight
representing the sum of all Weights in the given List.
-
convertToComparableQuantity
protected tech.units.indriya.ComparableQuantity<?> convertToComparableQuantity(com.broadleafcommerce.shipping.domain.Weight weight) Convert a BroadlefWeight
into an IndriyaComparableQuantity
.- Parameters:
weight
- TheWeight
to convert.- Returns:
- The equivalent
ComparableQuantity
.
-
addUnitLabels
Reads unit aliases from properties and registers them with theSimpleUnitFormat
singleton instance.- Parameters:
unitAliases
- Map of Unit class to aliases.
-
getShippingWeightMathContext
-
getMapper
protected com.fasterxml.jackson.databind.ObjectMapper getMapper() -
getMeasurementProperties
-