Skip to content

Commit

Permalink
Stopped code from running redundantly
Browse files Browse the repository at this point in the history
The slice of code for the multiple choice function that builds a list of
unique answers in the getPossibleAnswers method, used to run every time
the method was called, which was unnecessary since the result would
always be the same every time. Now, it will only run the first time the
method is called after a change to the contents of the question bank.
  • Loading branch information
theblackwidower committed Jan 24, 2018
1 parent a68da65 commit b0ac8aa
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions app/src/main/java/com/noprestige/kanaquiz/KanaQuestionBank.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
class KanaQuestionBank extends ArrayList<KanaQuestion>
{
private KanaQuestion currentQuestion;
private ArrayList<String> fullAnswerList = null;
private Random rng = new Random();

private static final int MAX_MULTIPLE_CHOICE_ANSWERS = 6;
Expand Down Expand Up @@ -51,19 +52,22 @@ String fetchCorrectAnswer()
boolean addQuestions(KanaQuestion[] questions)
{
previousQuestions = null;
fullAnswerList = null;
return super.addAll(Arrays.asList(questions));
}

boolean addQuestions(KanaQuestion[] questions1, KanaQuestion[] questions2)
{
previousQuestions = null;
fullAnswerList = null;
return (super.addAll(Arrays.asList(questions1)) &&
super.addAll(Arrays.asList(questions2)));
}

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

Expand All @@ -74,11 +78,13 @@ String[] getPossibleAnswers()

String[] getPossibleAnswers(int maxChoices)
{
ArrayList<String> fullAnswerList = new ArrayList<>();

for (int i = 0; i < size(); i++)
if (!fullAnswerList.contains(get(i).fetchCorrectAnswer()))
fullAnswerList.add(get(i).fetchCorrectAnswer());
if (fullAnswerList == null)
{
fullAnswerList = new ArrayList<>();
for (int i = 0; i < size(); i++)
if (!fullAnswerList.contains(get(i).fetchCorrectAnswer()))
fullAnswerList.add(get(i).fetchCorrectAnswer());
}

ArrayList<String> possibleAnswerStrings = new ArrayList<>();

Expand Down

0 comments on commit b0ac8aa

Please sign in to comment.