operator - method

ValidatedQuantity? operator -(
  1. Object other
)

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)) {
      return copyWith(value: value.subtract(other.value));
    } 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()) {
      return copyWith(value: value.subtract(newQuantity.value));
    } 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)');
  }
}