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 enumEnum interno che definisce le diverse tipologie di domande generabili. -
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionanswers()Returns the value of theanswersrecord component.intReturns the value of thecorrectAnswerIndexrecord component.static QuestionCrea una nuova istanza diQuestionvalidando i parametri forniti.final booleanIndicates whether some other object is "equal to" this one.final inthashCode()Returns a hash code value for this object.text()Returns the value of thetextrecord component.final StringtoString()Returns a string representation of this record class.
-
Field Details
-
text
The field for thetextrecord component. -
answers
-
correctAnswerIndex
private final int correctAnswerIndexThe field for thecorrectAnswerIndexrecord component.
-
-
Constructor Details
-
Question
Creates an instance of aQuestionrecord class.- Parameters:
text- the value for thetextrecord componentanswers- the value for theanswersrecord componentcorrectAnswerIndex- the value for thecorrectAnswerIndexrecord component
-
-
Method Details
-
create
Crea una nuova istanza diQuestionvalidando i parametri forniti. La domanda è valida solo se:textnon ènullanswersnon ènullcorrectAnswerIndexè compreso tra0eanswers.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 thecomparemethod from their corresponding wrapper classes. -
text
Returns the value of thetextrecord component.- Returns:
- the value of the
textrecord component
-
answers
-
correctAnswerIndex
public int correctAnswerIndex()Returns the value of thecorrectAnswerIndexrecord component.- Returns:
- the value of the
correctAnswerIndexrecord component
-