diff options
author | Jesse Morgan <jesse@jesterpm.net> | 2013-08-04 16:09:29 -0700 |
---|---|---|
committer | Jesse Morgan <jesse@jesterpm.net> | 2013-08-04 16:09:29 -0700 |
commit | 52539d7aaba96b7997a3c5a07e4a1ad234af7d04 (patch) | |
tree | 2686f56bc37656c0824a05e28472f7334ed39028 /src/com/p4square/grow/backend/resources/Question.java | |
parent | 69e2512750dd75fce43a21226979996c3cd7da1d (diff) |
Committing everything since its long overdue.
Diffstat (limited to 'src/com/p4square/grow/backend/resources/Question.java')
-rw-r--r-- | src/com/p4square/grow/backend/resources/Question.java | 72 |
1 files changed, 72 insertions, 0 deletions
diff --git a/src/com/p4square/grow/backend/resources/Question.java b/src/com/p4square/grow/backend/resources/Question.java new file mode 100644 index 0000000..c53883c --- /dev/null +++ b/src/com/p4square/grow/backend/resources/Question.java @@ -0,0 +1,72 @@ +/* + * Copyright 2013 Jesse Morgan + */ + +package com.p4square.grow.backend.resources; + +import java.util.Collections; +import java.util.HashMap; +import java.util.Map; + +/** + * Model of an assessment question. + * + * @author Jesse Morgan <jesse@jesterpm.net> + */ +class Question { + public static enum QuestionType { + TEXT, IMAGE, SLIDER, QUAD; + } + + private final String mQuestionId; + private final QuestionType mType; + private final String mQuestionText; + private Map<String, Answer> mAnswers; + + private final String mPreviousQuestionId; + private final String mNextQuestionId; + + public Question(final Map<String, Object> map) { + mQuestionId = (String) map.get("id"); + mType = QuestionType.valueOf(((String) map.get("type")).toUpperCase()); + + mQuestionText = (String) map.get("text"); + + mPreviousQuestionId = (String) map.get("previousQuestion"); + mNextQuestionId = (String) map.get("nextQuestion"); + + mAnswers = new HashMap<String, Answer>(); + for (Map.Entry<String, Object> answer : + ((Map<String, Object>) map.get("answers")).entrySet()) { + + final String id = answer.getKey(); + final Map<String, Object> answerMap = (Map<String, Object>) answer.getValue(); + final Answer answerObj = new Answer(id, answerMap); + mAnswers.put(id, answerObj); + } + } + + public String getId() { + return mQuestionId; + } + + public QuestionType getType() { + return mType; + } + + public String getText() { + return mQuestionText; + } + + public String getPrevious() { + return mPreviousQuestionId; + } + + public String getNext() { + return mNextQuestionId; + } + + public Map<String, Answer> getAnswers() { + return Collections.unmodifiableMap(mAnswers); + } +} |