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
)
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enum
Enum interno che definisce le diverse tipologie di domande generabili. -
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionanswers()
Returns the value of theanswers
record component.int
Returns the value of thecorrectAnswerIndex
record component.static Question
Crea una nuova istanza diQuestion
validando i parametri forniti.final boolean
Indicates whether some other object is "equal to" this one.final int
hashCode()
Returns a hash code value for this object.text()
Returns the value of thetext
record component.final String
toString()
Returns a string representation of this record class.
-
Field Details
-
text
The field for thetext
record component. -
answers
-
correctAnswerIndex
private final int correctAnswerIndexThe field for thecorrectAnswerIndex
record component.
-
-
Constructor Details
-
Question
Creates an instance of aQuestion
record class.- Parameters:
text
- the value for thetext
record componentanswers
- the value for theanswers
record componentcorrectAnswerIndex
- the value for thecorrectAnswerIndex
record component
-
-
Method Details
-
create
Crea una nuova istanza diQuestion
validando i parametri forniti. La domanda è valida solo se:text
non ènull
answers
non ènull
correctAnswerIndex
è compreso tra0
eanswers.size() - 1
IllegalArgumentException
.- Parameters:
text
- testo della domandaanswers
- lista delle possibili rispostecorrectAnswerIndex
- indice della risposta corretta- Returns:
- istanza valida di
GameService.Question
- Throws:
IllegalArgumentException
- se i parametri sono invalidi
-
toString
-
hashCode
-
equals
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 withObjects::equals(Object,Object)
; primitive components are compared with thecompare
method from their corresponding wrapper classes. -
text
Returns the value of thetext
record component.- Returns:
- the value of the
text
record component
-
answers
-
correctAnswerIndex
public int correctAnswerIndex()Returns the value of thecorrectAnswerIndex
record component.- Returns:
- the value of the
correctAnswerIndex
record component
-