Class Question
java.lang.Object
com.marcpg.libpg.formular.question.Question
- Direct Known Subclasses:
BooleanQuestion
,CheckboxesQuestion
,IntegerQuestion
,MultipleChoiceQuestion
,TextQuestion
Represents a formular's question, with title, description, input and rendering.
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
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic final class
Represents an exception that's thrown by a question. -
Field Summary
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionabstract void
Renders the current question toSystem.out
.abstract Object
getInput()
Gets the current or preferably final input of the question.protected final boolean
invalid()
Checks if this question does not meet the set requirement, if it's set.final boolean
Checks if the question is already submitted or not.abstract void
Resets the state of this question to be as if it was just created.void
Sets theFormular
that manages and renders this question.setRequirement
(String questionId, Object questionValue) Sets the requirement of this question.abstract void
submit()
Submits the question with the current choice and locks in a final answer.abstract FormularResult.Result
toResult()
Converts this question to a Result, that can be used in a FormularResult.
-
Field Details
-
form
The question's description. -
submitted
protected boolean submittedIf the question was already submitted or not. -
id
The question's title. -
title
The question's title. -
description
The question's description. -
requirement
The question's requirement. Pair(ID, Value).
-
-
Constructor Details
-
Question
Creates a new question.- Parameters:
id
- The question's unique identifier.title
- The question's title.description
- The question's description.
-
-
Method Details
-
setForm
Sets theFormular
that manages and renders this question.- Parameters:
form
- TheFormular
that manages and renders this question.
-
setRequirement
Sets the requirement of this question. It works by checking if the question with the set ID has the specified value or not. The question is checked from this question's formular.- Parameters:
questionId
- The checked question's ID.questionValue
- The value to check for.- Returns:
- A reference to this object.
-
invalid
protected final boolean invalid()Checks if this question does not meet the set requirement, if it's set.- Returns:
true
if the question doesn't meet the set requirement.
false
if the question meets the set requirement.
-
resetState
public abstract void resetState()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. -
submit
public abstract void submit()Submits the question with the current choice and locks in a final answer. -
isSubmitted
public final boolean isSubmitted()Checks if the question is already submitted or not.- Returns:
- If the question is already submitted or not.
-
getInput
Gets the current or preferably final input of the question.- Returns:
- The current or preferably final input of this question.
-
toResult
Converts this question to a Result, that can be used in a FormularResult.- Returns:
- The converted result.
-
cliRender
public abstract void cliRender()Renders the current question toSystem.out
. Will only work forCLIFormular
s.
-