QuestModel.java :  » Location » hauntedworld » sfu » iat » android » com » models » Android Open Source

Android Open Source » Location » hauntedworld 
hauntedworld » sfu » iat » android » com » models » QuestModel.java
package sfu.iat.android.com.models;

import android.util.Log;
import sfu.iat.android.com.constants.Constants;
import sfu.iat.android.com.utils.StringUtil;

public class QuestModel
{
  
  private int id = -1;
  private String name = "";
  private int type = -1;
  private int[] itemids = {};
  private String objective = "";
  private int rating = -1;
  private int start_lat = -1;
  private int start_lng = -1;
  private int lat_min = -1;
  private int lat_max = -1;
  private int lng_min = -1;
  private int lng_max = -1;
  private String icon = "";
  private WorldObjectModel objectModel;
  
  public QuestModel(int id, String name, int type, String itemids, String objective, int rating, 
      int start_lat, int start_lng, int lat_min, int lat_max, int lng_min, 
      int lng_max, String icon)
  {
    this.id = id;
    this.name = name;
    this.type = type;
    this.objective = objective;
    this.rating = rating;
    this.start_lat = start_lat;
    this.start_lng = start_lng;
    this.lat_min = lat_min;
    this.lat_max = lat_max;
    this.lng_min = lng_min;
    this.lng_max = lng_max;
    this.icon = icon;
    setItemids(itemids);
    objectModel = new WorldObjectModel(id, name, start_lat, start_lng, icon, Constants.MAP_MARKER_TYPE_QUEST, null, null);
  }
  
  /**
   * update a existing quest model
   * @param newQuest
   */
  public void update(QuestModel newQuest)
  {
    this.id = newQuest.getId();
    this.name = newQuest.getName();
    this.type = newQuest.getType();
    this.objective = newQuest.getObjective();
    this.rating = newQuest.getRating();
    this.start_lat = newQuest.getStartLatitude();
    this.start_lng = newQuest.getStartLongitude();
    this.lat_min = newQuest.getLatitudeMin();
    this.lat_max = newQuest.getLatitudeMax();
    this.lng_min = newQuest.getLongitudeMin();
    this.lng_max = newQuest.getLongitudeMax();
    this.icon = newQuest.getIcon();
    setItemids(StringUtil.arrayToString(newQuest.getItemids(), ","));
    objectModel.update(newQuest.getObjectModel());
    Log.i("QuestModel", "Quest updated, id=" + this.id);
  }
  
  public boolean validateBounds(int lat, int lng)
  {
    boolean withinBounds = true;
    if(lat < lat_min || lat > lat_max || lng < lng_min || lng > lng_max){
      withinBounds = false;
    }
    return withinBounds;
  }
  
  private void setItemids(String ids){
    if(ids.length() > 0){
      String[] idsStr = ids.split(",");
      this.itemids = new int[idsStr.length];
      for(int i=0; i<idsStr.length; i++){
        int id = Integer.parseInt(idsStr[i]);
        this.itemids[i] = id;
      }
    }
    else{
      this.itemids = new int[0];
    }
  }
  
  public String getObjective()
  {
    return this.objective;
  }
  
  public int getRating()
  {
    return this.rating;
  }
  
  public int getStartLatitude(){
    return this.start_lat;
  }
  
  public int getStartLongitude(){
    return this.start_lng;
  }
  
  public int getQuestType()
  {
    return this.type;
  }
  
  public int getId()
  {
    return this.id;
  }
  
  public String getName()
  {
    return this.name;
  }
  
  public int[] getItemids(){
    return this.itemids;
  }
  
  public int getLatitudeMax(){
    return this.lat_max;
  }
  
  public int getLatitudeMin(){
    return this.lat_min;
  }
  
  public int getLongitudeMax(){
    return this.lng_max;
  }
  
  public int getLongitudeMin(){
    return this.lng_min;
  }
  
  public String getIcon(){
    return this.icon;
  }
  
  public WorldObjectModel getObjectModel(){
    return this.objectModel;
  }
  
  public int getType(){
    return this.type;
  }
  
}
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.