CoderanchCorral / Blackjack

Mozilla Public License 2.0
17 stars 2 forks source link

Create a multipurpose input utility for the CLI #17

Closed ksnortum closed 3 years ago

ksnortum commented 3 years ago

Multipurpose Input Utility

Create a multipurpose input utility for use with a command line interface. The user can pass a prompt and optional validation and the utility will read the provided input stream and return a possibly validated String or primitive.

Contructors

InputUtility([input_stream])

Constructor that takes an input stream to be used. If no input stream is provided, System.in will be used.

Methods

nextString(prompt, [validation_predicate])

Displays the prompt and reads the input stream, returning a possibly validated String.

nextInt(prompt, [validation_int_predicate])

Displays the prompt and reads the input stream, returning a possibly validated integer.

nextDouble(prompt, [validation_double_predicate])

Displays the prompt and reads the input stream, returning a possibly validated real number.

nextYesNo(prompt, [validation_yes_no_predicate])

Calls nextString, passing the prompt and a predicate that validates (case insensitive) "y", "n", "yes", "no".

pause([prompt])

Calls nextString with the prompt entered and waits for the user to press . The prompt defaults to "Press when ready" if no prompt is passed.

Static Methods

yesOrNo()

Returns a String predicate that tests for (case insensitive) "y", "n", "yes", "no".

oneOfThese(String...)

Returns a String predicate that takes two or more Strings and tests whether any one of them match the input.

intRange(lower, upper)

Returns an int predicate that tests whether the input is between the two limits.

doubleRange(lower, upper)

Returns a double predicate that tests whether the input is between the two limits.

#

nibsi commented 3 years ago

I like it.