diff --git a/src/main/java/com/danieldiekert/buzzword/question/ChoiceQuestion.java b/src/main/java/com/danieldiekert/buzzword/question/ChoiceQuestion.java new file mode 100644 index 0000000..1fb2a91 --- /dev/null +++ b/src/main/java/com/danieldiekert/buzzword/question/ChoiceQuestion.java @@ -0,0 +1,23 @@ +package com.danieldiekert.buzzword.question; + +import java.util.List; + +public record ChoiceQuestion( + String text, + int points, + List 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); + } +} \ No newline at end of file diff --git a/src/main/java/com/danieldiekert/buzzword/question/EstimateQuestion.java b/src/main/java/com/danieldiekert/buzzword/question/EstimateQuestion.java new file mode 100644 index 0000000..80c804b --- /dev/null +++ b/src/main/java/com/danieldiekert/buzzword/question/EstimateQuestion.java @@ -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"); + } +} \ No newline at end of file diff --git a/src/main/java/com/danieldiekert/buzzword/question/Question.java b/src/main/java/com/danieldiekert/buzzword/question/Question.java new file mode 100644 index 0000000..9d8a000 --- /dev/null +++ b/src/main/java/com/danieldiekert/buzzword/question/Question.java @@ -0,0 +1,7 @@ +package com.danieldiekert.buzzword.question + +public sealed interface Question permits EstimateQuestion, ChoiceQuestion, TextQuestion { + String text(); + + int points(); +} \ No newline at end of file diff --git a/src/main/java/com/danieldiekert/buzzword/question/TextQuestion.java b/src/main/java/com/danieldiekert/buzzword/question/TextQuestion.java new file mode 100644 index 0000000..7a236c1 --- /dev/null +++ b/src/main/java/com/danieldiekert/buzzword/question/TextQuestion.java @@ -0,0 +1,23 @@ +package com.danieldiekert.buzzword.question; + +import java.util.List; + +public record TextQuestion( + String text, + int points, + String correctAnswer, + List 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); + } +} \ No newline at end of file