compare method

bool compare(
  1. _Comparator comparator,
  2. Object o
)

Implementation

bool compare(_Comparator comparator, Object o) {
  if (identical(this, o)) {
    return true;
  } else if (o is! FhirPathQuantity) {
    return false;
  } else {
    final fromUnit = stringUnitToProperty[unit];
    final toUnit = stringUnitToProperty[o.unit];
    if ((fromUnit is Ratio && toUnit is! Ratio) ||
        (fromUnit is! Ratio && toUnit is Ratio)) {
      return false;
    } else if (fromUnit is Ratio) {
      if (toUnit is! Ratio) {
        return false;
      } else {
        final convertedAmount = amount.convertRatioFromTo(fromUnit, toUnit);

        if (convertedAmount != null) {
          switch (comparator) {
            case _Comparator.gt:
              return convertedAmount > o.amount;
            case _Comparator.gte:
              return convertedAmount >= o.amount;
            case _Comparator.lt:
              return convertedAmount < o.amount;
            case _Comparator.lte:
              return convertedAmount <= o.amount;
          }
        } else {
          return false;
        }
      }
    } else {
      final convertedAmount = amount.convertFromTo(fromUnit, toUnit);
      if (convertedAmount != null) {
        switch (comparator) {
          case _Comparator.gt:
            return convertedAmount > o.amount;
          case _Comparator.gte:
            return convertedAmount >= o.amount;
          case _Comparator.lt:
            return convertedAmount < o.amount;
          case _Comparator.lte:
            return convertedAmount <= o.amount;
        }
      } else {
        return false;
      }
    }
  }
}