summaryrefslogtreecommitdiff
path: root/src/com/p4square/grow/backend/resources/Question.java
blob: c53883cebb2208c27c63f60145da1dc7ce26febc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
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);
    }
}