Unit

open class Unit<U : Unit<U>>(baseUnit: U?, toBaseConverter: UnaryFunction, fromBaseConverter: UnaryFunction, name: String, symbol: String)

Unit of measurement that defines a quantity, such as grams, meters, or seconds.

This is the base class for units. Actual units (such as Units.Grams and ) can be found in the Units class.

Since

1.0.0-pre

Parameters

the self type, e.g. `class SomeUnit extends Unit`

Inheritors

Constructors

Link copied to clipboard
protected constructor(baseUnit: U?, baseUnitEquivalent: Double, name: String, symbol: String)

Creates a new unit with the given name and multiplier to the base unit.

constructor(baseUnit: U?, toBaseConverter: UnaryFunction, fromBaseConverter: UnaryFunction, name: String, symbol: String)

Types

Link copied to clipboard
object Companion

Properties

Link copied to clipboard

Gets the base unit of measurement that this unit is derived from. If the unit is the base unit, the unit will be returned.

Link copied to clipboard

Gets the conversion function used to convert values to terms of this unit. This generally shouldn't need to be used directly; prefer fromBaseUnits instead.

Link copied to clipboard

Gets the conversion function used to convert values to base unit terms. This generally shouldn't need to be used directly; prefer toBaseUnits instead.

Functions

Link copied to clipboard
fun convertFrom(magnitude: Double, otherUnit: Unit<U>): Double

Converts a magnitude in terms of another unit of the same dimension to a magnitude in terms of this unit.

Link copied to clipboard
open operator override fun equals(other: Any?): Boolean
Link copied to clipboard
infix fun equivalent(other: Unit<*>): Boolean

Checks if this unit is equivalent to another one. Equivalence is determined by both units having the same base type and treat the same base unit magnitude as the same magnitude in their own units, to within Measure.EQUIVALENCE_THRESHOLD.

Link copied to clipboard
fun fromBaseUnits(valueInBaseUnits: Double): Double

Converts a value in terms of base units to a value in terms of this unit.

Link copied to clipboard
open override fun hashCode(): Int
Link copied to clipboard

Checks if this unit is the base unit for its own system of measurement.

Link copied to clipboard
infix fun <U2 : Unit<U2>> mult(other: U2): Mult<U, U2>

Takes this unit and creates a new combinatory unit equivalent to this unit multiplied by another.

Link copied to clipboard
fun name(): String

Gets the name of this unit.

Link copied to clipboard
infix fun of(magnitude: Double): Measure<U>

Creates a new measure of this unit with the given value. The resulting measure is immutable and cannot have its value modified.

Link copied to clipboard
infix fun ofBaseUnits(baseUnitMagnitude: Double): Measure<U>

Creates a new measure with a magnitude equal to the given base unit magnitude, converted to be in terms of this unit.

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

Gets a measure with a magnitude of 1 in terms of this unit.

Link copied to clipboard
infix fun <D : Unit<D>> per(denominator: D): Per<U, D>

Takes this unit and creates a new proportional unit where this unit is the numerator and the given denominator is the denominator.

infix fun per(period: Time): Velocity<U>

Creates a velocity unit derived from this one. Can be chained to denote velocity, acceleration, jerk, etc.

Link copied to clipboard
fun symbol(): String

Gets the symbol of this unit.

Link copied to clipboard
fun toBaseUnits(valueInNativeUnits: Double): Double

Converts a value in terms of this unit to a value in terms of the base unit.

Link copied to clipboard
open override fun toString(): String
Link copied to clipboard
fun zero(): Measure<U>

Gets a measure with a magnitude of 0 in terms of this unit.

Inherited functions

Link copied to clipboard
infix fun <U : Unit<U>> Unit<U>.from(conversion: Pair<Double, Unit<U>>): Double

Converts a magnitude in terms of this unit to a magnitude in terms of another unit of the same dimension.