Measurement

data class Measurement<out UnitType : Dimension>(val value: Double, val unit: UnitType) : Comparable<Measurement<UnitType>>

A Measurement holds a value in a specific unit.

Parameters

UnitType

The type of unit (e.g., UnitTemperature, UnitSpeed).

value

The numerical value of the measurement.

unit

The unit of the measurement.

Constructors

Link copied to clipboard
constructor(value: Double, unit: UnitType)

Types

Link copied to clipboard
object Companion

Properties

Link copied to clipboard
Link copied to clipboard

Functions

Link copied to clipboard
open operator override fun compareTo(other: Measurement<@UnsafeVariance UnitType>): Int

Compares this measurement to another measurement, enabling sorting and range operations. The other parameter uses in variance. This allows a Measurement to be compared with a Measurement, which is required for the Comparable contract.

Link copied to clipboard

Converts this measurement to a different unit of the same dimension. The to parameter is marked with @UnsafeVariance because it's in an "in" position, but we know our usage is safe as we only read from it for conversion.