<commit_before>package com.noprestige.kanaquiz.questions;

import com.noprestige.kanaquiz.R;
import com.noprestige.kanaquiz.logs.LogDatabase;
import com.noprestige.kanaquiz.options.OptionsControl;

import java.util.TreeSet;

public class KanaQuestionBank extends WeightedList<KanaQuestion>
{
    private KanaQuestion currentQuestion;
    private String[] fullAnswerList = null;

    private static final int MAX_MULTIPLE_CHOICE_ANSWERS = 6;

    private QuestionRecord previousQuestions = null;

    KanaQuestionBank()
    {
        super();
    }

    public void newQuestion() throws NoQuestionsException
    {
        if (this.count() > 0)
        {
            if (previousQuestions == null)
                previousQuestions = new QuestionRecord(Math.min(this.count(), OptionsControl.getInt(R.string.prefid_repetition)));
            do
                currentQuestion = this.getRandom();
            while (!previousQuestions.add(currentQuestion));
        }
        else
            throw new NoQuestionsException();
    }

    public String getCurrentKana()
    {
        return currentQuestion.getKana();
    }

    public boolean checkCurrentAnswer(String response)
    {
        return currentQuestion.checkAnswer(response);
    }

    public String fetchCorrectAnswer()
    {
        return currentQuestion.fetchCorrectAnswer();
    }

    public boolean addQuestions(KanaQuestion[] questions)
    {
        previousQuestions = null;
        fullAnswerList = null;
        if (questions != null)
            for (KanaQuestion question : questions)
            {
                // Fetches the percentage of times the user got a kana right,
                // The 1.05f is to invert the value so we get the number of times they got it wrong,
                // and add 5% so any kana the user got perfect will still appear in the quiz.
                // Times 100f to get the percentage.
                this.add((1.05f - LogDatabase.DAO.getKanaPercentage(question.getKana())) * 100f, question);
            }
        return true;
    }

    public boolean addQuestions(KanaQuestionBank questions)
    {
        previousQuestions = null;
        fullAnswerList = null;

        return this.merge(questions);
    }

    public String[] getPossibleAnswers()
    {
        return getPossibleAnswers(MAX_MULTIPLE_CHOICE_ANSWERS);
    }

    public String[] getPossibleAnswers(int maxChoices)
    {
        if (fullAnswerList == null)
        {
            TreeSet<String> answers = new TreeSet<>(new GojuonOrder());
            for (KanaQuestion question : this.values())
                answers.add(question.fetchCorrectAnswer());
            fullAnswerList = new String[answers.size()];
            answers.toArray(fullAnswerList);
        }

        if (fullAnswerList.length <= maxChoices)
            return fullAnswerList;
        else<commit_msg>FullAnswerList builds with QuestionBank<commit_after>package com.noprestige.kanaquiz.questions;

import com.noprestige.kanaquiz.R;
import com.noprestige.kanaquiz.logs.LogDatabase;
import com.noprestige.kanaquiz.options.OptionsControl;

import java.util.TreeSet;

public class KanaQuestionBank extends WeightedList<KanaQuestion>
{
    private KanaQuestion currentQuestion;
    private TreeSet<String> fullAnswerList = new TreeSet<>(new GojuonOrder());

    private static final int MAX_MULTIPLE_CHOICE_ANSWERS = 6;

    private QuestionRecord previousQuestions = null;

    KanaQuestionBank()
    {
        super();
    }

    public void newQuestion() throws NoQuestionsException
    {
        if (this.count() > 0)
        {
            if (previousQuestions == null)
                previousQuestions = new QuestionRecord(Math.min(this.count(), OptionsControl.getInt(R.string.prefid_repetition)));
            do
                currentQuestion = this.getRandom();
            while (!previousQuestions.add(currentQuestion));
        }
        else
            throw new NoQuestionsException();
    }

    public String getCurrentKana()
    {
        return currentQuestion.getKana();
    }

    public boolean checkCurrentAnswer(String response)
    {
        return currentQuestion.checkAnswer(response);
    }

    public String fetchCorrectAnswer()
    {
        return currentQuestion.fetchCorrectAnswer();
    }

    public boolean addQuestions(KanaQuestion[] questions)
    {
        previousQuestions = null;
        if (questions != null)
            for (KanaQuestion question : questions)
            {
                // Fetches the percentage of times the user got a kana right,
                // The 1.05f is to invert the value so we get the number of times they got it wrong,
                // and add 5% so any kana the user got perfect will still appear in the quiz.
                // Times 100f to get the percentage.
                this.add((1.05f - LogDatabase.DAO.getKanaPercentage(question.getKana())) * 100f, question);
                fullAnswerList.add(question.fetchCorrectAnswer());
            }
        return true;
    }

    public boolean addQuestions(KanaQuestionBank questions)
    {
        previousQuestions = null;
        this.fullAnswerList.addAll(questions.fullAnswerList);
        return this.merge(questions);
    }

    public String[] getPossibleAnswers()
    {
        return getPossibleAnswers(MAX_MULTIPLE_CHOICE_ANSWERS);
    }

    public String[] getPossibleAnswers(int maxChoices)
    {
        if (fullAnswerList.size() <= maxChoices)
        {
            String[] answerArray = new String[fullAnswerList.size()];
            fullAnswerList.toArray(answerArray);
            return answerArray;
        }
        else
{'fraction_non_alphanumeric': 0.0826534231997162, 'fraction_numerical': 0.005321035828307911, 'mean_word_length': 2.374625972471574, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '680901', 'n_tokens_mistral': 1634, 'n_tokens_neox': 1477, 'n_words': 366}