Beispiel #1
0
  /**
   * Updates the stored user with any not null information in the passed user
   *
   * @param u The user to update from.
   * @throws InvalidFieldException Thrown if anything is of the wrong format.
   */
  public void update(User u) throws InvalidFieldException {
    if (u.getFirstName() != null) {
      setFirstName(u.getFirstName());
    }

    if (u.getLastName() != null) {
      setLastName(u.getLastName());
    }

    if (u.getID() != null) {
      setID(u.getID());
    }

    if (u.getPoints() != getPoints()) {
      setPoints(u.getPoints());
    }

    if (u.getWeeklyPick() != null && !u.getWeeklyPick().isNull()) {
      setWeeklyPick(u.getWeeklyPick());
    }

    if (u.getUltimatePick() != null && !u.getUltimatePick().isNull()) {
      setUltimatePickNoSetPts(u.getUltimatePick());
    }

    if (u.getUltimatePoints() != getUltimatePoints()) {
      setUltimatePoints(u.getUltimatePoints());
    }
  }
Beispiel #2
0
  /**
   * Turns a JSON object into a User.
   *
   * @param o JSON object
   */
  public void fromJSONObject(JSONObject o) {
    try {
      setFirstName((String) o.remove(KEY_FIRST_NAME));
      setLastName((String) o.remove(KEY_LAST_NAME));
      setID((String) o.remove(KEY_ID));
      setPoints(Utils.numToInt(o.remove(KEY_POINTS)));

      String id = (String) o.remove(KEY_WEEKLY_PICK_ID);
      Contestant c = null;

      GameData g = GameData.getCurrentGame();

      if (id.equals(Contestant.NULL_ID)) {
        c = new Contestant();
        c.setNull();
      } else {
        c = g.getContestant(id);
      }
      setWeeklyPick(c);

      id = (String) o.remove(KEY_ULT_PICK_ID);
      if (id.equals(Contestant.NULL_ID)) {
        c = new Contestant();
        c.setNull();
      } else {
        c = g.getContestant(id);
      }
      setUltimatePick(c);

      setUltimatePoints(Utils.numToInt(o.remove(KEY_WIN_PICK_POINTS)));
      setNumBonusAnswer(((Number) o.remove(KEY_NUM_BONUS_ANSWER)).intValue());
    } catch (InvalidFieldException e) {
      System.out.println("Warning: InvalidFieldException in fromJSONObject");
      e.printStackTrace();
    }
  }
Beispiel #3
0
 /**
  * Constructor method for the type User sets names, initializes points
  *
  * @param first first name
  * @param last last name
  * @param id unique ID
  * @throws InvalidFieldException Thrown if any of the parameters passed are invalid
  */
 public User(String first, String last, String id) throws InvalidFieldException {
   setFirstName(first);
   setLastName(last);
   setID(id);
   setPoints(0); // begin with 0 points
 }