Enum Class MeasurementSystem

All Implemented Interfaces:
Serializable, Comparable<MeasurementSystem>, Constable

public enum MeasurementSystem extends Enum<MeasurementSystem>
The MeasurementSystem enum represents different systems of measurement and provides methods to convert between them.

The following systems are available:

  • METRIC - Metric system with units in millimeters and grams
  • IMPERIAL - Imperial system with units in inches and pounds
  • Enum Constant Details

    • METRIC

      public static final MeasurementSystem METRIC
      Metric system with units in millimeters and grams
    • IMPERIAL

      public static final MeasurementSystem IMPERIAL
      Imperial system with units in inches and pounds
  • Method Details

    • values

      public static MeasurementSystem[] 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 MeasurementSystem 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
    • getLengthUnitSymbol

      public String getLengthUnitSymbol()
      Retrieves the length unit symbol for this measurement unit.
      Returns:
      the length unit symbol
    • getWeightUnitSymbol

      public String getWeightUnitSymbol()
      Retrieves the weight unit symbol for this measurement unit.
      Returns:
      the weight unit symbol
    • convertToDisplayString

      public String convertToDisplayString()
      Retrieves a user-friendly display string for the measurement unit.
      Returns:
      the display string
    • fromDisplayString

      public static MeasurementSystem fromDisplayString(String displayString)
      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

      public double convertLength(double length, MeasurementSystem toUnit, boolean exact)
      Converts the given length value from the current unit to the target unit.
      Parameters:
      length - the length value to convert
      toUnit - the target measurement unit
      exact - whether to round the result to two decimal places
      Returns:
      the converted length value
    • convertWeight

      public double convertWeight(double weight, MeasurementSystem toUnit, boolean exact)
      Converts the given weight value from the current unit to the target unit.
      Parameters:
      weight - the weight value to convert
      toUnit - the target measurement unit
      exact - whether to return the exact conversion or round to two decimal places
      Returns:
      the converted weight value