Class Question

java.lang.Object
com.marcpg.libpg.formular.question.Question
Direct Known Subclasses:
BooleanQuestion, CheckboxesQuestion, IntegerQuestion, MultipleChoiceQuestion, TextQuestion

public abstract class Question extends Object
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)!
Since:
0.0.8
  • Field Details

    • form

      protected Formular form
      The question's description.
    • submitted

      protected boolean submitted
      If the question was already submitted or not.
    • id

      public final String id
      The question's title.
    • title

      public final String title
      The question's title.
    • description

      public final String description
      The question's description.
    • requirement

      protected Pair<String,Object> requirement
      The question's requirement. Pair(ID, Value).
  • Constructor Details

    • Question

      protected Question(String id, String title, String description)
      Creates a new question.
      Parameters:
      id - The question's unique identifier.
      title - The question's title.
      description - The question's description.
  • Method Details

    • setForm

      public void setForm(Formular form)
      Sets the Formular that manages and renders this question.
      Parameters:
      form - The Formular that manages and renders this question.
    • setRequirement

      public Question setRequirement(String questionId, Object questionValue)
      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

      public abstract Object getInput()
      Gets the current or preferably final input of the question.
      Returns:
      The current or preferably final input of this question.
    • toResult

      public abstract FormularResult.Result 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 to System.out. Will only work for CLIFormulars.