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
ConstructorsConstructorDescriptionDefaultWeightCalculationService(MathContext shippingWeightMathContext, com.fasterxml.jackson.databind.ObjectMapper mapper, MeasurementProperties measurementProperties) -
Method Summary
Modifier and TypeMethodDescriptionprotected voidaddUnitLabels(Map<String, List<String>> unitAliases) Reads unit aliases from properties and registers them with theSimpleUnitFormatsingleton instance.protected voidintcompare(com.broadleafcommerce.shipping.domain.Weight weight1, com.broadleafcommerce.shipping.domain.Weight weight2) Convert given weights toMassand compare.protected tech.units.indriya.ComparableQuantity<?>convertToComparableQuantity(com.broadleafcommerce.shipping.domain.Weight weight) Convert a BroadlefWeightinto an IndriyaComparableQuantity.protected List<com.broadleafcommerce.shipping.domain.Weight>getAllItemWeights(com.broadleafcommerce.order.client.domain.OrderFulfillment orderFulfillment) Returns a list with aWeightfor each item in the givenOrderFulfillment.protected List<com.broadleafcommerce.shipping.domain.Weight>getAllItemWeights(com.broadleafcommerce.shipping.domain.FulfillmentPricingRequest fulfillmentPricingRequest) Returns a list with aWeightfor each item in the givenFulfillmentPricingRequest.protected com.fasterxml.jackson.databind.ObjectMapperprotected MeasurementPropertiesprotected MathContextcom.broadleafcommerce.shipping.domain.WeightgetTotalPackageWeight(com.broadleafcommerce.order.client.domain.OrderFulfillment orderFulfillment) Calculate the total combined weight of anOrderFulfillment.com.broadleafcommerce.shipping.domain.WeightgetTotalPackageWeight(com.broadleafcommerce.shipping.domain.FulfillmentPricingRequest fulfillmentPricingRequest) Calculate the total combined weight of aFulfillmentPricingRequest.protected com.broadleafcommerce.shipping.domain.WeightsumWeights(List<com.broadleafcommerce.shipping.domain.Weight> itemWeights) Sum the given list ofWeights.
-
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 toMassand compare.- Specified by:
comparein 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:WeightCalculationServiceCalculate the total combined weight of aFulfillmentPricingRequest.- Specified by:
getTotalPackageWeightin interfaceWeightCalculationService- Parameters:
fulfillmentPricingRequest- The fulfillment being shipped.- Returns:
- A
Weightrepresenting 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:WeightCalculationServiceCalculate the total combined weight of anOrderFulfillment.- Specified by:
getTotalPackageWeightin interfaceWeightCalculationService- Parameters:
orderFulfillment- The fulfillment being shipped.- Returns:
- A
Weightrepresenting 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 aWeightfor 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
Listwith aWeightfor 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 aWeightfor 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
Listwith aWeightfor 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 ofWeights. Weights can be in different units.- Parameters:
itemWeights- The list to sum.- Returns:
- A
Weightrepresenting the sum of all Weights in the given List.
-
convertToComparableQuantity
protected tech.units.indriya.ComparableQuantity<?> convertToComparableQuantity(com.broadleafcommerce.shipping.domain.Weight weight) Convert a BroadlefWeightinto an IndriyaComparableQuantity.- Parameters:
weight- TheWeightto convert.- Returns:
- The equivalent
ComparableQuantity.
-
addUnitLabels
Reads unit aliases from properties and registers them with theSimpleUnitFormatsingleton instance.- Parameters:
unitAliases- Map of Unit class to aliases.
-
getShippingWeightMathContext
-
getMapper
protected com.fasterxml.jackson.databind.ObjectMapper getMapper() -
getMeasurementProperties
-