*/
public static boolean askBoolean(final String prompt, final Boolean defaultValue) {
while (true) {
- // Show the user something like "Continue? [Y/n]: " or "Continue? [y/N]: "
String finalPrompt = prompt;
if (defaultValue != null){
+ // Show the user something like "Continue? [Y/n]: " or "Continue? [y/N]: "
finalPrompt = prompt + " [" + (defaultValue ? "Y/n" : "y/N") + "]: ";
}
String line = askString(finalPrompt);
- // If user provided an empty line, askString() returns null in this usage => default
- if (line == null && defaultValue != null) {
+ if ((defaultValue != null) && (line == null)) {
return defaultValue;
}
String input = scanner.nextLine().trim();
// Return the default if user just pressed ENTER
- return input.isEmpty() && defaultValue != null ? defaultValue : input;
+ return input.isEmpty() ? defaultValue : input;
}
/**