}
}
+ public static Boolean askBoolean(String prompt, Boolean defaultValue) {
+ return askBoolean(prompt, defaultValue, false);
+ }
+
+ public static Boolean askBoolean(String prompt) {
+ return askBoolean(prompt, null, false);
+ }
+
/**
* Asks the user for a float value using the specified prompt on the command line.
* The user is prompted until a valid float (within optional ranges) is provided.
}
}
+ public static Float askFloat(String prompt, Float defaultValue) {
+ return askFloat(prompt, defaultValue, null, null, false);
+ }
+
+ public static Float askFloat(String prompt) {
+ return askFloat(prompt, null, null, null, false);
+ }
+
/**
* Asks the user for a long value using the specified prompt on the command line.
* The user is prompted until a valid long (within optional ranges) is provided.
}
}
+ public static Long askLong(String prompt, Long defaultValue) {
+ return askLong(prompt, defaultValue, null, null, false);
+ }
+
+ public static Long askLong(String prompt) {
+ return askLong(prompt, null, null, null, false);
+ }
+
+
/**
* Asks the user for an integer value using the specified prompt on the command line.
* The user is prompted until a valid integer (within optional ranges) is provided.
}
}
+ public static Integer askInteger (String prompt, Integer defaultValue) {
+ return askInteger(prompt, defaultValue, null, null, false);
+ }
+
+ public static Integer askInteger (String prompt) {
+ return askInteger(prompt, null, null, null, false);
+ }
/**
* Asks the user for a string value using the specified prompt on the command line.
* If the user presses ENTER without typing anything and {@code defaultValue} is non-null,
* @param defaultValue the value to return if the user provides no input
* @return the value typed by the user, or {@code defaultValue} if empty input
*/
- public static String askString(String prompt, String defaultValue, boolean allowEmpty) {
+ public static String askString(String prompt, String defaultValue, Integer minLength, Integer maxLength, boolean allowEmpty) {
while (true) {
// If we have a defaultValue, display it in brackets; otherwise display no default
String displayPrompt = prompt
}
}
+ if (minLength != null && input.length() < minLength) {
+ System.out.println("Input must be at least " + minLength + " characters long.");
+ continue;
+ }
+
+ if (maxLength != null && input.length() > maxLength) {
+ System.out.println("Input must be at most " + maxLength + " characters long.");
+ continue;
+ }
+
return input;
}
+ }
+ public static String askString(String prompt, String defaultValue) {
+ return askString(prompt, defaultValue, null, null, false);
}
+
+ public static String askString(String prompt) {
+ return askString(prompt, null, null, null, false);
+ }
+
}