PossibleAnswer.java 2.79 KB
/*
 * Copyright Codecrew Ry
 * 
 * All rights reserved.
 * 
 * This license applies to any software containing a notice placed by the 
 * copyright holder. Such software is herein referred to as the Software. 
 * This license covers modification, distribution and use of the Software. 
 * 
 * Any distribution and use in source and binary forms, with or without 
 * modification is not permitted without explicit written permission from the 
 * copyright owner. 
 * 
 * A non-exclusive royalty-free right is granted to the copyright owner of the 
 * Software to use, modify and distribute all modifications to the Software in 
 * future versions of the Software. 
 * 
 */
package fi.codecrew.moya.model;

import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.JoinColumn;
import javax.persistence.Lob;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;

@Entity
@Table(name = "possible_answer")
public class PossibleAnswer extends GenericEntity {

    public PossibleAnswer() {
        super();
    }

    private static final long serialVersionUID = 1686553713211996800L;
    @Column(nullable = false)
    private String answer;
    @Column(nullable = false)
    private Integer sort = 100;

    @Column(nullable = false)
    private boolean textanswer = false;

    @Lob
    private String description;

    @JoinColumn(name = "question_id", referencedColumnName = "id", nullable = false)
    @ManyToOne
    private PollQuestion question;

    @OneToMany(mappedBy = "choice", cascade = CascadeType.ALL)
    private List<PollAnswer> answers;

    public String getAnswer() {
        return answer;
    }

    public void setAnswer(String answer) {
        this.answer = answer;
    }

    public Integer getSort() {
        return sort;
    }

    public void setSort(Integer sort) {
        this.sort = sort;
    }

    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    public PollQuestion getQuestion() {
        return question;
    }

    public void setQuestion(PollQuestion question) {
        this.question = question;
    }

    public List<PollAnswer> getAnswers() {
        return answers;
    }

    public void setAnswers(List<PollAnswer> answers) {
        this.answers = answers;
    }

    public void setTextanswer(Boolean textanswer) {
        this.textanswer = textanswer;
    }

    public Boolean getTextanswer() {
        return textanswer;
    }

    public int getCheckedAnswers() {
        int ret = 0;
        for (PollAnswer and : answers) {
            if (and.getAnswerBoolean()) {
                ++ret;
            }
        }
        return ret;
    }

}