Class BooleanQuestion
java.lang.Object
com.marcpg.libpg.formular.question.Question
com.marcpg.libpg.formular.question.BooleanQuestion
A question with either true or false, with advanced input supporting multiple languages, based on starting letters.
Note that most features will require you to manually implement the JNA dependency (>5.14.0)!
Note that most features will require you to manually implement the JNA dependency (>5.14.0)!
- Since:
- 0.0.8
- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from class com.marcpg.libpg.formular.question.Question
Question.QuestionException
-
Field Summary
Modifier and TypeFieldDescriptionAll starting letters that correspond to a negative answer.All starting letters that correspond to a positive answer.Fields inherited from class com.marcpg.libpg.formular.question.Question
description, form, id, requirement, submitted, title
-
Constructor Summary
ConstructorDescriptionBooleanQuestion
(String id, String title, String description) Creates a new boolean question with the default choice set to true.BooleanQuestion
(String id, String title, String description, boolean defaultChoice) Creates a new boolean question. -
Method Summary
Modifier and TypeMethodDescriptionvoid
Renders the current question toSystem.out
.boolean
Gets the set default choice.getInput()
Gets the current or preferably final input of the question.void
Resets the state of this question to be as if it was just created.void
setChoice
(boolean choice) Sets the choice, if the question wasn't already submitted.void
submit()
Submits the question with the current choice and locks in a final answer.void
submit
(boolean choice) Submits the question with a specific value.toResult()
Converts this question to a Result, that can be used in a FormularResult.Methods inherited from class com.marcpg.libpg.formular.question.Question
invalid, isSubmitted, setForm, setRequirement
-
Field Details
-
FALSE_LETTERS
All starting letters that correspond to a negative answer. -
TRUE_LETTERS
All starting letters that correspond to a positive answer.
-
-
Constructor Details
-
BooleanQuestion
public BooleanQuestion(@Pattern("[a-z0-9_-]+") String id, String title, String description, boolean defaultChoice) Creates a new boolean question.- Parameters:
id
- The question's unique identifier.title
- The question's title.description
- The question's description.defaultChoice
- The question's default choice.
-
BooleanQuestion
Creates a new boolean question with the default choice set to true.- Parameters:
id
- The question's unique identifier.title
- The question's title.description
- The question's description.
-
-
Method Details
-
getDefaultChoice
public boolean getDefaultChoice()Gets the set default choice. By default, this is true.- Returns:
- The question's default choice.
-
resetState
public void resetState()Description copied from class:Question
Resets the state of this question to be as if it was just created. Won't reset the question's settings, but only the already chosen and rendered things.- Specified by:
resetState
in classQuestion
-
setChoice
public void setChoice(boolean choice) Sets the choice, if the question wasn't already submitted.- Parameters:
choice
- The new choice.
-
submit
public void submit(boolean choice) Submits the question with a specific value.- Parameters:
choice
- The choice to be submitted.
-
submit
public void submit()Description copied from class:Question
Submits the question with the current choice and locks in a final answer. -
getInput
Description copied from class:Question
Gets the current or preferably final input of the question. -
toResult
Description copied from class:Question
Converts this question to a Result, that can be used in a FormularResult. -
cliRender
public void cliRender()Renders the current question toSystem.out
. Will only work forCLIFormular
s.
If the default choice is true, it will ask this:Choice [Y|n]:
-