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