+ "Invalid syntax! Must be of the form <double-number><space><unit>!";
String[] parts = amountString.split(" ");
if (parts.length != 2) {
// first part is a double number, second is the physical unit, e.g. kg
throw new RulesetException(errMsg);
} else {
double amount;
try {
amount = Double.parseDouble(parts[0]);
} catch (NumberFormatException e) {
throw new RulesetException(errMsg);
}
PhysicalAmount.PhysicalUnit unit
= PhysicalAmount.PhysicalUnit.fromString(parts[1]);
if (unit == null) {
// could not identify unit
throw new RulesetException(errMsg);
}
return new PhysicalAmount(amount, unit);
}
}