You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

31 lines
789 B
Java

package com.example.pdaplccontrol;
final class WeightInputParser {
private WeightInputParser() {
}
static short parseKg(String input) {
if (input == null || input.trim().isEmpty()) {
throw new IllegalArgumentException("请输入重量");
}
int kg;
try {
kg = Integer.parseInt(input.trim());
} catch (NumberFormatException e) {
throw new IllegalArgumentException("重量必须为整数kg");
}
if (kg < PlcConfig.MIN_WEIGHT_KG || kg > PlcConfig.MAX_WEIGHT_KG) {
throw new IllegalArgumentException("重量范围为 0-30kg");
}
return (short) kg;
}
static String kgToDisplayText(short weightKg) {
return String.valueOf(weightKg);
}
}