summaryrefslogtreecommitdiff
path: root/src/com/p4square/grow/provider/QuestionProvider.java
blob: b569dc8b3c87a8175acbbb95287377a7dbff454c (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
/*
 * Copyright 2013 Jesse Morgan
 */

package com.p4square.grow.provider;

import java.io.IOException;

import com.p4square.grow.model.Question;

/**
 * QuestionProvider wraps an existing Provider to get and put Questions.
 *
 * @author Jesse Morgan <jesse@jesterpm.net>
 */
public abstract class QuestionProvider<K> implements Provider<String, Question> {

    private Provider<K, Question> mProvider;

    public QuestionProvider(Provider<K, Question> provider) {
        mProvider = provider;
    }

    @Override
    public Question get(String key) throws IOException {
        return mProvider.get(makeKey(key));
    }

    @Override
    public void put(String key, Question obj) throws IOException {
        mProvider.put(makeKey(key), obj);
    }

    /**
     * Make a Key for questionId.
     *
     * @param questionId The question id.
     * @return a key for questionId.
     */
    protected abstract K makeKey(String questionId);
}