if (nextOrdinal == maxOrdinal) {
// we could theoretically get bigger, but we don't have any units to represent that
break;
}
MeasurementUnits biggerUnits = MeasurementUnits.values()[nextOrdinal];
if (biggerUnits.getFamily() != currentValueAndUnits.getUnits().getFamily()) {
// we're as big as we can get, break out of the loop so we can return
break;
}
Double smallerValue = scale(currentValueAndUnits, biggerUnits);
nextValueAndUnits = new MeasurementNumericValueAndUnits(smallerValue, biggerUnits);
} while (nextValueAndUnits.getValue() > 1.0);
// next, make the value bigger if it's too small
int minOrdinal = (lowUnits != null) ? (lowUnits.ordinal() - 1) : -1;
while (currentValueAndUnits.getValue() < 1.0) {
int nextOrdinal = currentValueAndUnits.getUnits().ordinal() - 1;
if (nextOrdinal == minOrdinal) {
// we could theoretically get smaller, but we don't have any units to represent that
break;
}
MeasurementUnits smallerUnits = MeasurementUnits.values()[nextOrdinal];
if (smallerUnits.getFamily() != currentValueAndUnits.getUnits().getFamily()) {
// we're as small as we can get, break out of the loop so we can return
break;
}
Double biggerValue = scale(currentValueAndUnits, smallerUnits);