Record Class Question

java.lang.Object
java.lang.Record
it.unisa.diem.wordageddon_g16.models.Question
All Implemented Interfaces:
Serializable

public record Question(String text, List<String> answers, int correctAnswerIndex) extends Record implements Serializable
Rappresenta una domanda a risposta multipla generata dal GameService. Ogni Question contiene:
  • Il testo della domanda (text)
  • Un elenco di possibili risposte (answers)
  • L'indice della risposta corretta (correctAnswerIndex)
Utilizzato nella fase quiz per testare la comprensione dell'utente sui documenti letti.
See Also:
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    static enum 
    Enum interno che definisce le diverse tipologie di domande generabili.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    private final List<String>
    The field for the answers record component.
    private final int
    The field for the correctAnswerIndex record component.
    private final String
    The field for the text record component.
  • Constructor Summary

    Constructors
    Constructor
    Description
    Question(String text, List<String> answers, int correctAnswerIndex)
    Creates an instance of a Question record class.
  • Method Summary

    Modifier and Type
    Method
    Description
    Returns the value of the answers record component.
    int
    Returns the value of the correctAnswerIndex record component.
    static Question
    create(String text, List<String> answers, int correctAnswerIndex)
    Crea una nuova istanza di Question validando i parametri forniti.
    final boolean
    Indicates whether some other object is "equal to" this one.
    final int
    Returns a hash code value for this object.
    Returns the value of the text record component.
    final String
    Returns a string representation of this record class.

    Methods inherited from class java.lang.Object

    clone, finalize, getClass, notify, notifyAll, wait, wait, wait
  • Field Details

    • text

      private final String text
      The field for the text record component.
    • answers

      private final List<String> answers
      The field for the answers record component.
    • correctAnswerIndex

      private final int correctAnswerIndex
      The field for the correctAnswerIndex record component.
  • Constructor Details

    • Question

      public Question(String text, List<String> answers, int correctAnswerIndex)
      Creates an instance of a Question record class.
      Parameters:
      text - the value for the text record component
      answers - the value for the answers record component
      correctAnswerIndex - the value for the correctAnswerIndex record component
  • Method Details

    • create

      public static Question create(String text, List<String> answers, int correctAnswerIndex)
      Crea una nuova istanza di Question validando i parametri forniti. La domanda è valida solo se:
      • text non è null
      • answers non è null
      • correctAnswerIndex è compreso tra 0 e answers.size() - 1
      Se non rispettati, viene lanciata una IllegalArgumentException.
      Parameters:
      text - testo della domanda
      answers - lista delle possibili risposte
      correctAnswerIndex - indice della risposta corretta
      Returns:
      istanza valida di GameService.Question
      Throws:
      IllegalArgumentException - se i parametri sono invalidi
    • toString

      public final String toString()
      Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components.
      Specified by:
      toString in class Record
      Returns:
      a string representation of this object
    • hashCode

      public final int hashCode()
      Returns a hash code value for this object. The value is derived from the hash code of each of the record components.
      Specified by:
      hashCode in class Record
      Returns:
      a hash code value for this object
    • equals

      public final boolean equals(Object o)
      Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. Reference components are compared with Objects::equals(Object,Object); primitive components are compared with the compare method from their corresponding wrapper classes.
      Specified by:
      equals in class Record
      Parameters:
      o - the object with which to compare
      Returns:
      true if this object is the same as the o argument; false otherwise.
    • text

      public String text()
      Returns the value of the text record component.
      Returns:
      the value of the text record component
    • answers

      public List<String> answers()
      Returns the value of the answers record component.
      Returns:
      the value of the answers record component
    • correctAnswerIndex

      public int correctAnswerIndex()
      Returns the value of the correctAnswerIndex record component.
      Returns:
      the value of the correctAnswerIndex record component