Scala library to associate values to unit of measure type and scale. Quantity is intended to replace passing unitless/scaleless values through interfaces. Many times it is not obvious which unit/scale an interface requires. Using Quantity allows for interfaces to allow any unit/scale that the caller desires.
Note that this code is not attempting to implement any units of measure JSR.
- Angle
- Frequency
- Length
- Temperature
- Time
Example of creating a Length Quantity and conversion between units and scale.
val kmValue = 12.34
val kmUnit = METER
val kmScale = KILO
val kmQuantity = Quantity[LengthUnit](kmValue, kmUnit, kmScale)
val milliQuantity = kmQuantity.convertScaleTo(MILLI)
val footQuantity = kmQuantity.convertScaleTo(NONE).convertUnitTo(FOOT)
The quantities are converted to a common unit and scale when compared.
milliQuantity.compareTo(kmQuantity)
The quantities are converted to a common unit and scale when added. The sum will be returned in the unit/scale of the object instance that add method is called on.
val sum = milliQuantity.add(kmQuantity)
The quantities are converted to a common unit and scale when subtracted. The sum will be returned in the unit/scale of the object instance that subtract method is called on.
val diff = kmQuantity.sub(milliQuantity)
The quantities are converted to a common unit and scale when min/max are evaluated.
val microQuantity = Quantity[LengthUnit](456, METER, MICRO)
val min = microQuantity.min(kmQuantity)
val max = microQuantity.max(kmQuantity)