Enum Class MeasurementSystem
- All Implemented Interfaces:
Serializable
,Comparable<MeasurementSystem>
,Constable
-
Nested Class Summary
Nested classes/interfaces inherited from class java.lang.Enum
Enum.EnumDesc<E extends Enum<E>>
-
Enum Constant Summary
Enum Constants -
Method Summary
Modifier and TypeMethodDescriptiondouble
convertLength
(double length, MeasurementSystem toUnit, boolean exact) Converts the given length value from the current unit to the target unit.Retrieves a user-friendly display string for the measurement unit.double
convertWeight
(double weight, MeasurementSystem toUnit, boolean exact) Converts the given weight value from the current unit to the target unit.static MeasurementSystem
fromDisplayString
(String displayString) Finds a MeasurementUnit by its display string.Retrieves the length unit symbol for this measurement unit.Retrieves the weight unit symbol for this measurement unit.static MeasurementSystem
Returns the enum constant of this class with the specified name.static MeasurementSystem[]
values()
Returns an array containing the constants of this enum class, in the order they are declared.
-
Enum Constant Details
-
METRIC
Metric system with units in millimeters and grams -
IMPERIAL
Imperial system with units in inches and pounds
-
-
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
-
getLengthUnitSymbol
Retrieves the length unit symbol for this measurement unit.- Returns:
- the length unit symbol
-
getWeightUnitSymbol
Retrieves the weight unit symbol for this measurement unit.- Returns:
- the weight unit symbol
-
convertToDisplayString
Retrieves a user-friendly display string for the measurement unit.- Returns:
- the display string
-
fromDisplayString
Finds a MeasurementUnit by its display string.- Parameters:
displayString
- the display string to search for- Returns:
- the corresponding MeasurementUnit
- Throws:
IllegalArgumentException
- if no match is found
-
convertLength
Converts the given length value from the current unit to the target unit.- Parameters:
length
- the length value to converttoUnit
- the target measurement unitexact
- whether to round the result to two decimal places- Returns:
- the converted length value
-
convertWeight
Converts the given weight value from the current unit to the target unit.- Parameters:
weight
- the weight value to converttoUnit
- the target measurement unitexact
- whether to return the exact conversion or round to two decimal places- Returns:
- the converted weight value
-