compareTo method
Compares this quantity to another Quantity of the same type (T).
This method must be implemented by concrete subclasses.
The comparison is based on the physical magnitude of the quantities.
To achieve this, one quantity (or both) might need to be converted to a
common unit before their numerical values are compared. A common strategy
is to convert this.value to other.unit using getValue(other.unit)
and then compare the result with other.value.
Returns:
- A negative integer if this quantity is less than
other. - Zero if this quantity is equal in magnitude to
other. - A positive integer if this quantity is greater than
other.
This method is essential for sorting collections of Quantity objects.
Implementation
@override
int compareTo(Quantity<AngularVelocityUnit> other) {
final thisValueInOtherUnit = getValue(other.unit);
return thisValueInOtherUnit.compareTo(other.value);
}