ui

## Class REPL

- java.lang.Object
- - ui.REPL

-     public class REPL
      extends java.lang.Object

  Read-evaluate-print-loop (REPL) implementation. Asks questions on the given PrintStream (usually System.out) and manages answers to these questions on the given InputStream (usually Scanner of System.in). Answer are processed via simple validation, like length. Special methods for enumerations allow for easy choosing from a given enum.
  Author:
    David Hudec (dwdization@gmail.com)

- - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `private java.util.Scanner` | `in`
    `private java.io.PrintStream` | `out`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `REPL(java.io.PrintStream out, java.io.InputStream in)`

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `private void` | `ask(java.lang.String question)` Formats given question and asks it.
    `java.lang.String` | `askForBits(java.lang.String question, int count)` Asks for a given number of bits (ones and zeros).
    `boolean` | `askForBoolean(java.lang.String question)` Asks for a boolean value with given question and accepts yes, y, no, n, irrespective of case, as answers.
    `boolean` | `askForBoolean(java.lang.String question, java.lang.String[] yesAnswers, java.lang.String[] noAnswers)` Asks for a boolean value with given question, a set of positive answers and a set of negative answers.
    `boolean` | `askForBoolean(java.lang.String question, java.lang.String yesAnswer, java.lang.String noAnswer)` Asks for a boolean value with given question, and offers given positive and negative answers Blocks until one of given answers is provided.
    `byte` | `askForByte(java.lang.String question)` Asks for a single byte value (0-255).
    `int` | `askForChoice(java.lang.String question, java.lang.String[] options)` Asks for a pick from given list of options.
    `<E extends EnumBase> E` | `askForEnumOption(java.lang.String question, java.lang.Class<E> e)`
    `java.lang.String` | `askForHexString(java.lang.String question)` Asks a general question.
    `java.lang.String` | `askForHexStringNotEmpty(java.lang.String question)` Asks a general question.
    `int` | `askForInt(java.lang.String question)` Asks for an integer value without specifying the range.
    `int` | `askForIntBetween(java.lang.String question, int min, int max)` Asks for an integer value in the given range of values.
    `java.lang.String` | `askForString(java.lang.String question)` Asks a general question.
    `java.lang.String` | `askForStringNotEmpty(java.lang.String question)` Asks a general question.
    `private void` | `tryAgain(java.lang.String expected)` Formats a "Wrong value, try again" statement.

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Field Detail

    - #### in

          private java.util.Scanner in

    - #### out

          private java.io.PrintStream out

  - ### Constructor Detail

    - #### REPL

          public REPL(java.io.PrintStream out,
                      java.io.InputStream in)

  - ### Method Detail

    - #### ask

          private void ask(java.lang.String question)

      Formats given question and asks it.
      Parameters:
        `question` - question to be asked

    - #### askForBits

          public java.lang.String askForBits(java.lang.String question,
                                             int count)

      Asks for a given number of bits (ones and zeros). Block until a valid answer is provided.
      Parameters:
        `question` - question to be asked
        `count` - desired number of bits for the answer
      Returns:
        bits in a String as provided by user

    - #### askForBoolean

          public boolean askForBoolean(java.lang.String question)

      Asks for a boolean value with given question and accepts yes, y, no, n, irrespective of case, as answers.
      Parameters:
        `question` - question to be asked
      Returns:
        true / false as chosen by user

    - #### askForBoolean

          public boolean askForBoolean(java.lang.String question,
                                       java.lang.String[] yesAnswers,
                                       java.lang.String[] noAnswers)

      Asks for a boolean value with given question, a set of positive answers and a set of negative answers. Blocks until some of given answers is provided.
      Parameters:
        `question` - question to be asked
        `yesAnswers` - list of answers to be considered positive
        `noAnswers` - list of answers to be considered negative
      Returns:
        true / false as chosen by user

    - #### askForBoolean

          public boolean askForBoolean(java.lang.String question,
                                       java.lang.String yesAnswer,
                                       java.lang.String noAnswer)

      Asks for a boolean value with given question, and offers given positive and negative answers Blocks until one of given answers is provided.
      Parameters:
        `question` - question to be asked
        `yesAnswer` - answer to be considered positive
        `noAnswer` - answer to be considered negative
      Returns:
        true / false as chosen by user

    - #### askForByte

          public byte askForByte(java.lang.String question)

      Asks for a single byte value (0-255). Does not return until a valid answer is provided.
      Parameters:
        `question` - question to be asked
      Returns:
        byte provided by user

    - #### askForChoice

          public int askForChoice(java.lang.String question,
                                  java.lang.String[] options)

      Asks for a pick from given list of options. Does not return until a valid answer is provided.
      Parameters:
        `question` - question to be asked
        `options` - list of options to choose from
      Returns:
        index of option selected by user

    - #### askForEnumOption

          public <E extends EnumBase> E askForEnumOption(java.lang.String question,
                                                         java.lang.Class<E> e)

    - #### askForHexString

          public java.lang.String askForHexString(java.lang.String question)

      Asks a general question. First general answer containing only hexadecimal characters is provided, including an empty String. Blocks until a valid answer is provided.
      Parameters:
        `question` - question to be asked
      Returns:
        first hexadecimal answer from the user

    - #### askForHexStringNotEmpty

          public java.lang.String askForHexStringNotEmpty(java.lang.String question)

      Asks a general question. First general non-empty answer containing only hexadecimal characters is provided. Blocks until a valid answer is provided.
      Parameters:
        `question` - question to be asked
      Returns:
        first non-empty hexadecimal answer from the user

    - #### askForInt

          public int askForInt(java.lang.String question)

      Asks for an integer value without specifying the range. Does not return until a valid answer is provided.
      Parameters:
        `question` - question to be asked
      Returns:
        integer specified by user

    - #### askForIntBetween

          public int askForIntBetween(java.lang.String question,
                                      int min,
                                      int max)

      Asks for an integer value in the given range of values. Does not return until a valid answer within given range is provided.
      Parameters:
        `question` - question to be asked
        `min` - minimal required value
        `max` - maximal required value
      Returns:
        integer specified by user

    - #### askForString

          public java.lang.String askForString(java.lang.String question)

      Asks a general question. First general answer is provided, including an empty String.
      Parameters:
        `question` - question to be asked
      Returns:
        first answer from the user

    - #### askForStringNotEmpty

          public java.lang.String askForStringNotEmpty(java.lang.String question)

      Asks a general question. First non-empty answer is provided. Blocks until then.
      Parameters:
        `question` - question to be asked
      Returns:
        first non-empty answer from the user

    - #### tryAgain

          private void tryAgain(java.lang.String expected)

      Formats a "Wrong value, try again" statement. Expected value example is provided from the given String.
      Parameters:
        `expected` - hint for the user on what to insert