rcv
rcv copied to clipboard
Fun with stringifying booleans
Tried switching over some booleans to Strings, but hit a wall with excluded because of the way it interacts in the GUI. Also realized that the configs will load fine as it stands with either true or "true" in the config file, so there's really no need to handle this now (or maybe even at all). Filing a separate issue just in case.
Here's what I had going:
private boolean isBoolean(String s) {
return !isNullOrBlank(s) && (s.equalsIgnoreCase("true") || s.equalsIgnoreCase("false"));
}
// Makes sure String input can be converted to a boolean
private void checkStringToBoolean(String input, String inputName) {
checkStringToBoolean(input, inputName, null);
}
// Makes sure String input can be converted to a boolean
private void checkStringToBoolean(String input, String inputName, String inputLocation) {
if (!isBoolean(input)) {
invalidateAndLog(String.format("%s must be \"true\" or \"false\"", inputName), inputLocation);
}
}
Then add these checks for all booleans in validation (and call isBoolean whenever a boolean is accessed in validation for other purposes).
It's also possible to set a tertiary state on the checkboxes to potentially load booleans into if they have an unrecognized value (though clear method would need to also setIndeterminate(false)):
if (!outputSettings.generateCdfJson.equals("false") && !outputSettings.generateCdfJson.equals("true")) {
checkBoxGenerateCdfJson.setIndeterminate(true);
} else {
checkBoxGenerateCdfJson.setSelected(Boolean.parseBoolean(outputSettings.generateCdfJson));
}
Can maybe get rid of this comment once / if we do this?
// If any booleans are unspecified in config file, they should default to false no matter what