Enum Class WeightUnitOfMeasure
- All Implemented Interfaces:
Serializable
,Comparable<WeightUnitOfMeasure>
,Constable
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)
-
Nested Class Summary
Nested classes/interfaces inherited from class java.lang.Enum
Enum.EnumDesc<E extends Enum<E>>
-
Enum Constant Summary
-
Method Summary
Modifier and TypeMethodDescriptionfrom
(com.broadleafcommerce.fulfillment.common.domain.Weight weight) Convert the value from the givenWeight
to this unit.from
(BigDecimal value, WeightUnitOfMeasure unit) Convert a value in the given unit to this unit.from
(BigDecimal value, String unit) Convert a value in the given unit to this unit.String[]
Different names for this unit.The factor to apply to a value in this WeightUnitOfMeasure to convert the value to grams.static WeightUnitOfMeasure
Returns the enum constant of this class with the specified name.static WeightUnitOfMeasure
valueOfAliasIgnoreCase
(String unit) Like valueOf(), but also checks aliases.static WeightUnitOfMeasure[]
values()
Returns an array containing the constants of this enum class, in the order they are declared.
-
Enum Constant Details
-
GRAM
-
KILOGRAM
-
OUNCE
-
POUND
-
-
Method Details
-
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
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 nameNullPointerException
- if the argument is null
-
from
Convert the value from the givenWeight
to this unit.- Parameters:
weight
- TheWeight
to convert.- Returns:
- The value of the given
Weight
in this unit.
-
from
Convert a value in the given unit to this unit. The unit parameter is not case-sensitive and will be checked against the values ofWeightUnitOfMeasure
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 inWeightUnitOfMeasure
.- Returns:
- The given value converted to this unit.
-
from
Convert a value in the given unit to this unit.- Parameters:
value
- The value to convert.unit
- TheWeightUnitOfMeasure
the value is currently in.- Returns:
- The given value converted to this unit.
-
valueOfAliasIgnoreCase
Like valueOf(), but also checks aliases. For example, "KILOGRAM", "kilograms", and "kg" will all returnKILOGRAM
.- Parameters:
unit
-- Returns:
-
getToGramsFactor
The factor to apply to a value in this WeightUnitOfMeasure to convert the value to grams. -
getAliases
Different names for this unit. For example, abbreviations like "kg" or pluralizations like "pounds". Not case-sensitive.
-