Enum Class WeightUnitOfMeasure

java.lang.Object
java.lang.Enum<WeightUnitOfMeasure>
com.broadleafcommerce.fulfillment.domain.WeightUnitOfMeasure
All Implemented Interfaces:
Serializable, Comparable<WeightUnitOfMeasure>, Constable

public enum WeightUnitOfMeasure extends Enum<WeightUnitOfMeasure>
Enum to represent common units of weight, especially for packaging and fulfillment (shipping). Includes methods to facilitate conversion between units. Each enum includes an array of "aliases", alternate names for the unit, such as "kg" or "kilograms" for KILOGRAM.
Author:
Kelly Tisdell (ktisdell), Cade Rea (cade-rea)
  • Enum Constant Details

  • Method Details

    • values

      public static WeightUnitOfMeasure[] values()
      Returns an array containing the constants of this enum class, in the order they are declared.
      Returns:
      an array containing the constants of this enum class, in the order they are declared
    • valueOf

      public static WeightUnitOfMeasure valueOf(String name)
      Returns the enum constant of this class with the specified name. The string must match exactly an identifier used to declare an enum constant in this class. (Extraneous whitespace characters are not permitted.)
      Parameters:
      name - the name of the enum constant to be returned.
      Returns:
      the enum constant with the specified name
      Throws:
      IllegalArgumentException - if this enum class has no constant with the specified name
      NullPointerException - if the argument is null
    • from

      public BigDecimal from(com.broadleafcommerce.fulfillment.common.domain.Weight weight)
      Convert the value from the given Weight to this unit.
      Parameters:
      weight - The Weight to convert.
      Returns:
      The value of the given Weight in this unit.
    • from

      public BigDecimal from(BigDecimal value, String unit)
      Convert a value in the given unit to this unit. The unit parameter is not case-sensitive and will be checked against the values of WeightUnitOfMeasure and their aliases.
      Parameters:
      value - The value to convert.
      unit - The unit that the value is currently in. Should correspond to a value or alias in WeightUnitOfMeasure.
      Returns:
      The given value converted to this unit.
    • from

      public BigDecimal from(BigDecimal value, WeightUnitOfMeasure unit)
      Convert a value in the given unit to this unit.
      Parameters:
      value - The value to convert.
      unit - The WeightUnitOfMeasure the value is currently in.
      Returns:
      The given value converted to this unit.
    • valueOfAliasIgnoreCase

      public static WeightUnitOfMeasure valueOfAliasIgnoreCase(String unit)
      Like valueOf(), but also checks aliases. For example, "KILOGRAM", "kilograms", and "kg" will all return KILOGRAM.
      Parameters:
      unit -
      Returns:
    • getToGramsFactor

      public BigDecimal getToGramsFactor()
      The factor to apply to a value in this WeightUnitOfMeasure to convert the value to grams.
    • getAliases

      public String[] getAliases()
      Different names for this unit. For example, abbreviations like "kg" or pluralizations like "pounds". Not case-sensitive.