created Question Classes
This commit is contained in:
parent
d927ddf66e
commit
ae81ac5935
4 changed files with 71 additions and 0 deletions
|
|
@ -0,0 +1,23 @@
|
||||||
|
package com.danieldiekert.buzzword.question;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public record ChoiceQuestion(
|
||||||
|
String text,
|
||||||
|
int points,
|
||||||
|
List<String> options,
|
||||||
|
int correctIndex
|
||||||
|
) implements Question {
|
||||||
|
|
||||||
|
public ChoiceQuestion {
|
||||||
|
if (text == null || text.isBlank())
|
||||||
|
throw new IllegalArgumentException("text must not be blank");
|
||||||
|
if (points <= 0)
|
||||||
|
throw new IllegalArgumentException("points must be positive");
|
||||||
|
if (options == null || options.isEmpty())
|
||||||
|
throw new IllegalArgumentException("options must not be empty");
|
||||||
|
if (correctIndex < 0 || correctIndex >= options.size())
|
||||||
|
throw new IllegalArgumentException("correctIndex out of bounds");
|
||||||
|
options = List.copyOf(options);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,18 @@
|
||||||
|
package com.danieldiekert.buzzword.question;
|
||||||
|
|
||||||
|
public record EstimateQuestion(
|
||||||
|
String text,
|
||||||
|
int points,
|
||||||
|
double correctValue,
|
||||||
|
String unit
|
||||||
|
) implements Question {
|
||||||
|
|
||||||
|
public EstimateQuestion {
|
||||||
|
if (text == null || text.isBlank())
|
||||||
|
throw new IllegalArgumentException("text must not be blank");
|
||||||
|
if (points <= 0)
|
||||||
|
throw new IllegalArgumentException("points must be positive");
|
||||||
|
if (unit == null)
|
||||||
|
throw new IllegalArgumentException("unit must not be null");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,7 @@
|
||||||
|
package com.danieldiekert.buzzword.question
|
||||||
|
|
||||||
|
public sealed interface Question permits EstimateQuestion, ChoiceQuestion, TextQuestion {
|
||||||
|
String text();
|
||||||
|
|
||||||
|
int points();
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,23 @@
|
||||||
|
package com.danieldiekert.buzzword.question;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public record TextQuestion(
|
||||||
|
String text,
|
||||||
|
int points,
|
||||||
|
String correctAnswer,
|
||||||
|
List<String> acceptedVariants
|
||||||
|
) implements Question {
|
||||||
|
|
||||||
|
public TextQuestion {
|
||||||
|
if (text == null || text.isBlank())
|
||||||
|
throw new IllegalArgumentException("text must not be blank");
|
||||||
|
if (points <= 0)
|
||||||
|
throw new IllegalArgumentException("points must be positive");
|
||||||
|
if (correctAnswer == null || correctAnswer.isBlank())
|
||||||
|
throw new IllegalArgumentException("correctAnswer must not be blank");
|
||||||
|
acceptedVariants = acceptedVariants == null
|
||||||
|
? List.of()
|
||||||
|
: List.copyOf(acceptedVariants);
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue