UnitOfMeasurement<TUnit, TValue extends UnitOfMeasurement<TUnit, dynamic>> class abstract

Base class for units of measurement.

A unit of measurement is a value in the context of a specific measurement. That is, a quantity that is comparable to other quantities of the same kind. Moreover, a unit of measurement typically contains various "units" of size to make it practical to convey large ranges of values in a succinct and meaningful way.

This class serves as a base for concrete units of measurement. It encapsulates the majority of complexity required for specific units of measurement, particularly generalized formatting support.

The TValue type is the specific unit of measurement (i.e. the subclass extending this class). TUnit, on the other hand, is a type (typically an enumeration) that differentiates different units within the unit of measurement. For example, the Length unit of measurement uses LengthUnit, which includes LengthUnit.meter, LengthUnit.inch, and many more.

Implemented types
Implementers
Annotations
  • @immutable

Constructors

UnitOfMeasurement.fromUnits(TUnit unit, Rational value)
Creates a unit of measurement value with the specified unit and value.

Properties

baseValue ↔ Rational
The underlying base value of the unit of measurement.
latefinal
hashCode int
The hash code for this object.
no setteroverride
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

abs() → TValue
Gets the absolute value.
compareTo(TValue other) int
Compares this object to another object.
override
createValue(Rational baseValue) → TValue
Creates a unit of measurement value with the specified baseValue.
getBaseValue(TUnit unit, Rational value) → Rational
Gets the base value for a unit of measurement of unit and value.
getLargestUnit({required Set<TUnit> permissibleUnits}) → TUnit
Determines the largest unit that has a value of at least 1.
getUnits(TUnit unit) → Rational
Gets the number of unit units in this unit of measurement.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
round(TUnit roundTo) → TValue
Rounds this unit of measurement such that the roundTo unit will be rounded towards the nearest integer.
toString() String
A string representation of this object.
inherited

Operators

operator *(Rational factor) → TValue
Multiplies this value by factor.
operator +(TValue other) → TValue
Adds other onto this value.
operator -(TValue other) → TValue
Subtracts other from this value.
operator /(Rational divisor) → TValue
Divides this value by divisor.
operator <(TValue other) bool
Determines whether this value is less than other.
operator <=(TValue other) bool
Determines whether this value is less than or equal to other.
operator ==(Object other) bool
Determines whether this unit of measurement value is equal to other.
override
operator >(TValue other) bool
Determines whether this value is greater than other.
operator >=(TValue other) bool
Determines whether this value is greater than or equal to other.
operator unary-() → TValue
Negates this value.