summaryrefslogtreecommitdiff
path: root/src/main/java/com/p4square/grow/model/Question.java
diff options
context:
space:
mode:
authorJesse Morgan <jesse@jesterpm.net>2016-04-09 15:53:24 -0700
committerJesse Morgan <jesse@jesterpm.net>2016-04-09 15:53:24 -0700
commit371ccae3d1f31ec38f4af77fb7fcd175d49b3cd5 (patch)
tree38c4f1e8828f9af9c4b77a173bee0d312b321698 /src/main/java/com/p4square/grow/model/Question.java
parentbbf907e51dfcf157bdee24dead1d531122aa25db (diff)
parent3102d8bce3426d9cf41aeaf201c360d342677770 (diff)
Merge pull request #10 from PuyallupFoursquare/maven
Switching from Ivy+Ant to Maven.
Diffstat (limited to 'src/main/java/com/p4square/grow/model/Question.java')
-rw-r--r--src/main/java/com/p4square/grow/model/Question.java165
1 files changed, 165 insertions, 0 deletions
diff --git a/src/main/java/com/p4square/grow/model/Question.java b/src/main/java/com/p4square/grow/model/Question.java
new file mode 100644
index 0000000..f4b9458
--- /dev/null
+++ b/src/main/java/com/p4square/grow/model/Question.java
@@ -0,0 +1,165 @@
+/*
+ * Copyright 2013 Jesse Morgan
+ */
+
+package com.p4square.grow.model;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import com.fasterxml.jackson.annotation.JsonSubTypes;
+import com.fasterxml.jackson.annotation.JsonSubTypes.Type;
+import com.fasterxml.jackson.annotation.JsonTypeInfo;
+
+/**
+ * Model of an assessment question.
+ *
+ * @author Jesse Morgan <jesse@jesterpm.net>
+ */
+@JsonTypeInfo(
+ use = JsonTypeInfo.Id.NAME,
+ include = JsonTypeInfo.As.PROPERTY,
+ property = "type")
+@JsonSubTypes({
+ @Type(value = TextQuestion.class, name = "text"),
+ @Type(value = ImageQuestion.class, name = "image"),
+ @Type(value = SliderQuestion.class, name = "slider"),
+ @Type(value = QuadQuestion.class, name = "quad"),
+ @Type(value = CircleQuestion.class, name = "circle"),
+})
+public abstract class Question {
+ /**
+ * QuestionType indicates the type of Question.
+ *
+ * @author Jesse Morgan <jesse@jesterpm.net>
+ */
+ public enum QuestionType {
+ TEXT,
+ IMAGE,
+ SLIDER,
+ QUAD,
+ CIRCLE;
+
+ @Override
+ public String toString() {
+ return name().toLowerCase();
+ }
+ }
+
+ private String mQuestionId;
+ private QuestionType mType;
+ private String mQuestionText;
+ private Map<String, Answer> mAnswers;
+
+ private String mPreviousQuestionId;
+ private String mNextQuestionId;
+
+ public Question() {
+ mAnswers = new HashMap<String, Answer>();
+ }
+
+ /**
+ * @return the id String for this question.
+ */
+ public String getId() {
+ return mQuestionId;
+ }
+
+ /**
+ * Set the id String for this question.
+ * @param id New id
+ */
+ public void setId(String id) {
+ mQuestionId = id;
+ }
+
+ /**
+ * @return The Question text.
+ */
+ public String getQuestion() {
+ return mQuestionText;
+ }
+
+ /**
+ * Set the question text.
+ * @param value The new question text.
+ */
+ public void setQuestion(String value) {
+ mQuestionText = value;
+ }
+
+ /**
+ * @return The id String of the previous question or null if no previous question exists.
+ */
+ public String getPreviousQuestion() {
+ return mPreviousQuestionId;
+ }
+
+ /**
+ * Set the id string of the previous question.
+ * @param id Previous question id or null if there is no previous question.
+ */
+ public void setPreviousQuestion(String id) {
+ mPreviousQuestionId = id;
+ }
+
+ /**
+ * @return The id String of the next question or null if no next question exists.
+ */
+ public String getNextQuestion() {
+ return mNextQuestionId;
+ }
+
+ /**
+ * Set the id string of the next question.
+ * @param id next question id or null if there is no next question.
+ */
+ public void setNextQuestion(String id) {
+ mNextQuestionId = id;
+ }
+
+ /**
+ * @return a map of Answer id Strings to Answer objects.
+ */
+ public Map<String, Answer> getAnswers() {
+ return mAnswers;
+ }
+
+ /**
+ * Determine the id of the next question based on the answer to this
+ * question.
+ *
+ * @param answerid
+ * The id of the selected answer.
+ * @return a question id or null if this is the last question.
+ */
+ public String getNextQuestion(String answerid) {
+ String nextQuestion = null;
+
+ Answer a = mAnswers.get(answerid);
+ if (a != null) {
+ nextQuestion = a.getNextQuestion();
+ }
+
+ if (nextQuestion == null) {
+ nextQuestion = mNextQuestionId;
+ }
+
+ return nextQuestion;
+ }
+
+ /**
+ * Update the score based on the answer to this question.
+ *
+ * @param score The running score to update.
+ * @param answer The answer give to this question.
+ * @return true if scoring should continue, false if this answer trumps everything else.
+ */
+ public abstract boolean scoreAnswer(Score score, RecordedAnswer answer);
+
+ /**
+ * @return the QuestionType of this question.
+ */
+ public abstract QuestionType getType();
+
+}