package com.arcusweather.forecastio;

import java.util.HashMap;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

public class ForecastIODataPoint {

	private HashMap<String, String> mDataPointMap;
	
	/**
	 * constructor method which initializes data points provided by the api data
	 * @param forecastJsonObject the json object that will be used for instantiating this project.
	 */
	public ForecastIODataPoint(JSONObject forecastJsonObject) {
		mDataPointMap = new HashMap<String, String>();
		JSONArray dataPointNames = forecastJsonObject.names();
		for(int i=0;i<dataPointNames.length();i++) {
			String dataPointName = "";
			String dataPointValue = "";
			try {
				dataPointName = dataPointNames.getString(i);
			} catch (JSONException e) {
				//go to next
				continue;
			}
			
			try {
				dataPointValue = forecastJsonObject.getString(dataPointName);
			} catch (JSONException e) {
				//go to next
				continue;
			}
			mDataPointMap.put(dataPointName, dataPointValue);
		}

	}
	
	/**
	 * Method to retrieve a value for use
	 * @param key	string value of the parameter
	 * @return field value as string
	 */
	public String getValue(String key) {
		return mDataPointMap.get(key);
	}
	
	/**
	 * get Value as an integer
	 * @param key	string value of the parameter
	 * @return	field value as integer;
	 */
	public int getValueAsInt(String key) {
		return Integer.parseInt(getValue(key));
	}
	
	/**
	 * get Value as an double
	 * @param key	value of the amount 
	 * @return	field value as double;
	 */
	public Double getValueAsDouble(String key) {
		return Double.parseDouble(getValue(key));
	}
	
	/**
	 * get Value as an long
	 * @param key	value of the amount 
	 * @return	field value as long;
	 */
	public Long getValueAsLong(String key) {
		return Long.parseLong(getValue(key));
	}
}

@@ -1393,440 +1393,1030 @@
 %7B%0A%09%09
-return Integer.parseInt(getValue(key));%0A%09%7D%0A%09%0A%09/**%0A%09 * get Value as an double%0A%09 * @param key%09value of the amount %0A%09 * @return%09field value as double;%0A%09 */%0A%09public Double getValueAsDouble(String key) %7B%0A%09%09return Double.parseDouble(getValue(key));%0A%09%7D%0A%09%0A%09/**%0A%09 * get Value as an long%0A%09 * @param key%09value of the amount %0A%09 * @return%09field value as long;%0A%09 */%0A%09public Long getValueAsLong(String key) %7B%0A%09%09return Long.parseLong(getValue(key))
+String val = %22%22;%0A%09%09try%7B%0A%09%09%09val = getValue(key);%0A%09%09%7D%0A%09%09catch(NullPointerException e) %7B%0A%09%09%09return 0;%0A%09%09%7D%0A%09%09%0A%09%09int ret = 0;%0A%09%09try %7B%0A%09%09%09ret = Integer.parseInt(val);;%0A%09%09%7D%0A%09%09catch(NumberFormatException n) %7B%0A%09%09%09return 0;%0A%09%09%7D%0A%09%09return ret;%0A%09%7D%0A%09%0A%09/**%0A%09 * get Value as an double%0A%09 * @param key%09value of the amount %0A%09 * @return%09field value as double;%0A%09 */%0A%09public Double getValueAsDouble(String key) %7B%0A%09%09String val = %22%22;%0A%09%09try%7B%0A%09%09%09val = getValue(key);%0A%09%09%7D%0A%09%09catch(NullPointerException e) %7B%0A%09%09%09return null;%0A%09%09%7D%0A%09%09%0A%09%09double ret = 0;%0A%09%09try %7B%0A%09%09%09ret = Double.parseDouble(val);%0A%09%09%7D%0A%09%09catch(NumberFormatException n) %7B%0A%09%09%09return null;%0A%09%09%7D%0A%09%09return ret;%0A%09%7D%0A%09%0A%09/**%0A%09 * get Value as an long%0A%09 * @param key%09value of the amount %0A%09 * @return%09field value as long;%0A%09 */%0A%09public Long getValueAsLong(String key) %7B%0A%09%09String val = %22%22;%0A%09%09try%7B%0A%09%09%09val = getValue(key);%0A%09%09%7D%0A%09%09catch(NullPointerException e) %7B%0A%09%09%09return null;%0A%09%09%7D%0A%09%09%0A%09%09long ret = 0;%0A%09%09try %7B%0A%09%09%09ret = Long.parseLong(val);%0A%09%09%7D%0A%09%09catch(NumberFormatException n) %7B%0A%09%09%09return null;%0A%09%09%7D%0A%09%09return ret
 ;%0A%09%7D

return nulls for getValueAs* functions when key isnt present