Class DefaultPrompter

    • Field Detail

      • REGEX_COMMA_SEPARATED_INTEGER_RANGES

        private static final Pattern REGEX_COMMA_SEPARATED_INTEGER_RANGES
      • REGEX_NEXT_INTEGER_RANGE

        private static final Pattern REGEX_NEXT_INTEGER_RANGE
    • Constructor Detail

      • DefaultPrompter

        public DefaultPrompter()
    • Method Detail

      • promoteString

        public String promoteString​(String message,
                                    String defaultValue,
                                    java.util.function.Function<String,​InputValidateResult<String>> verify,
                                    boolean isRequired)
                             throws IOException
        Description copied from interface: IPrompter
        Promote user to input a text value through a terminal.
        Specified by:
        promoteString in interface IPrompter
        Parameters:
        message - promote message
        defaultValue - the default value if user presses ENTER key.
        verify - the function against user's input
        isRequired - whether a null/empty value is acceptable
        Returns:
        the text value user has input
        Throws:
        IOException - when there are any IO errors.
      • promoteYesNo

        public Boolean promoteYesNo​(String message,
                                    Boolean defaultValue,
                                    boolean isRequired)
                             throws IOException
        Description copied from interface: IPrompter
        Promote user to choose YES or NO through a terminal. If this property is optional and there is no default option, then this method returns null when user presses ENTER key.
        Specified by:
        promoteYesNo in interface IPrompter
        Parameters:
        message - promote message to give user a hint about the options.
        defaultValue - the default option if user presses ENTER key.
        isRequired - whether user must accept or decline explicitly.
        Returns:
        the yes/no option
        Throws:
        IOException - when there are any IO errors.
      • promoteMultipleEntities

        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
        Description copied from interface: IPrompter
        Promote user to choose some entities from a known list. if allowEmpty is true, then user has the option to select none from the list, otherwise, at least one entry must be selected.
        Specified by:
        promoteMultipleEntities in interface IPrompter
        Type Parameters:
        T - the entity type
        Parameters:
        header - the message print before the option list
        promotePrefix - promote message after the options list, will be appended with the text of range example and default entity.
        entities - the known list which are to be selected in
        getNameFunc - the entity to string convert function
        allowEmpty - whether to accept empty list.
        enterPromote - promote message to give user a hint about the behavior of pressing ENTER key directly, should be aligned with the actual meaning of defaultValue
        defaultValue - the default entities when pressing ENTER key directly.
        Returns:
        the list user selected
        Throws:
        IOException - when there are any IO errors.
      • promoteSingleEntity

        public <T> T promoteSingleEntity​(String header,
                                         String message,
                                         List<T> entities,
                                         T defaultEntity,
                                         java.util.function.Function<T,​String> getNameFunc,
                                         boolean isRequired)
                                  throws IOException
        Description copied from interface: IPrompter
        Promote user to choose a single entity from a known list. if isRequired is true, then user must select one entity.
        Specified by:
        promoteSingleEntity in interface IPrompter
        Type Parameters:
        T - the entity type
        Parameters:
        header - the message print before the option list
        message - the message print before printing the options
        entities - the known list which are to be selected in
        defaultEntity - the default entity when pressing ENTER key directly.
        getNameFunc - the entity to string convert function
        Returns:
        the entity user selected
        Throws:
        IOException - when there are any IO errors.
      • isValidIntRangeInput

        private static boolean isValidIntRangeInput​(String text)
      • printOptionList

        private static <T> void printOptionList​(String message,
                                                List<T> entities,
                                                T defaultEntity,
                                                java.util.function.Function<T,​String> getNameFunc)