public class DefaultPrompter extends Object implements IPrompter
| Modifier and Type | Field and Description |
|---|---|
private static String |
EMPTY_REPLACEMENT |
private BufferedReader |
reader |
private static Pattern |
REGEX_COMMA_SEPARATED_INTEGER_RANGES |
private static Pattern |
REGEX_NEXT_INTEGER_RANGE |
| Constructor and Description |
|---|
DefaultPrompter() |
| Modifier and Type | Method and Description |
|---|---|
void |
close() |
private static boolean |
isValidIntRangeInput(String text) |
private <T> T |
loopInput(T defaultValue,
boolean hasDefaultValue,
boolean isRequired,
String emptyPromoteMessage,
String promoteMessage,
java.util.function.Function<String,InputValidateResult<T>> handleInput) |
private static Collection<Integer> |
parseIntRanges(String text,
int maxValue) |
private static <T> void |
printOptionList(String message,
List<T> entities,
T defaultEntity,
java.util.function.Function<T,String> getNameFunc) |
<T> List<T> |
promoteMultipleEntities(String header,
String promotePrefix,
String selectNoneMessage,
List<T> entities,
java.util.function.Function<T,String> getNameFunc,
boolean allowEmpty,
String enterPromote,
List<T> defaultValue)
Promote user to choose some entities from a known list.
|
<T> T |
promoteSingleEntity(String header,
String message,
List<T> entities,
T defaultEntity,
java.util.function.Function<T,String> getNameFunc,
boolean isRequired)
Promote user to choose a single entity from a known list.
|
String |
promoteString(String message,
String defaultValue,
java.util.function.Function<String,InputValidateResult<String>> verify,
boolean isRequired)
Promote user to input a text value through a terminal.
|
Boolean |
promoteYesNo(String message,
Boolean defaultValue,
boolean isRequired)
Promote user to choose YES or NO through a terminal.
|
private InputValidateResult<Integer> |
validateUserInputAsInteger(String input,
int maxValue,
String message) |
private static final String EMPTY_REPLACEMENT
private static final Pattern REGEX_COMMA_SEPARATED_INTEGER_RANGES
private static final Pattern REGEX_NEXT_INTEGER_RANGE
private BufferedReader reader
public String promoteString(String message, String defaultValue, java.util.function.Function<String,InputValidateResult<String>> verify, boolean isRequired) throws IOException
IPrompterpromoteString in interface IPromptermessage - the promote messagedefaultValue - the default value if user presses ENTER key.verify - the function against user's inputisRequired - whether or not a null/empty value is acceptableIOException - when there are any IO errors.public Boolean promoteYesNo(String message, Boolean defaultValue, boolean isRequired) throws IOException
IPrompterpromoteYesNo in interface IPromptermessage - the promote message to give user a hint about the options.defaultValue - the default option if user presses ENTER key.isRequired - whether or not user must to accept or decline explicitly.IOException - when there are any IO errors.public <T> List<T> promoteMultipleEntities(String header, String promotePrefix, String selectNoneMessage, List<T> entities, java.util.function.Function<T,String> getNameFunc, boolean allowEmpty, String enterPromote, List<T> defaultValue) throws IOException
IPrompterallowEmpty is true, then user has the option to select none from
the list, otherwise, at least one entry must be selected.promoteMultipleEntities in interface IPrompterT - the entity typeheader - the message print before the option listpromotePrefix - the promote message after the options list, will be append with the text of range example and default entity.entities - the known list which are to be selected ingetNameFunc - the entity to string convert functionallowEmpty - whether or not to accept empty list.enterPromote - the promote message to give user a hint about the behavior of pressing ENTER key directly, should be align with the
actual meaning of defaultValuedefaultValue - the default entities when pressing ENTER key directly.IOException - when there are any IO errors.public <T> T promoteSingleEntity(String header, String message, List<T> entities, T defaultEntity, java.util.function.Function<T,String> getNameFunc, boolean isRequired) throws IOException
IPrompterisRequired is true, then user must select one entity.promoteSingleEntity in interface IPrompterT - the entity typeheader - the message print before the option listmessage - the message print before printing the optionsentities - the known list which are to be selected indefaultEntity - the default entity when pressing ENTER key directly.getNameFunc - the entity to string convert functionIOException - when there are any IO errors.private <T> T loopInput(T defaultValue,
boolean hasDefaultValue,
boolean isRequired,
String emptyPromoteMessage,
String promoteMessage,
java.util.function.Function<String,InputValidateResult<T>> handleInput)
throws IOException
IOExceptionprivate InputValidateResult<Integer> validateUserInputAsInteger(String input, int maxValue, String message)
public void close()
close in interface Closeableclose in interface AutoCloseableprivate static boolean isValidIntRangeInput(String text)
private static Collection<Integer> parseIntRanges(String text, int maxValue)
private static <T> void printOptionList(String message, List<T> entities, T defaultEntity, java.util.function.Function<T,String> getNameFunc)
Copyright © 2020. All rights reserved.