operator - method
Implementation
ValidatedQuantity? operator -(Object other) {
if (other is UcumDecimal) {
return copyWith(value: value.subtract(other));
} else if (other is ValidatedQuantity) {
if (UcumService().isComparable(unit, other.unit)) {
final UcumDecimal convertedValue =
UcumService().convert(other.value, other.unit, unit);
return copyWith(value: value.subtract(convertedValue));
} else {
return null;
}
} else if (other is num || other is BigInt) {
return copyWith(
value: value.subtract(UcumDecimal.fromString(other.toString())));
} else if (other is String) {
final ValidatedQuantity newQuantity = ValidatedQuantity.fromString(other);
if (newQuantity.isValid()) {
if (UcumService().isComparable(unit, newQuantity.unit)) {
final UcumDecimal convertedValue =
UcumService().convert(newQuantity.value, newQuantity.unit, unit);
return copyWith(value: value.subtract(convertedValue));
} else {
return null;
}
} else {
throw UcumException('$other could not be subtracted from $this '
'(reason: it is not an accepted type)');
}
} else {
throw UcumException('$other could not be subtracted from $this '
'(reason: it is not an accepted type)');
}
}