Android Open Source - Game-of-thrones-trivia Character To Questions Map






From Project

Back to project page Game-of-thrones-trivia.

License

The source code is released under:

MIT License

If you think the Android project Game-of-thrones-trivia listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.GameOfThrones.Trivia.core;
/*www .  j  a  v  a  2 s . co  m*/
import java.util.ArrayList;

/**
 * Creates and stores mapping info of characters to questions that reference the
 * characters.
 * 
 * @author andre
 * 
 */
public class CharacterToQuestionsMap {
  /**
   * 
   */
  private ArrayList<ArrayList<Integer>> gameCharactersIDs;
  private ArrayList<GameCharacter> gameCharacters;

  public CharacterToQuestionsMap(ArrayList<GameCharacter> gameCharacters) {
    this.gameCharacters = gameCharacters;
    gameCharactersIDs = new ArrayList<ArrayList<Integer>>();
    for (int i = 0; i < gameCharacters.size(); i++) {
      gameCharactersIDs.add(new ArrayList<Integer>());
    }
  }

  /**
   * Examines each string associated with a trivia and if the trivia matches
   * to one of the characters aliases then add that to the mappings collection
   * 
   * TODO - Expensive to perform for each trivia on each startup. will have to
   * find a way to cache mappings. Probably move all related pieces to DB
   * 
   * @param trivia
   */
  public void addMappings(Question question) {
    for (int i = 0; i < gameCharacters.size(); i++) {
      ArrayList<String> searchEle = gameCharacters.get(i)
          .getSearchTerms();
      for (String s : question.getAnswers()) {
        if (searchEle.contains(s)) {
          gameCharactersIDs.get(i).add(question.getId());
          break;
        }
      }
    }
  }

  /**
   * Returns the ids of questions mapped to a particular character
   * 
   * @param i
   * @return
   */
  private ArrayList<Integer> get(int i) {
    ArrayList<Integer> ele = gameCharactersIDs.get(i);
    return ele;
  }

  /**
   * Gets the id mapping for a character returns null if the character passed
   * is not found.
   * 
   * @param character
   * @return
   */
  public ArrayList<Integer> get(GameCharacter character) {
    int characterId;
    for (int i = 0; i < gameCharacters.size(); i++) {
      if (gameCharacters.get(i).equals(character)) {
        return get(i);
      }
    }
    return null;
  }

}




Java Source Code List

com.GameOfThrones.Trivia.core.CharacterToQuestionsMap.java
com.GameOfThrones.Trivia.core.GameCharacter.java
com.GameOfThrones.Trivia.core.HighScore.java
com.GameOfThrones.Trivia.core.OutOfQuestionsException.java
com.GameOfThrones.Trivia.core.QuestionCollection.java
com.GameOfThrones.Trivia.core.Question.java
com.GameOfThrones.Trivia.core.Session.java
com.GameOfThrones.Trivia.core.SimpleIterator.java
com.GameOfThrones.Trivia.core.TriviaGame.java
com.GameOfThrones.Trivia.data.HighScorePrefs.java
com.GameOfThrones.Trivia.data.RequestWebService.java
com.GameOfThrones.Trivia.data.StringsXMLFileData.java
com.GameOfThrones.Trivia.ui.AboutActivity.java
com.GameOfThrones.Trivia.ui.DynamicBackgroundActivity.java
com.GameOfThrones.Trivia.ui.GameActivity.java
com.GameOfThrones.Trivia.ui.HighScoreActivity.java
com.GameOfThrones.Trivia.ui.MainMenuActivity.java
com.GameOfThrones.Trivia.ui.ResultsActivity.java
com.GameOfThrones.Trivia.ui.TriviaSelectionActivity.java
com.GameOfThrones.Trivia.ui.music.MusicService.java
com.GameOfThrones.Trivia.util.GeneralAlgorithms.java
com.Spartacus.TriviaTest.TriviaMenuActivityTest.java
com.Spartacus.Trivia.utilTest.GeneralAlgorithmsTest.java