Class DefaultWeightCalculationService

java.lang.Object
com.broadleafcommerce.shipping.service.DefaultWeightCalculationService
All Implemented Interfaces:
WeightCalculationService

public class DefaultWeightCalculationService extends Object implements WeightCalculationService
Utilizes the Indriya project (Github) to support weight calculations with different units of measurement.
  • Constructor Summary

    Constructors
    Constructor
    Description
    DefaultWeightCalculationService(MathContext shippingWeightMathContext, com.fasterxml.jackson.databind.ObjectMapper mapper, MeasurementProperties measurementProperties)
     
  • Method Summary

    Modifier and Type
    Method
    Description
    protected void
    Reads unit aliases from properties and registers them with the SimpleUnitFormat singleton instance.
    protected void
     
    int
    compare(com.broadleafcommerce.shipping.domain.Weight weight1, com.broadleafcommerce.shipping.domain.Weight weight2)
    Convert given weights to Mass and compare.
    protected tech.units.indriya.ComparableQuantity<?>
    convertToComparableQuantity(com.broadleafcommerce.shipping.domain.Weight weight)
    Convert a Broadlef Weight into an Indriya ComparableQuantity.
    protected List<com.broadleafcommerce.shipping.domain.Weight>
    getAllItemWeights(com.broadleafcommerce.order.client.domain.OrderFulfillment orderFulfillment)
    Returns a list with a Weight for each item in the given OrderFulfillment.
    protected List<com.broadleafcommerce.shipping.domain.Weight>
    getAllItemWeights(com.broadleafcommerce.shipping.domain.FulfillmentPricingRequest fulfillmentPricingRequest)
    Returns a list with a Weight for each item in the given FulfillmentPricingRequest.
    protected com.fasterxml.jackson.databind.ObjectMapper
     
     
    protected MathContext
     
    com.broadleafcommerce.shipping.domain.Weight
    getTotalPackageWeight(com.broadleafcommerce.order.client.domain.OrderFulfillment orderFulfillment)
    Calculate the total combined weight of an OrderFulfillment.
    com.broadleafcommerce.shipping.domain.Weight
    getTotalPackageWeight(com.broadleafcommerce.shipping.domain.FulfillmentPricingRequest fulfillmentPricingRequest)
    Calculate the total combined weight of a FulfillmentPricingRequest.
    protected com.broadleafcommerce.shipping.domain.Weight
    sumWeights(List<com.broadleafcommerce.shipping.domain.Weight> itemWeights)
    Sum the given list of Weights.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • 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 to Mass and compare.
      Specified by:
      compare in interface WeightCalculationService
      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 a FulfillmentPricingRequest.
      Specified by:
      getTotalPackageWeight in interface WeightCalculationService
      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 an OrderFulfillment.
      Specified by:
      getTotalPackageWeight in interface WeightCalculationService
      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 a Weight for each item in the given FulfillmentPricingRequest. 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 a Weight 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 a Weight for each item in the given OrderFulfillment. 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 a Weight 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 of Weights. 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 Broadlef Weight into an Indriya ComparableQuantity.
      Parameters:
      weight - The Weight to convert.
      Returns:
      The equivalent ComparableQuantity.
    • addUnitLabels

      protected void addUnitLabels(Map<String,List<String>> unitAliases)
      Reads unit aliases from properties and registers them with the SimpleUnitFormat singleton instance.
      Parameters:
      unitAliases - Map of Unit class to aliases.
    • getShippingWeightMathContext

      protected MathContext getShippingWeightMathContext()
    • getMapper

      protected com.fasterxml.jackson.databind.ObjectMapper getMapper()
    • getMeasurementProperties

      protected MeasurementProperties getMeasurementProperties()