compareTo method

  1. @override
int compareTo(
  1. Temperature other
)
override

Compare this Temperature to other in the same measurment.

If this measurment is higher than other, it return positive int and vice versa. It return 0 when this and other are the same measurment value.

Implementation

@override
int compareTo(Temperature other) {
  Temperature sameUnit = _toSameUnit(other);

  double diff = value - sameUnit.value;

  if (diff > 0) {
    return 1;
  } else if (diff < 0) {
    return -1;
  }

  return 0;
}