compareTo method
Compares this Length object to another Quantity<LengthUnit>.
Comparison is based on the physical magnitude of the lengths.
For comparison, this length is converted to the unit of the other length.
Returns:
- A negative integer if this length is less than
other. - Zero if this length is equal to
other. - A positive integer if this length is greater than
other.
Implementation
@override
int compareTo(Quantity<LengthUnit> other) {
// Convert this quantity's value to the unit of the 'other' quantity
// for a direct numerical comparison.
final thisValueInOtherUnit = getValue(other.unit);
return thisValueInOtherUnit.compareTo(other.value);
}