Measure

interface Measure<U : Unit<U>> : Comparable<Measure<U>> (source)

A measure holds the magnitude and unit of some dimension, such as distance, time, or speed. Two measures with the same unit and magnitude are effectively equivalent objects.

Type Parameters

U

the unit type of the measure

Inheritors

Types

Link copied to clipboard
object Companion

Properties

Link copied to clipboard

Absolute value of measure.

Link copied to clipboard
open val baseUnit: U

A convenience method to get the base unit of the measurement. Equivalent to unit.baseUnit.

Link copied to clipboard

Gets the magnitude of this measure in terms of the base unit. If the unit is the base unit for its system of measure, then the value will be equivalent to magnitude.

Link copied to clipboard
abstract val magnitude: Double

Gets the unitless magnitude of this measure.

Link copied to clipboard
open val sign: Double

Returns the sign of this measure.

Link copied to clipboard
abstract val unit: U

Gets the units of this measure.

Functions

Link copied to clipboard
open fun abs(unit: U): Double

Absolute value of measure.

Link copied to clipboard
open operator override fun compareTo(other: Measure<U>): Int
Link copied to clipboard
open fun div(other: Measure<out U>): Double

Divides this measure by another measure and returns the ratio as a dimensionless value.

open operator fun <V : Unit<V>> div(other: Measure<V>): Per<U, V>

Divides this measure by another measure of a different type to create a ratio unit. For example, Distance / Time creates a velocity measurement, or Voltage / Distance creates electric field strength.

abstract operator fun div(divisor: Double): Measure<U>
open operator fun div(divisor: Number): Measure<U>

Divides this measure by a scalar and returns the result.

Link copied to clipboard
open fun into(unit: U): Double

Converts this measure to a measure with a different unit of the same type, eg minutes to seconds. Converting to the same unit is equivalent to calling magnitude.

Link copied to clipboard
open fun isEquivalent(other: Measure<*>): Boolean

Checks if this measure is equivalent to another measure of the same unit.

Link copied to clipboard
open fun isNear(other: Measure<*>, varianceThreshold: Double): Boolean

Checks if this measure is near another measure of the same unit. Provide a variance threshold for use for a +/- scalar, such as 0.05 for +/- 5%.

open fun isNear(other: Measure<U>, tolerance: Measure<U>): Boolean

Checks if this measure is near another measure of the same unit, with a specified tolerance of the same unit.

Link copied to clipboard
abstract operator fun minus(other: Measure<out U>): Measure<U>

Subtracts another measure of the same unit type from this one.

Link copied to clipboard
open fun negate(): Measure<U>

Returns a measure equivalent to this one equal to zero minus its current value. For non-linear unit types like temperature, the zero point is treated as the zero value of the base unit (eg Kelvin). In effect, this means code like Celsius.of(10).negate() returns a value equivalent to -10 Kelvin, and not -10° Celsius.

Link copied to clipboard
abstract operator fun plus(other: Measure<out U>): Measure<U>

Adds another measure of the same unit type to this one.

Link copied to clipboard
open operator fun <V : Unit<V>> times(other: Measure<V>): Mul<U, V>

Multiplies this measure by another measure of a different type to create a compound unit. For example, Distance * Distance creates an area measurement, or Voltage * Time creates charge.

abstract operator fun times(multiplier: Double): Measure<U>
open operator fun times(multiplier: Number): Measure<U>

Multiplies this measure by a scalar unitless multiplier.

Link copied to clipboard
open fun toLongString(): String

Returns a string representation of this measurement in a longhand form. The name of the backing unit is used, rather than its symbol, and the magnitude is represented in a full string, not scientific notation. (Very large values may be represented in scientific notation, however)

Link copied to clipboard
open fun toShortString(): String

Returns a string representation of this measurement in a shorthand form. The symbol of the backing unit is used, rather than the full name, and the magnitude is represented in scientific notation.

Link copied to clipboard
abstract operator fun unaryMinus(): Measure<U>

Returns a measure equivalent to this one equal to zero minus its current value. For non-linear unit types like temperature, the zero point is treated as the zero value of the base unit (eg Kelvin). In effect, this means code like Celsius.of(10).unaryMinus() returns a value equivalent to -10 Kelvin, and not -10° Celsius.

Link copied to clipboard
open fun withSign(other: Measure<U>): Measure<U>

Take the sign of another measure. This measure's and the provided measure's signs are considered in this measure's unit.

open fun withSign(other: Measure<U>, unit: U): Double

Take the sign of another measure.