package org.azavea.otm.data;

import org.azavea.otm.App;
import org.json.JSONException;
import org.json.JSONObject;

import android.util.Log;

public class Species extends Model {
	public Species() {
		data = new JSONObject();
	}
	
	public Species(int id, String scientificName, String commonName) throws JSONException {
		this();
		this.setCommonName(commonName);
		this.setScientificName(scientificName);
		this.setId(id);
	}
	
	public int getId() throws JSONException {
		return data.getInt("id");
	}

	public void setId(int id) throws JSONException {
		data.put("id", id);
	}

	public String getScientificName() throws JSONException {
		return data.getString("scientific_name");
	}

	public void setScientificName(String scientificName) throws JSONException {
		data.put("scientific_name", scientificName);
	}

	public String getCommonName() throws JSONException {
		return data.getString("common_name");
	}

	public void setCommonName(String commonName) throws JSONException {
		data.put("common_name", commonName);
	}

	public String getSpecies() throws JSONException {
		return data.getString("species");
	}

	public void setSpecies(String species) throws JSONException {
		data.put("species", species);
	}
	
	public String getGenus() throws JSONException {
		return data.getString("genus");
	}

	public void setGenus(String genus) throws JSONException {
		data.put("genus", genus);
	}
	
	@Override
	public String toString() {
		try {
			return getCommonName();
		} catch (JSONException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return null;
		
	}
}

@@ -27,35 +27,8 @@
 a;%0A%0A
-import org.azavea.otm.App;%0A
 impo
@@ -87,34 +87,8 @@
 t;%0A%0A
-import android.util.Log;%0A%0A
 publ
@@ -118,16 +118,38 @@
 s Model 
+implements Comparable 
 %7B%0A%09publi
@@ -1357,16 +1357,362 @@
 );%0A%09%7D%0A%09%0A
+%0A%09public int compareTo(Object otherOne) %0A%09%7B%0A%09%09Species other = (Species)otherOne;%0A%09%09try %7B%0A%09%09%09if (getCommonName().compareTo(other.getCommonName()) %3C 0) return -1;%0A%09%09%09if (getCommonName().compareTo(other.getCommonName())  %3E 0) return 1;%0A%09%09%7D catch (JSONException e) %7B%0A%09%09%09// TODO Auto-generated catch block%0A%09%09%09e.printStackTrace();%0A%09%09%7D%0A%09  return 0;%0A%09%7D%0A%0A
 %09@Overri

Implement Comparable on Species