mirror of
https://bitbucket.org/ethauvin/owm-japis.git
synced 2025-04-25 01:47:10 -07:00
Fixed bug of wrong data and time and improved code formatting.
This commit is contained in:
parent
4535ffd037
commit
0e90f5dcda
6 changed files with 1513 additions and 1184 deletions
|
@ -25,59 +25,73 @@ import java.util.Date;
|
||||||
import org.json.JSONObject;
|
import org.json.JSONObject;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This class provides default implementations for {@link net.aksingh.java.api.owm.CurrentWeatherData}
|
* This class provides default implementations for
|
||||||
* and {@link net.aksingh.java.api.owm.ForecastWeatherData} classes.
|
* {@link net.aksingh.java.api.owm.CurrentWeatherData} and
|
||||||
* Standard behaviors like the <code>has</code> and the <code>get</code>
|
* {@link net.aksingh.java.api.owm.ForecastWeatherData} classes. Standard
|
||||||
* methods for information about weather or forecast (for example,
|
* behaviors like the <code>has</code> and the <code>get</code> methods for
|
||||||
* temperature, pressure, weather, clouds, wind, etc.) are defined here.
|
* information about weather or forecast (for example, temperature, pressure,
|
||||||
*
|
* weather, clouds, wind, etc.) are defined here.
|
||||||
|
* <p>
|
||||||
* @author Ashutosh Kumar Singh
|
* @author Ashutosh Kumar Singh
|
||||||
* @version 2013/07/26
|
* @version 2013/07/26
|
||||||
* @since 2.5.0.1
|
* @since 2.5.0.1
|
||||||
*/
|
*/
|
||||||
abstract public class AbstractWeatherData {
|
abstract public class AbstractWeatherData {
|
||||||
/** Key for JSON object - Clouds */
|
|
||||||
|
/**
|
||||||
|
* Key for JSON object - Clouds
|
||||||
|
*/
|
||||||
protected final String JSON_CLOUDS = "clouds";
|
protected final String JSON_CLOUDS = "clouds";
|
||||||
/** Key for JSON object - Coordinates (Geographic coordinates) */
|
/**
|
||||||
|
* Key for JSON object - Coordinates (Geographic coordinates)
|
||||||
|
*/
|
||||||
protected final String JSON_COORD = "coord";
|
protected final String JSON_COORD = "coord";
|
||||||
/** Key for JSON object - Main (Temperature, pressure, etc.) */
|
/**
|
||||||
|
* Key for JSON object - Main (Temperature, pressure, etc.)
|
||||||
|
*/
|
||||||
protected final String JSON_MAIN = "main";
|
protected final String JSON_MAIN = "main";
|
||||||
/** Key for JSON array - Weather (Weather name, description, etc.) */
|
/**
|
||||||
|
* Key for JSON array - Weather (Weather name, description, etc.)
|
||||||
|
*/
|
||||||
protected final String JSON_WEATHER = "weather";
|
protected final String JSON_WEATHER = "weather";
|
||||||
/** Key for JSON object - Wind */
|
/**
|
||||||
|
* Key for JSON object - Wind
|
||||||
|
*/
|
||||||
protected final String JSON_WIND = "wind";
|
protected final String JSON_WIND = "wind";
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
************************
|
************************
|
||||||
* Defining sub-classes
|
* Defining sub-classes
|
||||||
************************
|
************************
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This class provides default implementations for <code>Clouds</code>.
|
* This class provides default implementations for <code>Clouds</code>.
|
||||||
* Standard behaviors like the <code>has</code> and the <code>get</code>
|
* Standard behaviors like the <code>has</code> and the <code>get</code>
|
||||||
* methods for information about clouds (for example, percentage of
|
* methods for information about clouds (for example, percentage of clouds,
|
||||||
* clouds, etc.) are defined here.
|
* etc.) are defined here.
|
||||||
*
|
* <p>
|
||||||
* @author Ashutosh Kumar Singh
|
* @author Ashutosh Kumar Singh
|
||||||
* @version 2013/07/27
|
* @version 2013/07/27
|
||||||
* @since 2.5.0.1
|
* @since 2.5.0.1
|
||||||
*/
|
*/
|
||||||
abstract public static class Clouds {
|
abstract public static class Clouds {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Key for JSON variable <code>Clouds -> All</code>
|
* Key for JSON variable <code>Clouds -> All</code> (percentage of all
|
||||||
* (percentage of all clouds)
|
* clouds)
|
||||||
*/
|
*/
|
||||||
private final String JSON_CLOUDS_ALL = "all";
|
private final String JSON_CLOUDS_ALL = "all";
|
||||||
|
|
||||||
/** Percentage of all clouds */
|
/**
|
||||||
|
* Percentage of all clouds
|
||||||
|
*/
|
||||||
private final float percentOfClouds;
|
private final float percentOfClouds;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Non-parameterized constructor
|
* Non-parameterized constructor
|
||||||
*
|
* <p>
|
||||||
* <p>Initializes variables as per following basis:<br>
|
* <p>
|
||||||
|
* Initializes variables as per following basis:<br>
|
||||||
* Boolean: <code>false</code><br>
|
* Boolean: <code>false</code><br>
|
||||||
* Integral: Minimum value (MIN_VALUE)<br>
|
* Integral: Minimum value (MIN_VALUE)<br>
|
||||||
* Floating point: Not a number (NaN)<br>
|
* Floating point: Not a number (NaN)<br>
|
||||||
|
@ -86,61 +100,73 @@ abstract public class AbstractWeatherData {
|
||||||
public Clouds() {
|
public Clouds() {
|
||||||
this.percentOfClouds = Float.NaN;
|
this.percentOfClouds = Float.NaN;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Parameterized constructor
|
* Parameterized constructor
|
||||||
*
|
* <p>
|
||||||
* Initializes variables from values from the given JSON object.
|
* Initializes variables from values from the given JSON object.
|
||||||
*
|
* <p>
|
||||||
* @param jsonObj JSON object containing data about clouds
|
* @param jsonObj JSON object containing data about clouds
|
||||||
*/
|
*/
|
||||||
public Clouds(JSONObject jsonObj) {
|
public Clouds(JSONObject jsonObj) {
|
||||||
this.percentOfClouds = (float) jsonObj.optDouble(this.JSON_CLOUDS_ALL, Double.NaN);
|
this.percentOfClouds = (float) jsonObj.optDouble(this.JSON_CLOUDS_ALL, Double.NaN);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tells if the data for percentage of all clouds is available or not.
|
* Tells if the data for percentage of all clouds is available or not.
|
||||||
* @return <code>true</code> if data available, otherwise <code>false</code>
|
* <p>
|
||||||
|
* @return <code>true</code> if data available, otherwise
|
||||||
|
* <code>false</code>
|
||||||
*/
|
*/
|
||||||
public boolean hasPercentageOfClouds() {
|
public boolean hasPercentageOfClouds() {
|
||||||
return (this.percentOfClouds != Float.NaN);
|
return (this.percentOfClouds != Float.NaN);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns data for percentage of all clouds.
|
* Returns data for percentage of all clouds.
|
||||||
* @return Percentage of all clouds if available,
|
* <p>
|
||||||
* otherwise <code>Float.NaN</code>, i.e., Not a Number.
|
* @return Percentage of all clouds if available, otherwise
|
||||||
|
* <code>Float.NaN</code>, i.e., Not a Number.
|
||||||
*/
|
*/
|
||||||
public float getPercentageOfClouds() {
|
public float getPercentageOfClouds() {
|
||||||
return this.percentOfClouds;
|
return this.percentOfClouds;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This class provides default implementations for <code>Coord</code>.
|
* This class provides default implementations for <code>Coord</code>.
|
||||||
* Standard behaviors like the <code>has</code> and the <code>get</code>
|
* Standard behaviors like the <code>has</code> and the <code>get</code>
|
||||||
* methods for information about geographic coordinates (latitude
|
* methods for information about geographic coordinates (latitude and
|
||||||
* and longitude) are defined here.
|
* longitude) are defined here.
|
||||||
*
|
* <p>
|
||||||
* @author Ashutosh Kumar Singh
|
* @author Ashutosh Kumar Singh
|
||||||
* @version 2013/07/28
|
* @version 2013/07/28
|
||||||
*/
|
*/
|
||||||
abstract public static class Coord {
|
abstract public static class Coord {
|
||||||
/** Key for JSON variable <code>Coord -> Latitude</code> */
|
|
||||||
|
/**
|
||||||
|
* Key for JSON variable <code>Coord -> Latitude</code>
|
||||||
|
*/
|
||||||
private final String JSON_COORD_LATITUDE = "lat";
|
private final String JSON_COORD_LATITUDE = "lat";
|
||||||
/** Key for JSON variable <code>Coord -> Longitude</code> */
|
/**
|
||||||
|
* Key for JSON variable <code>Coord -> Longitude</code>
|
||||||
|
*/
|
||||||
private final String JSON_COORD_LONGITUDE = "lon";
|
private final String JSON_COORD_LONGITUDE = "lon";
|
||||||
|
|
||||||
/** Latitude */
|
/**
|
||||||
|
* Latitude
|
||||||
|
*/
|
||||||
private final float lat;
|
private final float lat;
|
||||||
/** Longitude */
|
/**
|
||||||
|
* Longitude
|
||||||
|
*/
|
||||||
private final float lon;
|
private final float lon;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Non-parameterized constructor
|
* Non-parameterized constructor
|
||||||
*
|
* <p>
|
||||||
* <p>Initializes variables as per following basis:<br>
|
* <p>
|
||||||
|
* Initializes variables as per following basis:<br>
|
||||||
* Boolean: <code>false</code><br>
|
* Boolean: <code>false</code><br>
|
||||||
* Integral: Minimum value (MIN_VALUE)<br>
|
* Integral: Minimum value (MIN_VALUE)<br>
|
||||||
* Floating point: Not a number (NaN)<br>
|
* Floating point: Not a number (NaN)<br>
|
||||||
|
@ -150,92 +176,119 @@ abstract public class AbstractWeatherData {
|
||||||
this.lat = Float.NaN;
|
this.lat = Float.NaN;
|
||||||
this.lon = Float.NaN;
|
this.lon = Float.NaN;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Parameterized constructor
|
* Parameterized constructor
|
||||||
*
|
* <p>
|
||||||
* Initializes variables from values from the given JSON object.
|
* Initializes variables from values from the given JSON object.
|
||||||
*
|
* <p>
|
||||||
* @param jsonObj JSON object containing data about coordinates
|
* @param jsonObj JSON object containing data about coordinates
|
||||||
*/
|
*/
|
||||||
public Coord(JSONObject jsonObj) {
|
public Coord(JSONObject jsonObj) {
|
||||||
this.lat = (float) jsonObj.optDouble(this.JSON_COORD_LATITUDE, Double.NaN);
|
this.lat = (float) jsonObj.optDouble(this.JSON_COORD_LATITUDE, Double.NaN);
|
||||||
this.lon = (float) jsonObj.optDouble(this.JSON_COORD_LONGITUDE, Double.NaN);
|
this.lon = (float) jsonObj.optDouble(this.JSON_COORD_LONGITUDE, Double.NaN);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tells if the data for latitude of the city is available or not.
|
* Tells if the data for latitude of the city is available or not.
|
||||||
* @return <code>true</code> if data available, otherwise <code>false</code>
|
* <p>
|
||||||
|
* @return <code>true</code> if data available, otherwise
|
||||||
|
* <code>false</code>
|
||||||
*/
|
*/
|
||||||
public boolean hasLatitude() {
|
public boolean hasLatitude() {
|
||||||
return (this.lat != Float.NaN);
|
return (this.lat != Float.NaN);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tells if the data for longitude of the city is available or not.
|
* Tells if the data for longitude of the city is available or not.
|
||||||
* @return <code>true</code> if data available, otherwise <code>false</code>
|
* <p>
|
||||||
|
* @return <code>true</code> if data available, otherwise
|
||||||
|
* <code>false</code>
|
||||||
*/
|
*/
|
||||||
public boolean hasLongitude() {
|
public boolean hasLongitude() {
|
||||||
return (this.lon != Float.NaN);
|
return (this.lon != Float.NaN);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns data for latitude of the city.
|
* Returns data for latitude of the city.
|
||||||
* @return Latitude of the city if available,
|
* <p>
|
||||||
* otherwise <code>Float.NaN</code>, i.e., Not a Number.
|
* @return Latitude of the city if available, otherwise
|
||||||
|
* <code>Float.NaN</code>, i.e., Not a Number.
|
||||||
*/
|
*/
|
||||||
public float getLatitude() {
|
public float getLatitude() {
|
||||||
return this.lat;
|
return this.lat;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns data for longitude of the city.
|
* Returns data for longitude of the city.
|
||||||
* @return Longitude of the city if available,
|
* <p>
|
||||||
* otherwise <code>Float.NaN</code>, i.e., Not a Number.
|
* @return Longitude of the city if available, otherwise
|
||||||
|
* <code>Float.NaN</code>, i.e., Not a Number.
|
||||||
*/
|
*/
|
||||||
public float getLongitude() {
|
public float getLongitude() {
|
||||||
return this.lon;
|
return this.lon;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This class provides default implementations for <code>Main</code>.
|
* This class provides default implementations for <code>Main</code>.
|
||||||
* Standard behaviors like the <code>has</code> and the <code>get</code>
|
* Standard behaviors like the <code>has</code> and the <code>get</code>
|
||||||
* methods for information about main weather elements (for example,
|
* methods for information about main weather elements (for example,
|
||||||
* temperature, pressure, humidity, etc.) are defined here.
|
* temperature, pressure, humidity, etc.) are defined here.
|
||||||
*
|
* <p>
|
||||||
* @author Ashutosh Kumar Singh
|
* @author Ashutosh Kumar Singh
|
||||||
* @version 2013/07/28
|
* @version 2013/07/28
|
||||||
* @since 2.5.0.1
|
* @since 2.5.0.1
|
||||||
*/
|
*/
|
||||||
abstract public static class Main {
|
abstract public static class Main {
|
||||||
/** Key for JSON variable <code>Main -> Temperature</code> */
|
|
||||||
|
/**
|
||||||
|
* Key for JSON variable <code>Main -> Temperature</code>
|
||||||
|
*/
|
||||||
private final String JSON_MAIN_TEMP = "temp";
|
private final String JSON_MAIN_TEMP = "temp";
|
||||||
/** Key for JSON variable <code>Main -> Minimum temperature</code> */
|
/**
|
||||||
|
* Key for JSON variable <code>Main -> Minimum temperature</code>
|
||||||
|
*/
|
||||||
private final String JSON_MAIN_TEMP_MIN = "temp_min";
|
private final String JSON_MAIN_TEMP_MIN = "temp_min";
|
||||||
/** Key for JSON variable <code>Main -> Maximum temperature</code> */
|
/**
|
||||||
|
* Key for JSON variable <code>Main -> Maximum temperature</code>
|
||||||
|
*/
|
||||||
private final String JSON_MAIN_TEMP_MAX = "temp_max";
|
private final String JSON_MAIN_TEMP_MAX = "temp_max";
|
||||||
/** Key for JSON variable <code>Main -> Pressure</code> */
|
/**
|
||||||
|
* Key for JSON variable <code>Main -> Pressure</code>
|
||||||
|
*/
|
||||||
private final String JSON_MAIN_PRESSURE = "pressure";
|
private final String JSON_MAIN_PRESSURE = "pressure";
|
||||||
/** Key for JSON variable <code>Main -> Humidity</code> */
|
/**
|
||||||
|
* Key for JSON variable <code>Main -> Humidity</code>
|
||||||
|
*/
|
||||||
private final String JSON_MAIN_HUMIDITY = "humidity";
|
private final String JSON_MAIN_HUMIDITY = "humidity";
|
||||||
|
|
||||||
/** Temperature */
|
/**
|
||||||
|
* Temperature
|
||||||
|
*/
|
||||||
private final float temp;
|
private final float temp;
|
||||||
/** Minimum temperature */
|
/**
|
||||||
|
* Minimum temperature
|
||||||
|
*/
|
||||||
private final float minTemp;
|
private final float minTemp;
|
||||||
/** Maximum temperature */
|
/**
|
||||||
|
* Maximum temperature
|
||||||
|
*/
|
||||||
private final float maxTemp;
|
private final float maxTemp;
|
||||||
/** Pressure */
|
/**
|
||||||
|
* Pressure
|
||||||
|
*/
|
||||||
private final float pressure;
|
private final float pressure;
|
||||||
/** Humidity */
|
/**
|
||||||
|
* Humidity
|
||||||
|
*/
|
||||||
private final float humidity;
|
private final float humidity;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Non-parameterized constructor
|
* Non-parameterized constructor
|
||||||
*
|
* <p>
|
||||||
* <p>Initializes variables as per following basis:<br>
|
* <p>
|
||||||
|
* Initializes variables as per following basis:<br>
|
||||||
* Boolean: <code>false</code><br>
|
* Boolean: <code>false</code><br>
|
||||||
* Integral: Minimum value (MIN_VALUE)<br>
|
* Integral: Minimum value (MIN_VALUE)<br>
|
||||||
* Floating point: Not a number (NaN)<br>
|
* Floating point: Not a number (NaN)<br>
|
||||||
|
@ -248,13 +301,13 @@ abstract public class AbstractWeatherData {
|
||||||
this.pressure = Float.NaN;
|
this.pressure = Float.NaN;
|
||||||
this.humidity = Float.NaN;
|
this.humidity = Float.NaN;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Parameterized constructor
|
* Parameterized constructor
|
||||||
*
|
* <p>
|
||||||
* Initializes variables from values from the given JSON object.
|
* Initializes variables from values from the given JSON object.
|
||||||
*
|
* <p>
|
||||||
* @param jsonObj JSON object containing data about main weather
|
* @param jsonObj JSON object containing data about main weather
|
||||||
* elements. For example, temperature, pressure, etc.
|
* elements. For example, temperature, pressure, etc.
|
||||||
*/
|
*/
|
||||||
public Main(JSONObject jsonObj) {
|
public Main(JSONObject jsonObj) {
|
||||||
|
@ -264,127 +317,162 @@ abstract public class AbstractWeatherData {
|
||||||
this.pressure = (float) jsonObj.optDouble(this.JSON_MAIN_PRESSURE, Double.NaN);
|
this.pressure = (float) jsonObj.optDouble(this.JSON_MAIN_PRESSURE, Double.NaN);
|
||||||
this.humidity = (float) jsonObj.optDouble(this.JSON_MAIN_HUMIDITY, Double.NaN);
|
this.humidity = (float) jsonObj.optDouble(this.JSON_MAIN_HUMIDITY, Double.NaN);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tells if the data for temperature of the city is available or not.
|
* Tells if the data for temperature of the city is available or not.
|
||||||
* @return <code>true</code> if data available, otherwise <code>false</code>
|
* <p>
|
||||||
|
* @return <code>true</code> if data available, otherwise
|
||||||
|
* <code>false</code>
|
||||||
*/
|
*/
|
||||||
public boolean hasTemperature() {
|
public boolean hasTemperature() {
|
||||||
return (this.temp != Float.NaN);
|
return (this.temp != Float.NaN);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tells if the data for minimum temperature of the city is available or not.
|
* Tells if the data for minimum temperature of the city is available or
|
||||||
* @return <code>true</code> if data available, otherwise <code>false</code>
|
* not.
|
||||||
|
* <p>
|
||||||
|
* @return <code>true</code> if data available, otherwise
|
||||||
|
* <code>false</code>
|
||||||
*/
|
*/
|
||||||
public boolean hasMinTemperature() {
|
public boolean hasMinTemperature() {
|
||||||
return (this.minTemp != Float.NaN);
|
return (this.minTemp != Float.NaN);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tells if the data for maximum temperature of the city is available or not.
|
* Tells if the data for maximum temperature of the city is available or
|
||||||
* @return <code>true</code> if data available, otherwise <code>false</code>
|
* not.
|
||||||
|
* <p>
|
||||||
|
* @return <code>true</code> if data available, otherwise
|
||||||
|
* <code>false</code>
|
||||||
*/
|
*/
|
||||||
public boolean hasMaxTemperature() {
|
public boolean hasMaxTemperature() {
|
||||||
return (this.maxTemp != Float.NaN);
|
return (this.maxTemp != Float.NaN);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tells if the data for pressure of the city is available or not.
|
* Tells if the data for pressure of the city is available or not.
|
||||||
* @return <code>true</code> if data available, otherwise <code>false</code>
|
* <p>
|
||||||
|
* @return <code>true</code> if data available, otherwise
|
||||||
|
* <code>false</code>
|
||||||
*/
|
*/
|
||||||
public boolean hasPressure() {
|
public boolean hasPressure() {
|
||||||
return (this.pressure != Float.NaN);
|
return (this.pressure != Float.NaN);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tells if the data for humidity of the city is available or not.
|
* Tells if the data for humidity of the city is available or not.
|
||||||
* @return <code>true</code> if data available, otherwise <code>false</code>
|
* <p>
|
||||||
|
* @return <code>true</code> if data available, otherwise
|
||||||
|
* <code>false</code>
|
||||||
*/
|
*/
|
||||||
public boolean hasHumidity() {
|
public boolean hasHumidity() {
|
||||||
return (this.humidity != Float.NaN);
|
return (this.humidity != Float.NaN);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns data for temperature of the city.
|
* Returns data for temperature of the city.
|
||||||
* @return Temperature of the city if available,
|
* <p>
|
||||||
* otherwise <code>Float.NaN</code>, i.e., Not a Number.
|
* @return Temperature of the city if available, otherwise
|
||||||
|
* <code>Float.NaN</code>, i.e., Not a Number.
|
||||||
*/
|
*/
|
||||||
public float getTemperature() {
|
public float getTemperature() {
|
||||||
return this.temp;
|
return this.temp;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns data for minimum temperature of the city.
|
* Returns data for minimum temperature of the city.
|
||||||
* @return Minimum temperature of the city if available,
|
* <p>
|
||||||
* otherwise <code>Float.NaN</code>, i.e., Not a Number.
|
* @return Minimum temperature of the city if available, otherwise
|
||||||
|
* <code>Float.NaN</code>, i.e., Not a Number.
|
||||||
*/
|
*/
|
||||||
public float getMinTemperature() {
|
public float getMinTemperature() {
|
||||||
return this.minTemp;
|
return this.minTemp;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns data for maximum temperature of the city.
|
* Returns data for maximum temperature of the city.
|
||||||
* @return Maximum temperature of the city if available,
|
* <p>
|
||||||
* otherwise <code>Float.NaN</code>, i.e., Not a Number.
|
* @return Maximum temperature of the city if available, otherwise
|
||||||
|
* <code>Float.NaN</code>, i.e., Not a Number.
|
||||||
*/
|
*/
|
||||||
public float getMaxTemperature() {
|
public float getMaxTemperature() {
|
||||||
return this.maxTemp;
|
return this.maxTemp;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns data for pressure of the city.
|
* Returns data for pressure of the city.
|
||||||
* @return Pressure of the city if available,
|
* <p>
|
||||||
* otherwise <code>Float.NaN</code>, i.e., Not a Number.
|
* @return Pressure of the city if available, otherwise
|
||||||
|
* <code>Float.NaN</code>, i.e., Not a Number.
|
||||||
*/
|
*/
|
||||||
public float getPressure() {
|
public float getPressure() {
|
||||||
return this.pressure;
|
return this.pressure;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns data for humidity of the city.
|
* Returns data for humidity of the city.
|
||||||
* @return Humidity of the city if available,
|
* <p>
|
||||||
* otherwise <code>Float.NaN</code>, i.e., Not a Number.
|
* @return Humidity of the city if available, otherwise
|
||||||
|
* <code>Float.NaN</code>, i.e., Not a Number.
|
||||||
*/
|
*/
|
||||||
public float getHumidity() {
|
public float getHumidity() {
|
||||||
return this.humidity;
|
return this.humidity;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This class provides default implementations for <code>Weather</code>.
|
* This class provides default implementations for <code>Weather</code>.
|
||||||
* Standard behaviors like the <code>has</code> and the <code>get</code>
|
* Standard behaviors like the <code>has</code> and the <code>get</code>
|
||||||
* methods for information about weather (for example, id, name,
|
* methods for information about weather (for example, id, name,
|
||||||
* description, icon, etc.) are defined here.
|
* description, icon, etc.) are defined here.
|
||||||
*
|
* <p>
|
||||||
* @author Ashutosh Kumar Singh
|
* @author Ashutosh Kumar Singh
|
||||||
* @version 2013/07/28
|
* @version 2013/07/28
|
||||||
* @since 2.5.0.1
|
* @since 2.5.0.1
|
||||||
*/
|
*/
|
||||||
abstract public static class Weather {
|
abstract public static class Weather {
|
||||||
/** Key for JSON variable in array <code>Weather -> ID</code> */
|
|
||||||
|
/**
|
||||||
|
* Key for JSON variable in array <code>Weather -> ID</code>
|
||||||
|
*/
|
||||||
private final String JSON_WEATHER_ID = "id";
|
private final String JSON_WEATHER_ID = "id";
|
||||||
/** Key for JSON variable in array <code>Weather -> Main (name of weather)</code> */
|
/**
|
||||||
|
* Key for JSON variable in array
|
||||||
|
* <code>Weather -> Main (name of weather)</code>
|
||||||
|
*/
|
||||||
private final String JSON_WEATHER_MAIN = "main";
|
private final String JSON_WEATHER_MAIN = "main";
|
||||||
/** Key for JSON variable <code>Weather -> Description</code> */
|
/**
|
||||||
|
* Key for JSON variable <code>Weather -> Description</code>
|
||||||
|
*/
|
||||||
private final String JSON_WEATHER_DESCRIPTION = "description";
|
private final String JSON_WEATHER_DESCRIPTION = "description";
|
||||||
/** Key for JSON variable in array <code>Weather -> Icon</code> */
|
/**
|
||||||
|
* Key for JSON variable in array <code>Weather -> Icon</code>
|
||||||
|
*/
|
||||||
private final String JSON_WEATHER_ICON = "icon";
|
private final String JSON_WEATHER_ICON = "icon";
|
||||||
|
|
||||||
/** Weather ID */
|
/**
|
||||||
|
* Weather ID
|
||||||
|
*/
|
||||||
private final int id;
|
private final int id;
|
||||||
/** Weather name */
|
/**
|
||||||
|
* Weather name
|
||||||
|
*/
|
||||||
private final String name;
|
private final String name;
|
||||||
/** Weather description */
|
/**
|
||||||
|
* Weather description
|
||||||
|
*/
|
||||||
private final String description;
|
private final String description;
|
||||||
/** Weather icon */
|
/**
|
||||||
|
* Weather icon
|
||||||
|
*/
|
||||||
private final String icon;
|
private final String icon;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Non-parameterized constructor
|
* Non-parameterized constructor
|
||||||
*
|
* <p>
|
||||||
* <p>Initializes variables as per following basis:<br>
|
* <p>
|
||||||
|
* Initializes variables as per following basis:<br>
|
||||||
* Boolean: <code>false</code><br>
|
* Boolean: <code>false</code><br>
|
||||||
* Integral: Minimum value (MIN_VALUE)<br>
|
* Integral: Minimum value (MIN_VALUE)<br>
|
||||||
* Floating point: Not a number (NaN)<br>
|
* Floating point: Not a number (NaN)<br>
|
||||||
|
@ -396,13 +484,14 @@ abstract public class AbstractWeatherData {
|
||||||
this.description = null;
|
this.description = null;
|
||||||
this.icon = null;
|
this.icon = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Parameterized constructor
|
* Parameterized constructor
|
||||||
*
|
* <p>
|
||||||
* Initializes variables from values from the given JSON object.
|
* Initializes variables from values from the given JSON object.
|
||||||
*
|
* <p>
|
||||||
* @param jsonObj JSON object containing data about weather id, name, etc.
|
* @param jsonObj JSON object containing data about weather id, name,
|
||||||
|
* etc.
|
||||||
*/
|
*/
|
||||||
public Weather(JSONObject jsonObj) {
|
public Weather(JSONObject jsonObj) {
|
||||||
this.id = jsonObj.optInt(this.JSON_WEATHER_ID, Integer.MIN_VALUE);
|
this.id = jsonObj.optInt(this.JSON_WEATHER_ID, Integer.MIN_VALUE);
|
||||||
|
@ -410,102 +499,123 @@ abstract public class AbstractWeatherData {
|
||||||
this.description = jsonObj.optString(this.JSON_WEATHER_DESCRIPTION, null);
|
this.description = jsonObj.optString(this.JSON_WEATHER_DESCRIPTION, null);
|
||||||
this.icon = jsonObj.optString(this.JSON_WEATHER_ICON, null);
|
this.icon = jsonObj.optString(this.JSON_WEATHER_ICON, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tells if the data for weather's code is available or not.
|
* Tells if the data for weather's code is available or not.
|
||||||
* @return <code>true</code> if data available, otherwise <code>false</code>
|
* <p>
|
||||||
|
* @return <code>true</code> if data available, otherwise
|
||||||
|
* <code>false</code>
|
||||||
*/
|
*/
|
||||||
public boolean hasWeatherCode() {
|
public boolean hasWeatherCode() {
|
||||||
return (this.id != Integer.MIN_VALUE);
|
return (this.id != Integer.MIN_VALUE);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tells if the data for weather's name is available or not.
|
* Tells if the data for weather's name is available or not.
|
||||||
* @return <code>true</code> if data available, otherwise <code>false</code>
|
* <p>
|
||||||
|
* @return <code>true</code> if data available, otherwise
|
||||||
|
* <code>false</code>
|
||||||
*/
|
*/
|
||||||
public boolean hasWeatherName() {
|
public boolean hasWeatherName() {
|
||||||
return (this.name != null);
|
return (this.name != null);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tells if the data for weather's description is available or not.
|
* Tells if the data for weather's description is available or not.
|
||||||
* @return <code>true</code> if data available, otherwise <code>false</code>
|
* <p>
|
||||||
|
* @return <code>true</code> if data available, otherwise
|
||||||
|
* <code>false</code>
|
||||||
*/
|
*/
|
||||||
public boolean hasWeatherDescription() {
|
public boolean hasWeatherDescription() {
|
||||||
return (this.description != null);
|
return (this.description != null);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tells if the data for name of weather's icon is available or not.
|
* Tells if the data for name of weather's icon is available or not.
|
||||||
* @return <code>true</code> if data available, otherwise <code>false</code>
|
* <p>
|
||||||
|
* @return <code>true</code> if data available, otherwise
|
||||||
|
* <code>false</code>
|
||||||
*/
|
*/
|
||||||
public boolean hasWeatherIconName() {
|
public boolean hasWeatherIconName() {
|
||||||
return (this.icon != null);
|
return (this.icon != null);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns data for code for weather of the city.
|
* Returns data for code for weather of the city.
|
||||||
* @return Code for weather of the city if available,
|
* <p>
|
||||||
* otherwise <code>Integer.MIN_VALUE</code>
|
* @return Code for weather of the city if available, otherwise
|
||||||
|
* <code>Integer.MIN_VALUE</code>
|
||||||
*/
|
*/
|
||||||
public int getWeatherCode() {
|
public int getWeatherCode() {
|
||||||
return this.id;
|
return this.id;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns data for name for weather of the city.
|
* Returns data for name for weather of the city.
|
||||||
* @return Name for weather of the city if available,
|
* <p>
|
||||||
* otherwise <code>null</code>
|
* @return Name for weather of the city if available, otherwise
|
||||||
|
* <code>null</code>
|
||||||
*/
|
*/
|
||||||
public String getWeatherName() {
|
public String getWeatherName() {
|
||||||
return this.name;
|
return this.name;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns data for description for weather of the city.
|
* Returns data for description for weather of the city.
|
||||||
* @return Description for weather of the city if available,
|
* <p>
|
||||||
* otherwise <code>null</code>
|
* @return Description for weather of the city if available, otherwise
|
||||||
|
* <code>null</code>
|
||||||
*/
|
*/
|
||||||
public String getWeatherDescription() {
|
public String getWeatherDescription() {
|
||||||
return this.description;
|
return this.description;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns data for name of icon for weather of the city.
|
* Returns data for name of icon for weather of the city.
|
||||||
* @return Name of icon for weather of the city if available,
|
* <p>
|
||||||
* otherwise <code>null</code>
|
* @return Name of icon for weather of the city if available, otherwise
|
||||||
|
* <code>null</code>
|
||||||
*/
|
*/
|
||||||
public String getWeatherIconName() {
|
public String getWeatherIconName() {
|
||||||
return this.icon;
|
return this.icon;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This class provides default implementations for <code>Wind</code>.
|
* This class provides default implementations for <code>Wind</code>.
|
||||||
* Standard behaviors like the <code>has</code> and the <code>get</code>
|
* Standard behaviors like the <code>has</code> and the <code>get</code>
|
||||||
* methods for information about wind (for example, speed, degree,
|
* methods for information about wind (for example, speed, degree, etc.) are
|
||||||
* etc.) are defined here.
|
* defined here.
|
||||||
*
|
* <p>
|
||||||
* @author Ashutosh Kumar Singh
|
* @author Ashutosh Kumar Singh
|
||||||
* @version 2013/07/28
|
* @version 2013/07/28
|
||||||
* @since 2.5.0.1
|
* @since 2.5.0.1
|
||||||
*/
|
*/
|
||||||
abstract public static class Wind {
|
abstract public static class Wind {
|
||||||
/** Key for JSON variable <code>Wind -> Speed</code> */
|
|
||||||
|
/**
|
||||||
|
* Key for JSON variable <code>Wind -> Speed</code>
|
||||||
|
*/
|
||||||
private final String JSON_WIND_SPEED = "speed";
|
private final String JSON_WIND_SPEED = "speed";
|
||||||
/** Key for JSON variable <code>Wind -> Degree</code> */
|
/**
|
||||||
|
* Key for JSON variable <code>Wind -> Degree</code>
|
||||||
|
*/
|
||||||
private final String JSON_WIND_DEGREE = "deg";
|
private final String JSON_WIND_DEGREE = "deg";
|
||||||
|
|
||||||
/** Wind speed */
|
/**
|
||||||
|
* Wind speed
|
||||||
|
*/
|
||||||
private final float speed;
|
private final float speed;
|
||||||
/** Wind degree (direction of wind) */
|
/**
|
||||||
|
* Wind degree (direction of wind)
|
||||||
|
*/
|
||||||
private final float degree;
|
private final float degree;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Non-parameterized constructor
|
* Non-parameterized constructor
|
||||||
*
|
* <p>
|
||||||
* <p>Initializes variables as per following basis:<br>
|
* <p>
|
||||||
|
* Initializes variables as per following basis:<br>
|
||||||
* Boolean: <code>false</code><br>
|
* Boolean: <code>false</code><br>
|
||||||
* Integral: Minimum value (MIN_VALUE)<br>
|
* Integral: Minimum value (MIN_VALUE)<br>
|
||||||
* Floating point: Not a number (NaN)<br>
|
* Floating point: Not a number (NaN)<br>
|
||||||
|
@ -515,75 +625,82 @@ abstract public class AbstractWeatherData {
|
||||||
this.speed = Float.NaN;
|
this.speed = Float.NaN;
|
||||||
this.degree = Float.NaN;
|
this.degree = Float.NaN;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Parameterized constructor
|
* Parameterized constructor
|
||||||
*
|
* <p>
|
||||||
* Initializes variables from values from the given JSON object.
|
* Initializes variables from values from the given JSON object.
|
||||||
*
|
* <p>
|
||||||
* @param jsonObj JSON object containing data about wind
|
* @param jsonObj JSON object containing data about wind
|
||||||
*/
|
*/
|
||||||
public Wind(JSONObject jsonObj) {
|
public Wind(JSONObject jsonObj) {
|
||||||
this.speed = (float) jsonObj.optDouble(this.JSON_WIND_SPEED, Double.NaN);
|
this.speed = (float) jsonObj.optDouble(this.JSON_WIND_SPEED, Double.NaN);
|
||||||
this.degree = (float) jsonObj.optDouble(this.JSON_WIND_DEGREE, Double.NaN);
|
this.degree = (float) jsonObj.optDouble(this.JSON_WIND_DEGREE, Double.NaN);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tells if the data for speed of wind in the city is available or not.
|
* Tells if the data for speed of wind in the city is available or not.
|
||||||
* @return <code>true</code> if data available, otherwise <code>false</code>
|
* <p>
|
||||||
|
* @return <code>true</code> if data available, otherwise
|
||||||
|
* <code>false</code>
|
||||||
*/
|
*/
|
||||||
public boolean hasWindSpeed() {
|
public boolean hasWindSpeed() {
|
||||||
return (this.speed != Float.NaN);
|
return (this.speed != Float.NaN);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tells if the data for degree (degree gives direction) of wind
|
* Tells if the data for degree (degree gives direction) of wind in the
|
||||||
* in the city is available or not.
|
* city is available or not.
|
||||||
* @return <code>true</code> if data available, otherwise <code>false</code>
|
* <p>
|
||||||
|
* @return <code>true</code> if data available, otherwise
|
||||||
|
* <code>false</code>
|
||||||
*/
|
*/
|
||||||
public boolean hasWindDegree() {
|
public boolean hasWindDegree() {
|
||||||
return (this.hasWindSpeed() && (this.degree != Float.NaN));
|
return (this.hasWindSpeed() && (this.degree != Float.NaN));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns data for speed of wind in the city.
|
* Returns data for speed of wind in the city.
|
||||||
* @return Speed of wind in the city if available,
|
* <p>
|
||||||
* otherwise <code>Float.NaN</code>, i.e., Not a Number.
|
* @return Speed of wind in the city if available, otherwise
|
||||||
|
* <code>Float.NaN</code>, i.e., Not a Number.
|
||||||
*/
|
*/
|
||||||
public float getWindSpeed() {
|
public float getWindSpeed() {
|
||||||
return this.speed;
|
return this.speed;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns data for degree of wind in the city.
|
* Returns data for degree of wind in the city.
|
||||||
* @return Degree of wind in the city if available,
|
* <p>
|
||||||
* otherwise <code>Float.NaN</code>, i.e., Not a Number.
|
* @return Degree of wind in the city if available, otherwise
|
||||||
|
* <code>Float.NaN</code>, i.e., Not a Number.
|
||||||
*/
|
*/
|
||||||
public float getWindDegree() {
|
public float getWindDegree() {
|
||||||
return this.degree;
|
return this.degree;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
***********************
|
***********************
|
||||||
* Declaring this class
|
* Declaring this class
|
||||||
***********************
|
***********************
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/** Key for JSON variable Date-Time (date & time of the weather) */
|
|
||||||
private final String JSON_DATE_TIME = "dt";
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Date and time of the weather. This is answer for the question that
|
* Key for JSON variable Date-Time (date & time of the weather)
|
||||||
* when is/will be this weather.
|
*/
|
||||||
|
private final String JSON_DATE_TIME = "dt";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Date and time of the weather. This is answer for the question that when
|
||||||
|
* is/will be this weather.
|
||||||
*/
|
*/
|
||||||
private final Date dateTime;
|
private final Date dateTime;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Non-parameterized constructor
|
* Non-parameterized constructor
|
||||||
*
|
* <p>
|
||||||
* <p>Initializes variables as per following basis:<br>
|
* <p>
|
||||||
|
* Initializes variables as per following basis:<br>
|
||||||
* Boolean: <code>false</code><br>
|
* Boolean: <code>false</code><br>
|
||||||
* Integral: Minimum value (MIN_VALUE)<br>
|
* Integral: Minimum value (MIN_VALUE)<br>
|
||||||
* Floating point: Not a number (NaN)<br>
|
* Floating point: Not a number (NaN)<br>
|
||||||
|
@ -592,45 +709,47 @@ abstract public class AbstractWeatherData {
|
||||||
public AbstractWeatherData() {
|
public AbstractWeatherData() {
|
||||||
this.dateTime = null;
|
this.dateTime = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Parameterized constructor
|
* Parameterized constructor
|
||||||
*
|
* <p>
|
||||||
* Initializes variables from values from the given JSON object.
|
* Initializes variables from values from the given JSON object.
|
||||||
*
|
* <p>
|
||||||
* @param jsonObj JSON object containing weather data
|
* @param jsonObj JSON object containing weather data
|
||||||
*/
|
*/
|
||||||
public AbstractWeatherData(JSONObject jsonObj) {
|
public AbstractWeatherData(JSONObject jsonObj) {
|
||||||
// getting seconds from the data
|
// getting seconds from the data
|
||||||
long sec = (jsonObj != null) ? jsonObj.optLong(this.JSON_DATE_TIME, Long.MIN_VALUE) : Long.MIN_VALUE;
|
long sec = (jsonObj != null) ? jsonObj.optLong(this.JSON_DATE_TIME, Long.MIN_VALUE) : Long.MIN_VALUE;
|
||||||
|
|
||||||
// converting seconds to Date object
|
// converting seconds to Date object
|
||||||
if (sec != Long.MIN_VALUE) {
|
if (sec != Long.MIN_VALUE) {
|
||||||
/*
|
/*
|
||||||
@bugfix It always return "Sat Jan 17 04:10:42 CET 1970"
|
@bugfix It always return "Sat Jan 17 04:10:42 CET 1970"
|
||||||
Issue: #3 given at http://code.aksingh.net/owm-japis/issue/3/problem-with-datetime
|
Issue: #3 given at http://code.aksingh.net/owm-japis/issue/3/problem-with-datetime
|
||||||
Incorrect: this.dateTime = new Date(sec);
|
Incorrect: this.dateTime = new Date(sec);
|
||||||
Correct: this.dateTime = new Date(sec * 1000);
|
Correct: this.dateTime = new Date(sec * 1000);
|
||||||
Reason: Date requires milliseconds but previously, seconds were provided.
|
Reason: Date requires milliseconds but previously, seconds were provided.
|
||||||
*/
|
*/
|
||||||
this.dateTime = new Date(sec * 1000);
|
this.dateTime = new Date(sec * 1000);
|
||||||
} else {
|
} else {
|
||||||
this.dateTime = null;
|
this.dateTime = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tells if the data for date and time of this weather is available or not.
|
* Tells if the data for date and time of this weather is available or not.
|
||||||
|
* <p>
|
||||||
* @return <code>true</code> if data available, otherwise <code>false</code>
|
* @return <code>true</code> if data available, otherwise <code>false</code>
|
||||||
*/
|
*/
|
||||||
public boolean hasDateTime() {
|
public boolean hasDateTime() {
|
||||||
return (this.dateTime != null);
|
return (this.dateTime != null);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns data for date and time of this weather.
|
* Returns data for date and time of this weather.
|
||||||
* @return Date and time (in object of {@link java.util.Date}) if available,
|
* <p>
|
||||||
* otherwise <code>null</code>
|
* @return Date and time (in object of {@link java.util.Date}) if available,
|
||||||
|
* otherwise <code>null</code>
|
||||||
*/
|
*/
|
||||||
public Date getDateTime() {
|
public Date getDateTime() {
|
||||||
return this.dateTime;
|
return this.dateTime;
|
||||||
|
|
|
@ -29,68 +29,73 @@ import org.json.JSONArray;
|
||||||
import org.json.JSONObject;
|
import org.json.JSONObject;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Parses current weather data (from the JSON data) and provides methods
|
* Parses current weather data (from the JSON data) and provides methods to
|
||||||
* to get/access the information about current weather.
|
* get/access the information about current weather. This class provides
|
||||||
* This class provides <code>has</code> and <code>get</code> methods
|
* <code>has</code> and <code>get</code> methods to access the information.
|
||||||
* to access the information.
|
* <p>
|
||||||
*
|
* <p>
|
||||||
* <p><code>has</code> methods can be used to check
|
* <code>has</code> methods can be used to check if the data exists, i.e., if
|
||||||
* if the data exists, i.e., if the data was available (successfully
|
* the data was available (successfully downloaded) and was parsed correctly.
|
||||||
* downloaded) and was parsed correctly.
|
* <p>
|
||||||
*
|
* <p>
|
||||||
* <p><code>get</code> methods can be used to access the data, if the data
|
* <code>get</code> methods can be used to access the data, if the data exists,
|
||||||
* exists, otherwise <code>get</code> methods will give value as per
|
* otherwise <code>get</code> methods will give value as per following
|
||||||
* following basis:<br>
|
* basis:<br>
|
||||||
* Boolean: <code>false</code><br>
|
* Boolean: <code>false</code><br>
|
||||||
* Integral: Minimum value (MIN_VALUE)<br>
|
* Integral: Minimum value (MIN_VALUE)<br>
|
||||||
* Floating point: Not a number (NaN)<br>
|
* Floating point: Not a number (NaN)<br>
|
||||||
* Others: <code>null</code><br>
|
* Others: <code>null</code><br>
|
||||||
*
|
* <p>
|
||||||
* @author Ashutosh Kumar Singh
|
* @author Ashutosh Kumar Singh
|
||||||
* @version 2013/08/07
|
* @version 2013/08/07
|
||||||
* @since 2.5.0.1
|
* @since 2.5.0.1
|
||||||
*/
|
*/
|
||||||
public class CurrentWeatherData extends AbstractWeatherData {
|
public class CurrentWeatherData extends AbstractWeatherData {
|
||||||
/** Key for JSON object - Rain */
|
|
||||||
|
/**
|
||||||
|
* Key for JSON object - Rain
|
||||||
|
*/
|
||||||
private final String JSON_RAIN = "rain";
|
private final String JSON_RAIN = "rain";
|
||||||
/** Key for JSON object - Sys */
|
/**
|
||||||
|
* Key for JSON object - Sys
|
||||||
|
*/
|
||||||
private final String JSON_SYS = "sys";
|
private final String JSON_SYS = "sys";
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
************************
|
************************
|
||||||
* Declaring sub-classes
|
* Declaring sub-classes
|
||||||
************************
|
************************
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Parses data about clouds (from the JSON data) and provides methods
|
* Parses data about clouds (from the JSON data) and provides methods to
|
||||||
* to get/access the information.
|
* get/access the information. This class provides <code>has</code> and
|
||||||
* This class provides <code>has</code> and <code>get</code> methods
|
* <code>get</code> methods to access the information.
|
||||||
* to access the information.
|
* <p>
|
||||||
*
|
* <p>
|
||||||
* <p><code>has</code> methods can be used to check
|
* <code>has</code> methods can be used to check if the data exists, i.e.,
|
||||||
* if the data exists, i.e., if the data was available (successfully
|
* if the data was available (successfully downloaded) and was parsed
|
||||||
* downloaded) and was parsed correctly.
|
* correctly.
|
||||||
*
|
* <p>
|
||||||
* <p><code>get</code> methods can be used to access the data, if the data
|
* <p>
|
||||||
* exists, otherwise <code>get</code> methods will give value as per
|
* <code>get</code> methods can be used to access the data, if the data
|
||||||
|
* exists, otherwise <code>get</code> methods will give value as per
|
||||||
* following basis:<br>
|
* following basis:<br>
|
||||||
* Boolean: <code>false</code><br>
|
* Boolean: <code>false</code><br>
|
||||||
* Integral: Minimum value (MIN_VALUE)<br>
|
* Integral: Minimum value (MIN_VALUE)<br>
|
||||||
* Floating point: Not a number (NaN)<br>
|
* Floating point: Not a number (NaN)<br>
|
||||||
* Others: <code>null</code><br>
|
* Others: <code>null</code><br>
|
||||||
*
|
* <p>
|
||||||
* @author Ashutosh Kumar Singh
|
* @author Ashutosh Kumar Singh
|
||||||
* @version 2013/08/07
|
* @version 2013/08/07
|
||||||
* @since 2.5.0.1
|
* @since 2.5.0.1
|
||||||
*/
|
*/
|
||||||
public static class Clouds extends AbstractWeatherData.Clouds {
|
public static class Clouds extends AbstractWeatherData.Clouds {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Non-parameterized constructor
|
* Non-parameterized constructor
|
||||||
*
|
* <p>
|
||||||
* <p>Initializes variables as per following basis:<br>
|
* <p>
|
||||||
|
* Initializes variables as per following basis:<br>
|
||||||
* Boolean: <code>false</code><br>
|
* Boolean: <code>false</code><br>
|
||||||
* Integral: Minimum value (MIN_VALUE)<br>
|
* Integral: Minimum value (MIN_VALUE)<br>
|
||||||
* Floating point: Not a number (NaN)<br>
|
* Floating point: Not a number (NaN)<br>
|
||||||
|
@ -99,48 +104,49 @@ public class CurrentWeatherData extends AbstractWeatherData {
|
||||||
public Clouds() {
|
public Clouds() {
|
||||||
super();
|
super();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Parameterized constructor
|
* Parameterized constructor
|
||||||
*
|
* <p>
|
||||||
* Initializes variables from values from the given JSON object.
|
* Initializes variables from values from the given JSON object.
|
||||||
*
|
* <p>
|
||||||
* @param jsonObj JSON object containing data about clouds
|
* @param jsonObj JSON object containing data about clouds
|
||||||
*/
|
*/
|
||||||
public Clouds(JSONObject jsonObj) {
|
public Clouds(JSONObject jsonObj) {
|
||||||
super(jsonObj);
|
super(jsonObj);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Parses data about geographic coordinates (from the JSON data)
|
* Parses data about geographic coordinates (from the JSON data) and
|
||||||
* and provides methods to get/access the information.
|
* provides methods to get/access the information. This class provides
|
||||||
* This class provides <code>has</code> and <code>get</code> methods
|
* <code>has</code> and <code>get</code> methods to access the information.
|
||||||
* to access the information.
|
* <p>
|
||||||
*
|
* <p>
|
||||||
* <p><code>has</code> methods can be used to check
|
* <code>has</code> methods can be used to check if the data exists, i.e.,
|
||||||
* if the data exists, i.e., if the data was available (successfully
|
* if the data was available (successfully downloaded) and was parsed
|
||||||
* downloaded) and was parsed correctly.
|
* correctly.
|
||||||
*
|
* <p>
|
||||||
* <p><code>get</code> methods can be used to access the data, if the data
|
* <p>
|
||||||
* exists, otherwise <code>get</code> methods will give value as per
|
* <code>get</code> methods can be used to access the data, if the data
|
||||||
|
* exists, otherwise <code>get</code> methods will give value as per
|
||||||
* following basis:<br>
|
* following basis:<br>
|
||||||
* Boolean: <code>false</code><br>
|
* Boolean: <code>false</code><br>
|
||||||
* Integral: Minimum value (MIN_VALUE)<br>
|
* Integral: Minimum value (MIN_VALUE)<br>
|
||||||
* Floating point: Not a number (NaN)<br>
|
* Floating point: Not a number (NaN)<br>
|
||||||
* Others: <code>null</code><br>
|
* Others: <code>null</code><br>
|
||||||
*
|
* <p>
|
||||||
* @author Ashutosh Kumar Singh
|
* @author Ashutosh Kumar Singh
|
||||||
* @version 2013/08/07
|
* @version 2013/08/07
|
||||||
* @since 2.5.0.1
|
* @since 2.5.0.1
|
||||||
*/
|
*/
|
||||||
public static class Coord extends AbstractWeatherData.Coord {
|
public static class Coord extends AbstractWeatherData.Coord {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Non-parameterized constructor
|
* Non-parameterized constructor
|
||||||
*
|
* <p>
|
||||||
* <p>Initializes variables as per following basis:<br>
|
* <p>
|
||||||
|
* Initializes variables as per following basis:<br>
|
||||||
* Boolean: <code>false</code><br>
|
* Boolean: <code>false</code><br>
|
||||||
* Integral: Minimum value (MIN_VALUE)<br>
|
* Integral: Minimum value (MIN_VALUE)<br>
|
||||||
* Floating point: Not a number (NaN)<br>
|
* Floating point: Not a number (NaN)<br>
|
||||||
|
@ -149,48 +155,49 @@ public class CurrentWeatherData extends AbstractWeatherData {
|
||||||
public Coord() {
|
public Coord() {
|
||||||
super();
|
super();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Parameterized constructor
|
* Parameterized constructor
|
||||||
*
|
* <p>
|
||||||
* Initializes variables from values from the given JSON object.
|
* Initializes variables from values from the given JSON object.
|
||||||
*
|
* <p>
|
||||||
* @param jsonObj JSON object containing data about coordinates
|
* @param jsonObj JSON object containing data about coordinates
|
||||||
*/
|
*/
|
||||||
public Coord(JSONObject jsonObj) {
|
public Coord(JSONObject jsonObj) {
|
||||||
super(jsonObj);
|
super(jsonObj);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Parses data about main weather elements (from the JSON data) and
|
* Parses data about main weather elements (from the JSON data) and provides
|
||||||
* provides methods to get/access the information.
|
* methods to get/access the information. This class provides
|
||||||
* This class provides <code>has</code> and <code>get</code> methods
|
* <code>has</code> and <code>get</code> methods to access the information.
|
||||||
* to access the information.
|
* <p>
|
||||||
*
|
* <p>
|
||||||
* <p><code>has</code> methods can be used to check
|
* <code>has</code> methods can be used to check if the data exists, i.e.,
|
||||||
* if the data exists, i.e., if the data was available (successfully
|
* if the data was available (successfully downloaded) and was parsed
|
||||||
* downloaded) and was parsed correctly.
|
* correctly.
|
||||||
*
|
* <p>
|
||||||
* <p><code>get</code> methods can be used to access the data, if the data
|
* <p>
|
||||||
* exists, otherwise <code>get</code> methods will give value as per
|
* <code>get</code> methods can be used to access the data, if the data
|
||||||
|
* exists, otherwise <code>get</code> methods will give value as per
|
||||||
* following basis:<br>
|
* following basis:<br>
|
||||||
* Boolean: <code>false</code><br>
|
* Boolean: <code>false</code><br>
|
||||||
* Integral: Minimum value (MIN_VALUE)<br>
|
* Integral: Minimum value (MIN_VALUE)<br>
|
||||||
* Floating point: Not a number (NaN)<br>
|
* Floating point: Not a number (NaN)<br>
|
||||||
* Others: <code>null</code><br>
|
* Others: <code>null</code><br>
|
||||||
*
|
* <p>
|
||||||
* @author Ashutosh Kumar Singh
|
* @author Ashutosh Kumar Singh
|
||||||
* @version 2013/08/07
|
* @version 2013/08/07
|
||||||
* @since 2.5.0.1
|
* @since 2.5.0.1
|
||||||
*/
|
*/
|
||||||
public static class Main extends AbstractWeatherData.Main {
|
public static class Main extends AbstractWeatherData.Main {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Non-parameterized constructor
|
* Non-parameterized constructor
|
||||||
*
|
* <p>
|
||||||
* <p>Initializes variables as per following basis:<br>
|
* <p>
|
||||||
|
* Initializes variables as per following basis:<br>
|
||||||
* Boolean: <code>false</code><br>
|
* Boolean: <code>false</code><br>
|
||||||
* Integral: Minimum value (MIN_VALUE)<br>
|
* Integral: Minimum value (MIN_VALUE)<br>
|
||||||
* Floating point: Not a number (NaN)<br>
|
* Floating point: Not a number (NaN)<br>
|
||||||
|
@ -199,54 +206,60 @@ public class CurrentWeatherData extends AbstractWeatherData {
|
||||||
public Main() {
|
public Main() {
|
||||||
super();
|
super();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Parameterized constructor
|
* Parameterized constructor
|
||||||
*
|
* <p>
|
||||||
* Initializes variables from values from the given JSON object.
|
* Initializes variables from values from the given JSON object.
|
||||||
*
|
* <p>
|
||||||
* @param jsonObj JSON object containing data about main
|
* @param jsonObj JSON object containing data about main weather
|
||||||
* weather elements (temperature, pressure, etc.)
|
* elements (temperature, pressure, etc.)
|
||||||
*/
|
*/
|
||||||
public Main(JSONObject jsonObj) {
|
public Main(JSONObject jsonObj) {
|
||||||
super(jsonObj);
|
super(jsonObj);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Parses data about rain (from the JSON data) and provides methods
|
* Parses data about rain (from the JSON data) and provides methods to
|
||||||
* to get/access the information.
|
* get/access the information. This class provides <code>has</code> and
|
||||||
* This class provides <code>has</code> and <code>get</code> methods
|
* <code>get</code> methods to access the information.
|
||||||
* to access the information.
|
* <p>
|
||||||
*
|
* <p>
|
||||||
* <p><code>has</code> methods can be used to check
|
* <code>has</code> methods can be used to check if the data exists, i.e.,
|
||||||
* if the data exists, i.e., if the data was available (successfully
|
* if the data was available (successfully downloaded) and was parsed
|
||||||
* downloaded) and was parsed correctly.
|
* correctly.
|
||||||
*
|
* <p>
|
||||||
* <p><code>get</code> methods can be used to access the data, if the data
|
* <p>
|
||||||
* exists, otherwise <code>get</code> methods will give value as per
|
* <code>get</code> methods can be used to access the data, if the data
|
||||||
|
* exists, otherwise <code>get</code> methods will give value as per
|
||||||
* following basis:<br>
|
* following basis:<br>
|
||||||
* Boolean: <code>false</code><br>
|
* Boolean: <code>false</code><br>
|
||||||
* Integral: Minimum value (MIN_VALUE)<br>
|
* Integral: Minimum value (MIN_VALUE)<br>
|
||||||
* Floating point: Not a number (NaN)<br>
|
* Floating point: Not a number (NaN)<br>
|
||||||
* Others: <code>null</code><br>
|
* Others: <code>null</code><br>
|
||||||
*
|
* <p>
|
||||||
* @author Ashutosh Kumar Singh
|
* @author Ashutosh Kumar Singh
|
||||||
* @version 2013/08/07
|
* @version 2013/08/07
|
||||||
* @since 2.5.0.1
|
* @since 2.5.0.1
|
||||||
*/
|
*/
|
||||||
public static class Rain {
|
public static class Rain {
|
||||||
/** Key for JSON variable <code>Rain -> Rain per 3 hours</code> */
|
|
||||||
|
/**
|
||||||
|
* Key for JSON variable <code>Rain -> Rain per 3 hours</code>
|
||||||
|
*/
|
||||||
private final String JSON_RAIN_3HOURS = "3h";
|
private final String JSON_RAIN_3HOURS = "3h";
|
||||||
|
|
||||||
/** Rain per 3 hours */
|
/**
|
||||||
|
* Rain per 3 hours
|
||||||
|
*/
|
||||||
private final float rain3h;
|
private final float rain3h;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Non-parameterized constructor
|
* Non-parameterized constructor
|
||||||
*
|
* <p>
|
||||||
* <p>Initializes variables as per following basis:<br>
|
* <p>
|
||||||
|
* Initializes variables as per following basis:<br>
|
||||||
* Boolean: <code>false</code><br>
|
* Boolean: <code>false</code><br>
|
||||||
* Integral: Minimum value (MIN_VALUE)<br>
|
* Integral: Minimum value (MIN_VALUE)<br>
|
||||||
* Floating point: Not a number (NaN)<br>
|
* Floating point: Not a number (NaN)<br>
|
||||||
|
@ -255,69 +268,83 @@ public class CurrentWeatherData extends AbstractWeatherData {
|
||||||
public Rain() {
|
public Rain() {
|
||||||
this.rain3h = Float.NaN;
|
this.rain3h = Float.NaN;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Parameterized constructor
|
* Parameterized constructor
|
||||||
*
|
* <p>
|
||||||
* Initializes variables from values from the given JSON object.
|
* Initializes variables from values from the given JSON object.
|
||||||
*
|
* <p>
|
||||||
* @param jsonObj JSON object containing data about rain
|
* @param jsonObj JSON object containing data about rain
|
||||||
*/
|
*/
|
||||||
public Rain(JSONObject jsonObj) {
|
public Rain(JSONObject jsonObj) {
|
||||||
this.rain3h = (float) jsonObj.optDouble(this.JSON_RAIN_3HOURS, Double.NaN);
|
this.rain3h = (float) jsonObj.optDouble(this.JSON_RAIN_3HOURS, Double.NaN);
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean hasRain3Hours() {
|
public boolean hasRain3Hours() {
|
||||||
return (this.rain3h != Float.NaN);
|
return (this.rain3h != Float.NaN);
|
||||||
}
|
}
|
||||||
|
|
||||||
public float getRain3Hours() {
|
public float getRain3Hours() {
|
||||||
return this.rain3h;
|
return this.rain3h;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Parses data about country, sunrise, and sunset (from the JSON data)
|
* Parses data about country, sunrise, and sunset (from the JSON data) and
|
||||||
* and provides methods to get/access the information.
|
* provides methods to get/access the information. This class provides
|
||||||
* This class provides <code>has</code> and <code>get</code> methods
|
* <code>has</code> and <code>get</code> methods to access the information.
|
||||||
* to access the information.
|
* <p>
|
||||||
*
|
* <p>
|
||||||
* <p><code>has</code> methods can be used to check
|
* <code>has</code> methods can be used to check if the data exists, i.e.,
|
||||||
* if the data exists, i.e., if the data was available (successfully
|
* if the data was available (successfully downloaded) and was parsed
|
||||||
* downloaded) and was parsed correctly.
|
* correctly.
|
||||||
*
|
* <p>
|
||||||
* <p><code>get</code> methods can be used to access the data, if the data
|
* <p>
|
||||||
* exists, otherwise <code>get</code> methods will give value as per
|
* <code>get</code> methods can be used to access the data, if the data
|
||||||
|
* exists, otherwise <code>get</code> methods will give value as per
|
||||||
* following basis:<br>
|
* following basis:<br>
|
||||||
* Boolean: <code>false</code><br>
|
* Boolean: <code>false</code><br>
|
||||||
* Integral: Minimum value (MIN_VALUE)<br>
|
* Integral: Minimum value (MIN_VALUE)<br>
|
||||||
* Floating point: Not a number (NaN)<br>
|
* Floating point: Not a number (NaN)<br>
|
||||||
* Others: <code>null</code><br>
|
* Others: <code>null</code><br>
|
||||||
*
|
* <p>
|
||||||
* @author Ashutosh Kumar Singh
|
* @author Ashutosh Kumar Singh
|
||||||
* @version 2013/08/07
|
* @version 2013/08/07
|
||||||
* @since 2.5.0.1
|
* @since 2.5.0.1
|
||||||
*/
|
*/
|
||||||
public static class Sys {
|
public static class Sys {
|
||||||
/** Key for JSON variable <code>Sys -> Country</code> */
|
|
||||||
|
/**
|
||||||
|
* Key for JSON variable <code>Sys -> Country</code>
|
||||||
|
*/
|
||||||
private final String JSON_SYS_COUNTRY_CODE = "country";
|
private final String JSON_SYS_COUNTRY_CODE = "country";
|
||||||
/** Key for JSON variable <code>Sys -> Sunrise</code> */
|
/**
|
||||||
|
* Key for JSON variable <code>Sys -> Sunrise</code>
|
||||||
|
*/
|
||||||
private final String JSON_SYS_SUNRISE = "sunrise";
|
private final String JSON_SYS_SUNRISE = "sunrise";
|
||||||
/** Key for JSON variable <code>Sys -> Sunset</code> */
|
/**
|
||||||
|
* Key for JSON variable <code>Sys -> Sunset</code>
|
||||||
|
*/
|
||||||
private final String JSON_SYS_SUNSET = "sunset";
|
private final String JSON_SYS_SUNSET = "sunset";
|
||||||
|
|
||||||
/** Country code for the city */
|
/**
|
||||||
|
* Country code for the city
|
||||||
|
*/
|
||||||
private final String countryCode;
|
private final String countryCode;
|
||||||
/** Sunrise time */
|
/**
|
||||||
|
* Sunrise time
|
||||||
|
*/
|
||||||
private final Date sunrise;
|
private final Date sunrise;
|
||||||
/** Sunset time */
|
/**
|
||||||
|
* Sunset time
|
||||||
|
*/
|
||||||
private final Date sunset;
|
private final Date sunset;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Non-parameterized constructor
|
* Non-parameterized constructor
|
||||||
*
|
* <p>
|
||||||
* <p>Initializes variables as per following basis:<br>
|
* <p>
|
||||||
|
* Initializes variables as per following basis:<br>
|
||||||
* Boolean: <code>false</code><br>
|
* Boolean: <code>false</code><br>
|
||||||
* Integral: Minimum value (MIN_VALUE)<br>
|
* Integral: Minimum value (MIN_VALUE)<br>
|
||||||
* Floating point: Not a number (NaN)<br>
|
* Floating point: Not a number (NaN)<br>
|
||||||
|
@ -328,326 +355,364 @@ public class CurrentWeatherData extends AbstractWeatherData {
|
||||||
this.sunrise = null;
|
this.sunrise = null;
|
||||||
this.sunset = null;
|
this.sunset = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Parameterized constructor
|
* Parameterized constructor
|
||||||
*
|
* <p>
|
||||||
* Initializes variables from values from the given JSON object.
|
* Initializes variables from values from the given JSON object.
|
||||||
*
|
* <p>
|
||||||
* @param jsonObj JSON object containing data about country, sunrise,
|
* @param jsonObj JSON object containing data about country, sunrise,
|
||||||
* and sunset.
|
* and sunset.
|
||||||
*/
|
*/
|
||||||
public Sys(JSONObject jsonObj) {
|
public Sys(JSONObject jsonObj) {
|
||||||
this.countryCode = jsonObj.optString(this.JSON_SYS_COUNTRY_CODE, null);
|
this.countryCode = jsonObj.optString(this.JSON_SYS_COUNTRY_CODE, null);
|
||||||
|
|
||||||
long sr_secs = jsonObj.optLong(this.JSON_SYS_SUNRISE, Long.MIN_VALUE);
|
long sr_secs = jsonObj.optLong(this.JSON_SYS_SUNRISE, Long.MIN_VALUE);
|
||||||
if (sr_secs != Long.MIN_VALUE) {
|
if (sr_secs != Long.MIN_VALUE) {
|
||||||
this.sunrise = new Date(sr_secs);
|
/*
|
||||||
|
@bugfix Incorrect date and time
|
||||||
|
Issue: #3 given at http://code.aksingh.net/owm-japis/issue/3/problem-with-datetime
|
||||||
|
Incorrect: this.sunrise = new Date(sr_secs);
|
||||||
|
Correct: this.sunrise = new Date(sr_secs * 1000);
|
||||||
|
Reason: Date requires milliseconds but previously, seconds were provided.
|
||||||
|
*/
|
||||||
|
this.sunrise = new Date(sr_secs * 1000);
|
||||||
} else {
|
} else {
|
||||||
this.sunrise = null;
|
this.sunrise = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
long ss_secs = jsonObj.optLong(this.JSON_SYS_SUNSET, Long.MIN_VALUE);
|
long ss_secs = jsonObj.optLong(this.JSON_SYS_SUNSET, Long.MIN_VALUE);
|
||||||
if (ss_secs != Long.MIN_VALUE) {
|
if (ss_secs != Long.MIN_VALUE) {
|
||||||
this.sunset = new Date(ss_secs);
|
/*
|
||||||
|
@bugfix Incorrect date and time
|
||||||
|
Issue: #3 given at http://code.aksingh.net/owm-japis/issue/3/problem-with-datetime
|
||||||
|
Incorrect: this.sunrise = new Date(ss_secs);
|
||||||
|
Correct: this.sunrise = new Date(ss_secs * 1000);
|
||||||
|
Reason: Date requires milliseconds but previously, seconds were provided.
|
||||||
|
*/
|
||||||
|
this.sunset = new Date(ss_secs * 1000);
|
||||||
} else {
|
} else {
|
||||||
this.sunset = null;
|
this.sunset = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean hasCountryCode() {
|
public boolean hasCountryCode() {
|
||||||
return (this.countryCode != null);
|
return (this.countryCode != null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean hasSunriseTime() {
|
public boolean hasSunriseTime() {
|
||||||
return (this.sunrise != null);
|
return (this.sunrise != null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean hasSunsetTime() {
|
public boolean hasSunsetTime() {
|
||||||
return (this.sunset != null);
|
return (this.sunset != null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getCountryCode() {
|
public String getCountryCode() {
|
||||||
return this.countryCode;
|
return this.countryCode;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Date getSunriseTime() {
|
public Date getSunriseTime() {
|
||||||
return this.sunrise;
|
return this.sunrise;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Date getSunsetTime() {
|
public Date getSunsetTime() {
|
||||||
return this.sunset;
|
return this.sunset;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Parses data about weather code, name, etc. (from the JSON data)
|
* Parses data about weather code, name, etc. (from the JSON data) and
|
||||||
* and provides methods to get/access the information.
|
* provides methods to get/access the information. This class provides
|
||||||
* This class provides <code>has</code> and <code>get</code> methods
|
* <code>has</code> and <code>get</code> methods to access the information.
|
||||||
* to access the information.
|
* <p>
|
||||||
*
|
* <p>
|
||||||
* <p><code>has</code> methods can be used to check
|
* <code>has</code> methods can be used to check if the data exists, i.e.,
|
||||||
* if the data exists, i.e., if the data was available (successfully
|
* if the data was available (successfully downloaded) and was parsed
|
||||||
* downloaded) and was parsed correctly.
|
* correctly.
|
||||||
*
|
* <p>
|
||||||
* <p><code>get</code> methods can be used to access the data, if the data
|
* <p>
|
||||||
* exists, otherwise <code>get</code> methods will give value as per
|
* <code>get</code> methods can be used to access the data, if the data
|
||||||
|
* exists, otherwise <code>get</code> methods will give value as per
|
||||||
* following basis:<br>
|
* following basis:<br>
|
||||||
* Boolean: <code>false</code><br>
|
* Boolean: <code>false</code><br>
|
||||||
* Integral: Minimum value (MIN_VALUE)<br>
|
* Integral: Minimum value (MIN_VALUE)<br>
|
||||||
* Floating point: Not a number (NaN)<br>
|
* Floating point: Not a number (NaN)<br>
|
||||||
* Others: <code>null</code><br>
|
* Others: <code>null</code><br>
|
||||||
*
|
* <p>
|
||||||
* @author Ashutosh Kumar Singh
|
* @author Ashutosh Kumar Singh
|
||||||
* @version 2013/08/07
|
* @version 2013/08/07
|
||||||
* @since 2.5.0.1
|
* @since 2.5.0.1
|
||||||
*/
|
*/
|
||||||
public static class Weather extends AbstractWeatherData.Weather {
|
public static class Weather extends AbstractWeatherData.Weather {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Non-parameterized constructor
|
* Non-parameterized constructor
|
||||||
*
|
* <p>
|
||||||
* <p>Initializes variables as per following basis:<br>
|
* <p>
|
||||||
|
* Initializes variables as per following basis:<br>
|
||||||
* Boolean: <code>false</code><br>
|
* Boolean: <code>false</code><br>
|
||||||
* Integral: Minimum value (MIN_VALUE)<br>
|
* Integral: Minimum value (MIN_VALUE)<br>
|
||||||
* Floating point: Not a number (NaN)<br>
|
* Floating point: Not a number (NaN)<br>
|
||||||
* Others: <code>null</code><br>
|
* Others: <code>null</code><br>
|
||||||
*/
|
*/
|
||||||
public Weather () {
|
public Weather() {
|
||||||
super();
|
super();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Parameterized constructor
|
* Parameterized constructor
|
||||||
*
|
* <p>
|
||||||
* Initializes variables from values from the given JSON object.
|
* Initializes variables from values from the given JSON object.
|
||||||
*
|
* <p>
|
||||||
* @param jsonObj JSON object containing data about weather id, name, etc.
|
* @param jsonObj JSON object containing data about weather id, name,
|
||||||
|
* etc.
|
||||||
*/
|
*/
|
||||||
public Weather (JSONObject jsonObj) {
|
public Weather(JSONObject jsonObj) {
|
||||||
super(jsonObj);
|
super(jsonObj);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Parses data about winds (from the JSON data) and provides methods
|
* Parses data about winds (from the JSON data) and provides methods to
|
||||||
* to get/access the information.
|
* get/access the information. This class provides <code>has</code> and
|
||||||
* This class provides <code>has</code> and <code>get</code> methods
|
* <code>get</code> methods to access the information.
|
||||||
* to access the information.
|
* <p>
|
||||||
*
|
* <p>
|
||||||
* <p><code>has</code> methods can be used to check
|
* <code>has</code> methods can be used to check if the data exists, i.e.,
|
||||||
* if the data exists, i.e., if the data was available (successfully
|
* if the data was available (successfully downloaded) and was parsed
|
||||||
* downloaded) and was parsed correctly.
|
* correctly.
|
||||||
*
|
* <p>
|
||||||
* <p><code>get</code> methods can be used to access the data, if the data
|
* <p>
|
||||||
* exists, otherwise <code>get</code> methods will give value as per
|
* <code>get</code> methods can be used to access the data, if the data
|
||||||
|
* exists, otherwise <code>get</code> methods will give value as per
|
||||||
* following basis:<br>
|
* following basis:<br>
|
||||||
* Boolean: <code>false</code><br>
|
* Boolean: <code>false</code><br>
|
||||||
* Integral: Minimum value (MIN_VALUE)<br>
|
* Integral: Minimum value (MIN_VALUE)<br>
|
||||||
* Floating point: Not a number (NaN)<br>
|
* Floating point: Not a number (NaN)<br>
|
||||||
* Others: <code>null</code><br>
|
* Others: <code>null</code><br>
|
||||||
*
|
* <p>
|
||||||
* @author Ashutosh Kumar Singh
|
* @author Ashutosh Kumar Singh
|
||||||
* @version 2013/08/07
|
* @version 2013/08/07
|
||||||
* @since 2.5.0.1
|
* @since 2.5.0.1
|
||||||
*/
|
*/
|
||||||
public static class Wind extends AbstractWeatherData.Wind {
|
public static class Wind extends AbstractWeatherData.Wind {
|
||||||
/** Key for JSON variable <code>Wind -> Gust</code> */
|
|
||||||
|
/**
|
||||||
|
* Key for JSON variable <code>Wind -> Gust</code>
|
||||||
|
*/
|
||||||
private final String JSON_WIND_GUST = "gust";
|
private final String JSON_WIND_GUST = "gust";
|
||||||
|
|
||||||
/** Wind gust */
|
/**
|
||||||
|
* Wind gust
|
||||||
|
*/
|
||||||
private final float gust;
|
private final float gust;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Non-parameterized constructor
|
* Non-parameterized constructor
|
||||||
*
|
* <p>
|
||||||
* <p>Initializes variables as per following basis:<br>
|
* <p>
|
||||||
|
* Initializes variables as per following basis:<br>
|
||||||
* Boolean: <code>false</code><br>
|
* Boolean: <code>false</code><br>
|
||||||
* Integral: Minimum value (MIN_VALUE)<br>
|
* Integral: Minimum value (MIN_VALUE)<br>
|
||||||
* Floating point: Not a number (NaN)<br>
|
* Floating point: Not a number (NaN)<br>
|
||||||
* Others: <code>null</code><br>
|
* Others: <code>null</code><br>
|
||||||
*/
|
*/
|
||||||
public Wind () {
|
public Wind() {
|
||||||
super ();
|
super();
|
||||||
|
|
||||||
this.gust = Float.NaN;
|
this.gust = Float.NaN;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Parameterized constructor
|
* Parameterized constructor
|
||||||
*
|
* <p>
|
||||||
* Initializes variables from values from the given JSON object.
|
* Initializes variables from values from the given JSON object.
|
||||||
*
|
* <p>
|
||||||
* @param jsonObj JSON object containing data about wind
|
* @param jsonObj JSON object containing data about wind
|
||||||
*/
|
*/
|
||||||
public Wind (JSONObject jsonObj) {
|
public Wind(JSONObject jsonObj) {
|
||||||
super (jsonObj);
|
super(jsonObj);
|
||||||
|
|
||||||
this.gust = (float) jsonObj.optDouble(this.JSON_WIND_GUST, Double.NaN);
|
this.gust = (float) jsonObj.optDouble(this.JSON_WIND_GUST, Double.NaN);
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean hasWindGust() {
|
public boolean hasWindGust() {
|
||||||
return (this.gust != Float.NaN);
|
return (this.gust != Float.NaN);
|
||||||
}
|
}
|
||||||
|
|
||||||
public float getWindGust() {
|
public float getWindGust() {
|
||||||
return this.gust;
|
return this.gust;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
***********************
|
***********************
|
||||||
* Declaring this class
|
* Declaring this class
|
||||||
***********************
|
***********************
|
||||||
*/
|
*/
|
||||||
|
/**
|
||||||
/** Key for JSON variable <code>Base</code> */
|
* Key for JSON variable <code>Base</code>
|
||||||
|
*/
|
||||||
private final String JSON_BASE = "base";
|
private final String JSON_BASE = "base";
|
||||||
/** Key for JSON variable <code>City code (ID)</code> */
|
/**
|
||||||
|
* Key for JSON variable <code>City code (ID)</code>
|
||||||
|
*/
|
||||||
private final String JSON_CITY_ID = "id";
|
private final String JSON_CITY_ID = "id";
|
||||||
/** Key for JSON variable <code>City name</code> */
|
/**
|
||||||
|
* Key for JSON variable <code>City name</code>
|
||||||
|
*/
|
||||||
private final String JSON_CITY_NAME = "name";
|
private final String JSON_CITY_NAME = "name";
|
||||||
/** Key for JSON variable <code>Response code</code> */
|
/**
|
||||||
|
* Key for JSON variable <code>Response code</code>
|
||||||
|
*/
|
||||||
private final String JSON_RESPONSE_CODE = "cod";
|
private final String JSON_RESPONSE_CODE = "cod";
|
||||||
|
|
||||||
/** Base */
|
/**
|
||||||
|
* Base
|
||||||
|
*/
|
||||||
private final String base;
|
private final String base;
|
||||||
/** City code (ID) */
|
/**
|
||||||
|
* City code (ID)
|
||||||
|
*/
|
||||||
private final long cityID;
|
private final long cityID;
|
||||||
/** City name */
|
/**
|
||||||
|
* City name
|
||||||
|
*/
|
||||||
private final String cityName;
|
private final String cityName;
|
||||||
/** Response code */
|
/**
|
||||||
|
* Response code
|
||||||
|
*/
|
||||||
private final int responseCode;
|
private final int responseCode;
|
||||||
|
|
||||||
private final Clouds clouds;
|
private final Clouds clouds;
|
||||||
private final Coord coord;
|
private final Coord coord;
|
||||||
private final Main main;
|
private final Main main;
|
||||||
private final Rain rain;
|
private final Rain rain;
|
||||||
private final Sys sys;
|
private final Sys sys;
|
||||||
private final Wind wind;
|
private final Wind wind;
|
||||||
|
|
||||||
/** List of weather information (code, name, etc.) */
|
/**
|
||||||
|
* List of weather information (code, name, etc.)
|
||||||
|
*/
|
||||||
private final List<Weather> weatherList;
|
private final List<Weather> weatherList;
|
||||||
/** Count (number) of elements in list of weather information */
|
/**
|
||||||
|
* Count (number) of elements in list of weather information
|
||||||
|
*/
|
||||||
private final int weatherListCount;
|
private final int weatherListCount;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Parameterized constructor
|
* Parameterized constructor
|
||||||
*
|
* <p>
|
||||||
* Initializes variables from values from the given JSON object.
|
* Initializes variables from values from the given JSON object.
|
||||||
*
|
* <p>
|
||||||
* @param jsonObj JSON object containing current weather data
|
* @param jsonObj JSON object containing current weather data
|
||||||
*/
|
*/
|
||||||
public CurrentWeatherData(JSONObject jsonObj) {
|
public CurrentWeatherData(JSONObject jsonObj) {
|
||||||
super(jsonObj);
|
super(jsonObj);
|
||||||
|
|
||||||
this.base = (jsonObj != null) ? jsonObj.optString(this.JSON_BASE, null) : null;
|
this.base = (jsonObj != null) ? jsonObj.optString(this.JSON_BASE, null) : null;
|
||||||
this.cityID = (jsonObj != null) ? jsonObj.optLong(this.JSON_CITY_ID, Long.MIN_VALUE) : Long.MIN_VALUE;
|
this.cityID = (jsonObj != null) ? jsonObj.optLong(this.JSON_CITY_ID, Long.MIN_VALUE) : Long.MIN_VALUE;
|
||||||
this.cityName = (jsonObj != null) ? jsonObj.optString(this.JSON_CITY_NAME, null) : null;
|
this.cityName = (jsonObj != null) ? jsonObj.optString(this.JSON_CITY_NAME, null) : null;
|
||||||
this.responseCode = (jsonObj != null) ? jsonObj.optInt(this.JSON_RESPONSE_CODE, Integer.MIN_VALUE) : Integer.MIN_VALUE;
|
this.responseCode = (jsonObj != null) ? jsonObj.optInt(this.JSON_RESPONSE_CODE, Integer.MIN_VALUE) : Integer.MIN_VALUE;
|
||||||
|
|
||||||
JSONObject jsonObjClouds = (jsonObj != null) ? jsonObj.optJSONObject(this.JSON_CLOUDS) : null;
|
JSONObject jsonObjClouds = (jsonObj != null) ? jsonObj.optJSONObject(this.JSON_CLOUDS) : null;
|
||||||
this.clouds = (jsonObjClouds != null) ? new Clouds(jsonObjClouds) : new Clouds();
|
this.clouds = (jsonObjClouds != null) ? new Clouds(jsonObjClouds) : new Clouds();
|
||||||
|
|
||||||
JSONObject jsonObjCoord = (jsonObj != null) ? jsonObj.optJSONObject(this.JSON_COORD) : null;
|
JSONObject jsonObjCoord = (jsonObj != null) ? jsonObj.optJSONObject(this.JSON_COORD) : null;
|
||||||
this.coord = (jsonObjCoord != null) ? new Coord(jsonObjCoord) : new Coord();
|
this.coord = (jsonObjCoord != null) ? new Coord(jsonObjCoord) : new Coord();
|
||||||
|
|
||||||
JSONObject jsonObjMain = (jsonObj != null) ? jsonObj.optJSONObject(this.JSON_MAIN) : null;
|
JSONObject jsonObjMain = (jsonObj != null) ? jsonObj.optJSONObject(this.JSON_MAIN) : null;
|
||||||
this.main = (jsonObjMain != null) ? new Main(jsonObjMain) : new Main();
|
this.main = (jsonObjMain != null) ? new Main(jsonObjMain) : new Main();
|
||||||
|
|
||||||
JSONObject jsonObjRain = (jsonObj != null) ? jsonObj.optJSONObject(this.JSON_RAIN) : null;
|
JSONObject jsonObjRain = (jsonObj != null) ? jsonObj.optJSONObject(this.JSON_RAIN) : null;
|
||||||
this.rain = (jsonObjRain != null) ? new Rain(jsonObjRain) : new Rain();
|
this.rain = (jsonObjRain != null) ? new Rain(jsonObjRain) : new Rain();
|
||||||
|
|
||||||
JSONObject jsonObjSys = (jsonObj != null) ? jsonObj.optJSONObject(this.JSON_SYS) : null;
|
JSONObject jsonObjSys = (jsonObj != null) ? jsonObj.optJSONObject(this.JSON_SYS) : null;
|
||||||
this.sys = (jsonObjSys != null) ? new Sys(jsonObjSys) : new Sys();
|
this.sys = (jsonObjSys != null) ? new Sys(jsonObjSys) : new Sys();
|
||||||
|
|
||||||
JSONArray jsonArrWeather = (jsonObj != null) ? jsonObj.optJSONArray(this.JSON_WEATHER) : null;
|
JSONArray jsonArrWeather = (jsonObj != null) ? jsonObj.optJSONArray(this.JSON_WEATHER) : null;
|
||||||
this.weatherList = (jsonArrWeather != null) ? new ArrayList<Weather>(jsonArrWeather.length()) : Collections.EMPTY_LIST;
|
this.weatherList = (jsonArrWeather != null) ? new ArrayList<Weather>(jsonArrWeather.length()) : Collections.EMPTY_LIST;
|
||||||
if (this.weatherList != Collections.EMPTY_LIST) {
|
if (this.weatherList != Collections.EMPTY_LIST) {
|
||||||
for (int i = 0; i < jsonArrWeather.length(); i++) {
|
for (int i = 0; i < jsonArrWeather.length(); i++) {
|
||||||
JSONObject jsonObjWeather = jsonArrWeather.optJSONObject (i);
|
JSONObject jsonObjWeather = jsonArrWeather.optJSONObject(i);
|
||||||
if (jsonObjWeather != null) {
|
if (jsonObjWeather != null) {
|
||||||
this.weatherList.add(new Weather(jsonObjWeather));
|
this.weatherList.add(new Weather(jsonObjWeather));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
this.weatherListCount = this.weatherList.size();
|
this.weatherListCount = this.weatherList.size();
|
||||||
|
|
||||||
JSONObject jsonObjWind = (jsonObj != null) ? jsonObj.optJSONObject(this.JSON_WIND) : null;
|
JSONObject jsonObjWind = (jsonObj != null) ? jsonObj.optJSONObject(this.JSON_WIND) : null;
|
||||||
this.wind = (jsonObjWind != null) ? new Wind(jsonObjWind) : new Wind();
|
this.wind = (jsonObjWind != null) ? new Wind(jsonObjWind) : new Wind();
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean hasBaseStation() {
|
public boolean hasBaseStation() {
|
||||||
return (this.base != null);
|
return (this.base != null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean hasCityCode() {
|
public boolean hasCityCode() {
|
||||||
return (this.cityID != Long.MIN_VALUE);
|
return (this.cityID != Long.MIN_VALUE);
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean hasCityName() {
|
public boolean hasCityName() {
|
||||||
return (this.cityName != null);
|
return (this.cityName != null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean hasResponseCode() {
|
public boolean hasResponseCode() {
|
||||||
return (this.responseCode != Integer.MIN_VALUE);
|
return (this.responseCode != Integer.MIN_VALUE);
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getBaseStation() {
|
public String getBaseStation() {
|
||||||
return this.base;
|
return this.base;
|
||||||
}
|
}
|
||||||
|
|
||||||
public long getCityCode() {
|
public long getCityCode() {
|
||||||
return this.cityID;
|
return this.cityID;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getCityName() {
|
public String getCityName() {
|
||||||
return this.cityName;
|
return this.cityName;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getResponseCode() {
|
public int getResponseCode() {
|
||||||
return this.responseCode;
|
return this.responseCode;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Objects
|
// Objects
|
||||||
|
|
||||||
public Clouds getClouds_Object() {
|
public Clouds getClouds_Object() {
|
||||||
return this.clouds;
|
return this.clouds;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Coord getCoordinates_Object() {
|
public Coord getCoordinates_Object() {
|
||||||
return this.coord;
|
return this.coord;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Main getMainData_Object() {
|
public Main getMainData_Object() {
|
||||||
return this.main;
|
return this.main;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Rain getRain_Object() {
|
public Rain getRain_Object() {
|
||||||
return this.rain;
|
return this.rain;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Sys getSysData_Object() {
|
public Sys getSysData_Object() {
|
||||||
return this.sys;
|
return this.sys;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Wind getWind_Object() {
|
public Wind getWind_Object() {
|
||||||
return this.wind;
|
return this.wind;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Lists
|
// Lists
|
||||||
|
|
||||||
public boolean hasWeather_List() {
|
public boolean hasWeather_List() {
|
||||||
return (this.weatherListCount != 0);
|
return (this.weatherListCount != 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getWeather_List_Count() {
|
public int getWeather_List_Count() {
|
||||||
return this.weatherListCount;
|
return this.weatherListCount;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<Weather> getWeather_List() {
|
public List<Weather> getWeather_List() {
|
||||||
return this.weatherList;
|
return this.weatherList;
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,97 +28,107 @@ import org.json.JSONArray;
|
||||||
import org.json.JSONObject;
|
import org.json.JSONObject;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Parses daily forecast data (from the JSON data) and provides methods
|
* Parses daily forecast data (from the JSON data) and provides methods to
|
||||||
* to get/access the information about daily forecasted weather.
|
* get/access the information about daily forecasted weather. This class
|
||||||
* This class provides <code>has</code> and <code>get</code> methods
|
* provides <code>has</code> and <code>get</code> methods to access the
|
||||||
* to access the information.
|
* information.
|
||||||
*
|
* <p>
|
||||||
* <p><code>has</code> methods can be used to check
|
* <p>
|
||||||
* if the data exists, i.e., if the data was available (successfully
|
* <code>has</code> methods can be used to check if the data exists, i.e., if
|
||||||
* downloaded) and was parsed correctly.
|
* the data was available (successfully downloaded) and was parsed correctly.
|
||||||
*
|
* <p>
|
||||||
* <p><code>get</code> methods can be used to access the data, if the data
|
* <p>
|
||||||
* exists, otherwise <code>get</code> methods will give value as per
|
* <code>get</code> methods can be used to access the data, if the data exists,
|
||||||
* following basis:<br>
|
* otherwise <code>get</code> methods will give value as per following
|
||||||
|
* basis:<br>
|
||||||
* Boolean: <code>false</code><br>
|
* Boolean: <code>false</code><br>
|
||||||
* Integral: Minimum value (MIN_VALUE)<br>
|
* Integral: Minimum value (MIN_VALUE)<br>
|
||||||
* Floating point: Not a number (NaN)<br>
|
* Floating point: Not a number (NaN)<br>
|
||||||
* Objects: Data initialized with default/non-parameterized constructor<br>
|
* Objects: Data initialized with default/non-parameterized constructor<br>
|
||||||
* Others: <code>null</code><br>
|
* Others: <code>null</code><br>
|
||||||
*
|
* <p>
|
||||||
* @author Ashutosh Kumar Singh
|
* @author Ashutosh Kumar Singh
|
||||||
* @version 2013/08/07
|
* @version 2013/08/07
|
||||||
* @since 2.5.0.1
|
* @since 2.5.0.1
|
||||||
*/
|
*/
|
||||||
public class DailyForecastData {
|
public class DailyForecastData {
|
||||||
/** Key for JSON object - City */
|
|
||||||
|
/**
|
||||||
|
* Key for JSON object - City
|
||||||
|
*/
|
||||||
private final String JSON_CITY = "city";
|
private final String JSON_CITY = "city";
|
||||||
/** Key for JSON object - List of forecasts */
|
/**
|
||||||
|
* Key for JSON object - List of forecasts
|
||||||
|
*/
|
||||||
private final String JSON_FORECAST_LIST = "list";
|
private final String JSON_FORECAST_LIST = "list";
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
************************
|
************************
|
||||||
* Declaring sub-classes
|
* Declaring sub-classes
|
||||||
************************
|
************************
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Parses data about city (from the JSON data)
|
* Parses data about city (from the JSON data) and provides methods to
|
||||||
* and provides methods to get/access the information.
|
* get/access the information. For example, city name, coordinates, country
|
||||||
* For example, city name, coordinates, country name, population, etc.
|
* name, population, etc. This class provides <code>has</code> and
|
||||||
* This class provides <code>has</code> and <code>get</code> methods
|
* <code>get</code> methods to access the information.
|
||||||
* to access the information.
|
* <p>
|
||||||
*
|
* <p>
|
||||||
* <p><code>has</code> methods can be used to check
|
* <code>has</code> methods can be used to check if the data exists, i.e.,
|
||||||
* if the data exists, i.e., if the data was available (successfully
|
* if the data was available (successfully downloaded) and was parsed
|
||||||
* downloaded) and was parsed correctly.
|
* correctly.
|
||||||
*
|
* <p>
|
||||||
* <p><code>get</code> methods can be used to access the data, if the data
|
* <p>
|
||||||
* exists, otherwise <code>get</code> methods will give value as per
|
* <code>get</code> methods can be used to access the data, if the data
|
||||||
|
* exists, otherwise <code>get</code> methods will give value as per
|
||||||
* following basis:<br>
|
* following basis:<br>
|
||||||
* Boolean: <code>false</code><br>
|
* Boolean: <code>false</code><br>
|
||||||
* Integral: Minimum value (MIN_VALUE)<br>
|
* Integral: Minimum value (MIN_VALUE)<br>
|
||||||
* Floating point: Not a number (NaN)<br>
|
* Floating point: Not a number (NaN)<br>
|
||||||
* Others: <code>null</code><br>
|
* Others: <code>null</code><br>
|
||||||
*
|
* <p>
|
||||||
* @author Ashutosh Kumar Singh
|
* @author Ashutosh Kumar Singh
|
||||||
* @version 2013/08/07
|
* @version 2013/08/07
|
||||||
* @since 2.5.0.1
|
* @since 2.5.0.1
|
||||||
*/
|
*/
|
||||||
public static class City {
|
public static class City {
|
||||||
/** Key for JSON object - Coordinates */
|
|
||||||
private final String JSON_CITY_COORD = "coord";
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Parses data about geographic coordinates (from the JSON data)
|
* Key for JSON object - Coordinates
|
||||||
* and provides methods to get/access the information.
|
*/
|
||||||
* This class provides <code>has</code> and <code>get</code> methods
|
private final String JSON_CITY_COORD = "coord";
|
||||||
* to access the information.
|
|
||||||
*
|
/**
|
||||||
* <p><code>has</code> methods can be used to check
|
* Parses data about geographic coordinates (from the JSON data) and
|
||||||
* if the data exists, i.e., if the data was available (successfully
|
* provides methods to get/access the information. This class provides
|
||||||
* downloaded) and was parsed correctly.
|
* <code>has</code> and <code>get</code> methods to access the
|
||||||
*
|
* information.
|
||||||
* <p><code>get</code> methods can be used to access the data, if the data
|
* <p>
|
||||||
* exists, otherwise <code>get</code> methods will give value as per
|
* <p>
|
||||||
|
* <code>has</code> methods can be used to check if the data exists,
|
||||||
|
* i.e., if the data was available (successfully downloaded) and was
|
||||||
|
* parsed correctly.
|
||||||
|
* <p>
|
||||||
|
* <p>
|
||||||
|
* <code>get</code> methods can be used to access the data, if the data
|
||||||
|
* exists, otherwise <code>get</code> methods will give value as per
|
||||||
* following basis:<br>
|
* following basis:<br>
|
||||||
* Boolean: <code>false</code><br>
|
* Boolean: <code>false</code><br>
|
||||||
* Integral: Minimum value (MIN_VALUE)<br>
|
* Integral: Minimum value (MIN_VALUE)<br>
|
||||||
* Floating point: Not a number (NaN)<br>
|
* Floating point: Not a number (NaN)<br>
|
||||||
* Others: <code>null</code><br>
|
* Others: <code>null</code><br>
|
||||||
*
|
* <p>
|
||||||
* @author Ashutosh Kumar Singh
|
* @author Ashutosh Kumar Singh
|
||||||
* @version 2013/08/07
|
* @version 2013/08/07
|
||||||
* @since 2.5.0.1
|
* @since 2.5.0.1
|
||||||
*/
|
*/
|
||||||
public static class Coord extends AbstractWeatherData.Coord {
|
public static class Coord extends AbstractWeatherData.Coord {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Non-parameterized constructor
|
* Non-parameterized constructor
|
||||||
*
|
* <p>
|
||||||
* <p>Initializes variables as per following basis:<br>
|
* <p>
|
||||||
|
* Initializes variables as per following basis:<br>
|
||||||
* Boolean: <code>false</code><br>
|
* Boolean: <code>false</code><br>
|
||||||
* Integral: Minimum value (MIN_VALUE)<br>
|
* Integral: Minimum value (MIN_VALUE)<br>
|
||||||
* Floating point: Not a number (NaN)<br>
|
* Floating point: Not a number (NaN)<br>
|
||||||
|
@ -127,44 +137,60 @@ public class DailyForecastData {
|
||||||
public Coord() {
|
public Coord() {
|
||||||
super();
|
super();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Parameterized constructor
|
* Parameterized constructor
|
||||||
*
|
* <p>
|
||||||
* Initializes variables from values from the given JSON object.
|
* Initializes variables from values from the given JSON object.
|
||||||
*
|
* <p>
|
||||||
* @param jsonObj JSON object containing data about clouds
|
* @param jsonObj JSON object containing data about clouds
|
||||||
*/
|
*/
|
||||||
public Coord(JSONObject jsonObj) {
|
public Coord(JSONObject jsonObj) {
|
||||||
super(jsonObj);
|
super(jsonObj);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
/** Key for JSON variable <code>City code (ID)</code> */
|
* Key for JSON variable <code>City code (ID)</code>
|
||||||
|
*/
|
||||||
private final String JSON_CITY_ID = "id";
|
private final String JSON_CITY_ID = "id";
|
||||||
/** Key for JSON variable <code>City name</code> */
|
/**
|
||||||
|
* Key for JSON variable <code>City name</code>
|
||||||
|
*/
|
||||||
private final String JSON_CITY_NAME = "name";
|
private final String JSON_CITY_NAME = "name";
|
||||||
/** Key for JSON variable <code>Country code of city</code> */
|
/**
|
||||||
|
* Key for JSON variable <code>Country code of city</code>
|
||||||
|
*/
|
||||||
private final String JSON_CITY_COUNTRY_CODE = "country";
|
private final String JSON_CITY_COUNTRY_CODE = "country";
|
||||||
/** Key for JSON variable <code>Population of city</code> */
|
/**
|
||||||
|
* Key for JSON variable <code>Population of city</code>
|
||||||
|
*/
|
||||||
private final String JSON_CITY_POPULATION = "population";
|
private final String JSON_CITY_POPULATION = "population";
|
||||||
|
|
||||||
/** City code (ID) */
|
/**
|
||||||
|
* City code (ID)
|
||||||
|
*/
|
||||||
private final long cityID;
|
private final long cityID;
|
||||||
/** City name */
|
/**
|
||||||
|
* City name
|
||||||
|
*/
|
||||||
private final String cityName;
|
private final String cityName;
|
||||||
/** Country code of city */
|
/**
|
||||||
|
* Country code of city
|
||||||
|
*/
|
||||||
private final String countryCode;
|
private final String countryCode;
|
||||||
/** Population of city */
|
/**
|
||||||
|
* Population of city
|
||||||
|
*/
|
||||||
private final long population;
|
private final long population;
|
||||||
|
|
||||||
private final Coord coord;
|
private final Coord coord;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Non-parameterized constructor
|
* Non-parameterized constructor
|
||||||
*
|
* <p>
|
||||||
* <p>Initializes variables as per following basis:<br>
|
* <p>
|
||||||
|
* Initializes variables as per following basis:<br>
|
||||||
* Boolean: <code>false</code><br>
|
* Boolean: <code>false</code><br>
|
||||||
* Integral: Minimum value (MIN_VALUE)<br>
|
* Integral: Minimum value (MIN_VALUE)<br>
|
||||||
* Floating point: Not a number (NaN)<br>
|
* Floating point: Not a number (NaN)<br>
|
||||||
|
@ -175,15 +201,15 @@ public class DailyForecastData {
|
||||||
this.cityName = null;
|
this.cityName = null;
|
||||||
this.countryCode = null;
|
this.countryCode = null;
|
||||||
this.population = Long.MIN_VALUE;
|
this.population = Long.MIN_VALUE;
|
||||||
|
|
||||||
this.coord = new Coord();
|
this.coord = new Coord();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Parameterized constructor
|
* Parameterized constructor
|
||||||
*
|
* <p>
|
||||||
* Initializes variables from values from the given JSON object.
|
* Initializes variables from values from the given JSON object.
|
||||||
*
|
* <p>
|
||||||
* @param jsonObj JSON object containing data about city
|
* @param jsonObj JSON object containing data about city
|
||||||
*/
|
*/
|
||||||
public City(JSONObject jsonObj) {
|
public City(JSONObject jsonObj) {
|
||||||
|
@ -191,187 +217,217 @@ public class DailyForecastData {
|
||||||
this.cityName = (jsonObj != null) ? jsonObj.optString(this.JSON_CITY_NAME, null) : null;
|
this.cityName = (jsonObj != null) ? jsonObj.optString(this.JSON_CITY_NAME, null) : null;
|
||||||
this.countryCode = (jsonObj != null) ? jsonObj.optString(this.JSON_CITY_COUNTRY_CODE, null) : null;
|
this.countryCode = (jsonObj != null) ? jsonObj.optString(this.JSON_CITY_COUNTRY_CODE, null) : null;
|
||||||
this.population = (jsonObj != null) ? jsonObj.optLong(this.JSON_CITY_POPULATION, Long.MIN_VALUE) : Long.MIN_VALUE;
|
this.population = (jsonObj != null) ? jsonObj.optLong(this.JSON_CITY_POPULATION, Long.MIN_VALUE) : Long.MIN_VALUE;
|
||||||
|
|
||||||
JSONObject jsonObjCoord = (jsonObj != null) ? jsonObj.optJSONObject(this.JSON_CITY_COORD) : null;
|
JSONObject jsonObjCoord = (jsonObj != null) ? jsonObj.optJSONObject(this.JSON_CITY_COORD) : null;
|
||||||
this.coord = (jsonObjCoord != null) ? new Coord(jsonObjCoord) : new Coord();
|
this.coord = (jsonObjCoord != null) ? new Coord(jsonObjCoord) : new Coord();
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean hasCityCode() {
|
public boolean hasCityCode() {
|
||||||
return (this.cityID != Long.MIN_VALUE);
|
return (this.cityID != Long.MIN_VALUE);
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean hasCityName() {
|
public boolean hasCityName() {
|
||||||
return (this.cityName != null);
|
return (this.cityName != null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean hasCountryCode() {
|
public boolean hasCountryCode() {
|
||||||
return (this.countryCode != null);
|
return (this.countryCode != null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean hasCityPopulation() {
|
public boolean hasCityPopulation() {
|
||||||
return (this.population != Long.MIN_VALUE);
|
return (this.population != Long.MIN_VALUE);
|
||||||
}
|
}
|
||||||
|
|
||||||
public long getCityCode() {
|
public long getCityCode() {
|
||||||
return this.cityID;
|
return this.cityID;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getCityName() {
|
public String getCityName() {
|
||||||
return this.cityName;
|
return this.cityName;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getCountryCode() {
|
public String getCountryCode() {
|
||||||
return this.countryCode;
|
return this.countryCode;
|
||||||
}
|
}
|
||||||
|
|
||||||
public long getCityPopulation() {
|
public long getCityPopulation() {
|
||||||
return this.population;
|
return this.population;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Objects
|
// Objects
|
||||||
|
|
||||||
public Coord getCoordinates_Object() {
|
public Coord getCoordinates_Object() {
|
||||||
return this.coord;
|
return this.coord;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Parses data about forecasts (from the JSON data)
|
* Parses data about forecasts (from the JSON data) and provides methods to
|
||||||
* and provides methods to get/access the information.
|
* get/access the information. This class provides <code>has</code> and
|
||||||
* This class provides <code>has</code> and <code>get</code> methods
|
* <code>get</code> methods to access the information.
|
||||||
* to access the information.
|
* <p>
|
||||||
*
|
* <p>
|
||||||
* <p><code>has</code> methods can be used to check
|
* <code>has</code> methods can be used to check if the data exists, i.e.,
|
||||||
* if the data exists, i.e., if the data was available (successfully
|
* if the data was available (successfully downloaded) and was parsed
|
||||||
* downloaded) and was parsed correctly.
|
* correctly.
|
||||||
*
|
* <p>
|
||||||
* <p><code>get</code> methods can be used to access the data, if the data
|
* <p>
|
||||||
* exists, otherwise <code>get</code> methods will give value as per
|
* <code>get</code> methods can be used to access the data, if the data
|
||||||
|
* exists, otherwise <code>get</code> methods will give value as per
|
||||||
* following basis:<br>
|
* following basis:<br>
|
||||||
* Boolean: <code>false</code><br>
|
* Boolean: <code>false</code><br>
|
||||||
* Integral: Minimum value (MIN_VALUE)<br>
|
* Integral: Minimum value (MIN_VALUE)<br>
|
||||||
* Floating point: Not a number (NaN)<br>
|
* Floating point: Not a number (NaN)<br>
|
||||||
* Others: <code>null</code><br>
|
* Others: <code>null</code><br>
|
||||||
*
|
* <p>
|
||||||
* @author Ashutosh Kumar Singh
|
* @author Ashutosh Kumar Singh
|
||||||
* @version 2013/08/07
|
* @version 2013/08/07
|
||||||
* @since 2.5.0.1
|
* @since 2.5.0.1
|
||||||
*/
|
*/
|
||||||
public static class Forecast extends AbstractWeatherData {
|
public static class Forecast extends AbstractWeatherData {
|
||||||
/** Key for JSON object - Temperature */
|
|
||||||
public final String JSON_TEMP = "temp";
|
|
||||||
|
|
||||||
/*
|
|
||||||
***************************
|
|
||||||
* Declaring sub-sub-classes
|
|
||||||
***************************
|
|
||||||
*/
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Parses data about weather (from the JSON data)
|
* Key for JSON object - Temperature
|
||||||
* and provides methods to get/access the information.
|
*/
|
||||||
* For example, weather id, name, etc.
|
public final String JSON_TEMP = "temp";
|
||||||
* This class provides <code>has</code> and <code>get</code> methods
|
|
||||||
* to access the information.
|
/*
|
||||||
*
|
***************************
|
||||||
* <p><code>has</code> methods can be used to check
|
* Declaring sub-sub-classes
|
||||||
* if the data exists, i.e., if the data was available (successfully
|
***************************
|
||||||
* downloaded) and was parsed correctly.
|
*/
|
||||||
*
|
/**
|
||||||
* <p><code>get</code> methods can be used to access the data, if the data
|
* Parses data about weather (from the JSON data) and provides methods
|
||||||
* exists, otherwise <code>get</code> methods will give value as per
|
* to get/access the information. For example, weather id, name, etc.
|
||||||
|
* This class provides <code>has</code> and <code>get</code> methods to
|
||||||
|
* access the information.
|
||||||
|
* <p>
|
||||||
|
* <p>
|
||||||
|
* <code>has</code> methods can be used to check if the data exists,
|
||||||
|
* i.e., if the data was available (successfully downloaded) and was
|
||||||
|
* parsed correctly.
|
||||||
|
* <p>
|
||||||
|
* <p>
|
||||||
|
* <code>get</code> methods can be used to access the data, if the data
|
||||||
|
* exists, otherwise <code>get</code> methods will give value as per
|
||||||
* following basis:<br>
|
* following basis:<br>
|
||||||
* Boolean: <code>false</code><br>
|
* Boolean: <code>false</code><br>
|
||||||
* Integral: Minimum value (MIN_VALUE)<br>
|
* Integral: Minimum value (MIN_VALUE)<br>
|
||||||
* Floating point: Not a number (NaN)<br>
|
* Floating point: Not a number (NaN)<br>
|
||||||
* Others: <code>null</code><br>
|
* Others: <code>null</code><br>
|
||||||
*
|
* <p>
|
||||||
* @author Ashutosh Kumar Singh
|
* @author Ashutosh Kumar Singh
|
||||||
* @version 2013/08/07
|
* @version 2013/08/07
|
||||||
* @since 2.5.0.1
|
* @since 2.5.0.1
|
||||||
*/
|
*/
|
||||||
public static class Weather extends AbstractWeatherData.Weather {
|
public static class Weather extends AbstractWeatherData.Weather {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Non-parameterized constructor
|
* Non-parameterized constructor
|
||||||
*
|
* <p>
|
||||||
* <p>Initializes variables as per following basis:<br>
|
* <p>
|
||||||
* Boolean: <code>false</code><br>
|
* Initializes variables as per following basis:<br>
|
||||||
* Integral: Minimum value (MIN_VALUE)<br>
|
* Boolean: <code>false</code><br>
|
||||||
* Floating point: Not a number (NaN)<br>
|
* Integral: Minimum value (MIN_VALUE)<br>
|
||||||
* Others: <code>null</code><br>
|
* Floating point: Not a number (NaN)<br>
|
||||||
*/
|
* Others: <code>null</code><br>
|
||||||
public Weather () {
|
*/
|
||||||
|
public Weather() {
|
||||||
super();
|
super();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Parameterized constructor
|
* Parameterized constructor
|
||||||
*
|
* <p>
|
||||||
* Initializes variables from values from the given JSON object.
|
* Initializes variables from values from the given JSON object.
|
||||||
*
|
* <p>
|
||||||
* @param jsonObj JSON object containing data about weather
|
* @param jsonObj JSON object containing data about weather
|
||||||
*/
|
*/
|
||||||
public Weather (JSONObject jsonObj) {
|
public Weather(JSONObject jsonObj) {
|
||||||
super(jsonObj);
|
super(jsonObj);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Parses data about temperature (from the JSON data)
|
* Parses data about temperature (from the JSON data) and provides
|
||||||
* and provides methods to get/access the information.
|
* methods to get/access the information. For example, weather id, name,
|
||||||
* For example, weather id, name, etc.
|
* etc. This class provides <code>has</code> and <code>get</code>
|
||||||
* This class provides <code>has</code> and <code>get</code> methods
|
* methods to access the information.
|
||||||
* to access the information.
|
* <p>
|
||||||
*
|
* <p>
|
||||||
* <p><code>has</code> methods can be used to check
|
* <code>has</code> methods can be used to check if the data exists,
|
||||||
* if the data exists, i.e., if the data was available (successfully
|
* i.e., if the data was available (successfully downloaded) and was
|
||||||
* downloaded) and was parsed correctly.
|
* parsed correctly.
|
||||||
*
|
* <p>
|
||||||
* <p><code>get</code> methods can be used to access the data, if the data
|
* <p>
|
||||||
* exists, otherwise <code>get</code> methods will give value as per
|
* <code>get</code> methods can be used to access the data, if the data
|
||||||
|
* exists, otherwise <code>get</code> methods will give value as per
|
||||||
* following basis:<br>
|
* following basis:<br>
|
||||||
* Boolean: <code>false</code><br>
|
* Boolean: <code>false</code><br>
|
||||||
* Integral: Minimum value (MIN_VALUE)<br>
|
* Integral: Minimum value (MIN_VALUE)<br>
|
||||||
* Floating point: Not a number (NaN)<br>
|
* Floating point: Not a number (NaN)<br>
|
||||||
* Others: <code>null</code><br>
|
* Others: <code>null</code><br>
|
||||||
*
|
* <p>
|
||||||
* @author Ashutosh Kumar Singh
|
* @author Ashutosh Kumar Singh
|
||||||
* @version 2013/08/07
|
* @version 2013/08/07
|
||||||
* @since 2.5.0.1
|
* @since 2.5.0.1
|
||||||
*/
|
*/
|
||||||
public static class Temperature {
|
public static class Temperature {
|
||||||
/** Key for JSON variable <code>Temp -> Day</code> */
|
|
||||||
|
/**
|
||||||
|
* Key for JSON variable <code>Temp -> Day</code>
|
||||||
|
*/
|
||||||
public final String JSON_TEMP_DAY = "day";
|
public final String JSON_TEMP_DAY = "day";
|
||||||
/** Key for JSON variable <code>Temp -> Minimum</code> */
|
/**
|
||||||
|
* Key for JSON variable <code>Temp -> Minimum</code>
|
||||||
|
*/
|
||||||
public final String JSON_TEMP_MIN = "min";
|
public final String JSON_TEMP_MIN = "min";
|
||||||
/** Key for JSON variable <code>Temp -> Maximum</code> */
|
/**
|
||||||
|
* Key for JSON variable <code>Temp -> Maximum</code>
|
||||||
|
*/
|
||||||
public final String JSON_TEMP_MAX = "max";
|
public final String JSON_TEMP_MAX = "max";
|
||||||
/** Key for JSON variable <code>Temp -> Night</code> */
|
/**
|
||||||
|
* Key for JSON variable <code>Temp -> Night</code>
|
||||||
|
*/
|
||||||
public final String JSON_TEMP_NIGHT = "night";
|
public final String JSON_TEMP_NIGHT = "night";
|
||||||
/** Key for JSON variable <code>Temp -> Evening</code> */
|
/**
|
||||||
|
* Key for JSON variable <code>Temp -> Evening</code>
|
||||||
|
*/
|
||||||
public final String JSON_TEMP_EVENING = "eve";
|
public final String JSON_TEMP_EVENING = "eve";
|
||||||
/** Key for JSON variable <code>Temp -> Morning</code> */
|
/**
|
||||||
|
* Key for JSON variable <code>Temp -> Morning</code>
|
||||||
|
*/
|
||||||
public final String JSON_TEMP_MORNING = "morn";
|
public final String JSON_TEMP_MORNING = "morn";
|
||||||
|
|
||||||
/** Day temperature */
|
/**
|
||||||
|
* Day temperature
|
||||||
|
*/
|
||||||
private final float dayTemp;
|
private final float dayTemp;
|
||||||
/** Minimum temperature */
|
/**
|
||||||
|
* Minimum temperature
|
||||||
|
*/
|
||||||
private final float minTemp;
|
private final float minTemp;
|
||||||
/** Maximum temperature */
|
/**
|
||||||
|
* Maximum temperature
|
||||||
|
*/
|
||||||
private final float maxTemp;
|
private final float maxTemp;
|
||||||
/** Night temperature */
|
/**
|
||||||
|
* Night temperature
|
||||||
|
*/
|
||||||
private final float nightTemp;
|
private final float nightTemp;
|
||||||
/** Evening temperature */
|
/**
|
||||||
|
* Evening temperature
|
||||||
|
*/
|
||||||
private final float eveTemp;
|
private final float eveTemp;
|
||||||
/** Morning temperature */
|
/**
|
||||||
|
* Morning temperature
|
||||||
|
*/
|
||||||
private final float mornTemp;
|
private final float mornTemp;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Non-parameterized constructor
|
* Non-parameterized constructor
|
||||||
*
|
* <p>
|
||||||
* <p>Initializes variables as per following basis:<br>
|
* <p>
|
||||||
|
* Initializes variables as per following basis:<br>
|
||||||
* Boolean: <code>false</code><br>
|
* Boolean: <code>false</code><br>
|
||||||
* Integral: Minimum value (MIN_VALUE)<br>
|
* Integral: Minimum value (MIN_VALUE)<br>
|
||||||
* Floating point: Not a number (NaN)<br>
|
* Floating point: Not a number (NaN)<br>
|
||||||
|
@ -385,12 +441,12 @@ public class DailyForecastData {
|
||||||
this.eveTemp = Float.NaN;
|
this.eveTemp = Float.NaN;
|
||||||
this.mornTemp = Float.NaN;
|
this.mornTemp = Float.NaN;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Parameterized constructor
|
* Parameterized constructor
|
||||||
*
|
* <p>
|
||||||
* Initializes variables from values from the given JSON object.
|
* Initializes variables from values from the given JSON object.
|
||||||
*
|
* <p>
|
||||||
* @param jsonObj JSON object containing data about temperature
|
* @param jsonObj JSON object containing data about temperature
|
||||||
*/
|
*/
|
||||||
public Temperature(JSONObject jsonObj) {
|
public Temperature(JSONObject jsonObj) {
|
||||||
|
@ -401,95 +457,119 @@ public class DailyForecastData {
|
||||||
this.eveTemp = (jsonObj != null) ? (float) jsonObj.optDouble(this.JSON_TEMP_EVENING, Double.NaN) : Float.NaN;
|
this.eveTemp = (jsonObj != null) ? (float) jsonObj.optDouble(this.JSON_TEMP_EVENING, Double.NaN) : Float.NaN;
|
||||||
this.mornTemp = (jsonObj != null) ? (float) jsonObj.optDouble(this.JSON_TEMP_MORNING, Double.NaN) : Float.NaN;
|
this.mornTemp = (jsonObj != null) ? (float) jsonObj.optDouble(this.JSON_TEMP_MORNING, Double.NaN) : Float.NaN;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean hasDayTemperature() {
|
public boolean hasDayTemperature() {
|
||||||
return (this.dayTemp != Float.NaN);
|
return (this.dayTemp != Float.NaN);
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean hasMinimumTemperature() {
|
public boolean hasMinimumTemperature() {
|
||||||
return (this.minTemp != Float.NaN);
|
return (this.minTemp != Float.NaN);
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean hasMaximumTemperature() {
|
public boolean hasMaximumTemperature() {
|
||||||
return (this.maxTemp != Float.NaN);
|
return (this.maxTemp != Float.NaN);
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean hasNightTemperature() {
|
public boolean hasNightTemperature() {
|
||||||
return (this.nightTemp != Float.NaN);
|
return (this.nightTemp != Float.NaN);
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean hasEveningTemperature() {
|
public boolean hasEveningTemperature() {
|
||||||
return (this.eveTemp != Float.NaN);
|
return (this.eveTemp != Float.NaN);
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean hasMorningTemperature() {
|
public boolean hasMorningTemperature() {
|
||||||
return (this.mornTemp != Float.NaN);
|
return (this.mornTemp != Float.NaN);
|
||||||
}
|
}
|
||||||
|
|
||||||
public float getDayTemperature() {
|
public float getDayTemperature() {
|
||||||
return this.dayTemp;
|
return this.dayTemp;
|
||||||
}
|
}
|
||||||
|
|
||||||
public float getMinimumTemperature() {
|
public float getMinimumTemperature() {
|
||||||
return this.minTemp;
|
return this.minTemp;
|
||||||
}
|
}
|
||||||
|
|
||||||
public float getMaximumTemperature() {
|
public float getMaximumTemperature() {
|
||||||
return this.maxTemp;
|
return this.maxTemp;
|
||||||
}
|
}
|
||||||
|
|
||||||
public float getNightTemperature() {
|
public float getNightTemperature() {
|
||||||
return this.nightTemp;
|
return this.nightTemp;
|
||||||
}
|
}
|
||||||
|
|
||||||
public float getEveningTemperature() {
|
public float getEveningTemperature() {
|
||||||
return this.eveTemp;
|
return this.eveTemp;
|
||||||
}
|
}
|
||||||
|
|
||||||
public float getMorningTemperature() {
|
public float getMorningTemperature() {
|
||||||
return this.mornTemp;
|
return this.mornTemp;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
************************
|
************************
|
||||||
* Declaring this sub-class
|
* Declaring this sub-class
|
||||||
************************
|
************************
|
||||||
*/
|
*/
|
||||||
|
/**
|
||||||
/** Key for JSON variable <code>Pressure</code> */
|
* Key for JSON variable <code>Pressure</code>
|
||||||
|
*/
|
||||||
private final String JSON_FORECAST_PRESSURE = "pressure";
|
private final String JSON_FORECAST_PRESSURE = "pressure";
|
||||||
/** Key for JSON variable <code>Humidity</code> */
|
/**
|
||||||
|
* Key for JSON variable <code>Humidity</code>
|
||||||
|
*/
|
||||||
private final String JSON_FORECAST_HUMIDITY = "humidity";
|
private final String JSON_FORECAST_HUMIDITY = "humidity";
|
||||||
/** Key for JSON variable <code>Wind speed</code> */
|
/**
|
||||||
|
* Key for JSON variable <code>Wind speed</code>
|
||||||
|
*/
|
||||||
private final String JSON_FORECAST_WIND_SPEED = "speed";
|
private final String JSON_FORECAST_WIND_SPEED = "speed";
|
||||||
/** Key for JSON variable <code>Wind degree</code> */
|
/**
|
||||||
|
* Key for JSON variable <code>Wind degree</code>
|
||||||
|
*/
|
||||||
private final String JSON_FORECAST_WIND_DEGREE = "deg";
|
private final String JSON_FORECAST_WIND_DEGREE = "deg";
|
||||||
/** Key for JSON variable <code>Percentage of clouds</code> */
|
/**
|
||||||
|
* Key for JSON variable <code>Percentage of clouds</code>
|
||||||
|
*/
|
||||||
private final String JSON_FORECAST_CLOUDS = "clouds";
|
private final String JSON_FORECAST_CLOUDS = "clouds";
|
||||||
|
|
||||||
/** Pressure */
|
/**
|
||||||
|
* Pressure
|
||||||
|
*/
|
||||||
private final float pressure;
|
private final float pressure;
|
||||||
/** Humidity */
|
/**
|
||||||
|
* Humidity
|
||||||
|
*/
|
||||||
private final float humidity;
|
private final float humidity;
|
||||||
/** Wind speed */
|
/**
|
||||||
|
* Wind speed
|
||||||
|
*/
|
||||||
private final float windSpeed;
|
private final float windSpeed;
|
||||||
/** Wind degree */
|
/**
|
||||||
|
* Wind degree
|
||||||
|
*/
|
||||||
private final float windDegree;
|
private final float windDegree;
|
||||||
/** Percentage of clouds */
|
/**
|
||||||
|
* Percentage of clouds
|
||||||
|
*/
|
||||||
private final float cloudsPercent;
|
private final float cloudsPercent;
|
||||||
|
|
||||||
private final Temperature temp;
|
private final Temperature temp;
|
||||||
|
|
||||||
/** List of weather information (code, name, etc.) */
|
/**
|
||||||
|
* List of weather information (code, name, etc.)
|
||||||
|
*/
|
||||||
private final List<Weather> weatherList;
|
private final List<Weather> weatherList;
|
||||||
/** Count (number) of elements in list of weather information */
|
/**
|
||||||
|
* Count (number) of elements in list of weather information
|
||||||
|
*/
|
||||||
private final int weatherListCount;
|
private final int weatherListCount;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Non-parameterized constructor
|
* Non-parameterized constructor
|
||||||
*
|
* <p>
|
||||||
* <p>Initializes variables as per following basis:<br>
|
* <p>
|
||||||
|
* Initializes variables as per following basis:<br>
|
||||||
* Boolean: <code>false</code><br>
|
* Boolean: <code>false</code><br>
|
||||||
* Integral: Minimum value (MIN_VALUE)<br>
|
* Integral: Minimum value (MIN_VALUE)<br>
|
||||||
* Floating point: Not a number (NaN)<br>
|
* Floating point: Not a number (NaN)<br>
|
||||||
|
@ -497,32 +577,32 @@ public class DailyForecastData {
|
||||||
*/
|
*/
|
||||||
public Forecast() {
|
public Forecast() {
|
||||||
super();
|
super();
|
||||||
|
|
||||||
this.pressure = Float.NaN;
|
this.pressure = Float.NaN;
|
||||||
this.humidity = Float.NaN;
|
this.humidity = Float.NaN;
|
||||||
this.windSpeed = Float.NaN;
|
this.windSpeed = Float.NaN;
|
||||||
this.windDegree = Float.NaN;
|
this.windDegree = Float.NaN;
|
||||||
this.cloudsPercent = Float.NaN;
|
this.cloudsPercent = Float.NaN;
|
||||||
|
|
||||||
this.temp = new Temperature();
|
this.temp = new Temperature();
|
||||||
|
|
||||||
this.weatherList = Collections.EMPTY_LIST;
|
this.weatherList = Collections.EMPTY_LIST;
|
||||||
this.weatherListCount = this.weatherList.size();
|
this.weatherListCount = this.weatherList.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Parameterized constructor
|
* Parameterized constructor
|
||||||
*
|
* <p>
|
||||||
* Initializes variables from values from the given JSON object.
|
* Initializes variables from values from the given JSON object.
|
||||||
*
|
* <p>
|
||||||
* @param jsonObj JSON object containing data about forecasts
|
* @param jsonObj JSON object containing data about forecasts
|
||||||
*/
|
*/
|
||||||
public Forecast(JSONObject jsonObj) {
|
public Forecast(JSONObject jsonObj) {
|
||||||
super(jsonObj);
|
super(jsonObj);
|
||||||
|
|
||||||
JSONObject jsonObjTemp = (jsonObj != null) ? jsonObj.optJSONObject(this.JSON_TEMP) : null;
|
JSONObject jsonObjTemp = (jsonObj != null) ? jsonObj.optJSONObject(this.JSON_TEMP) : null;
|
||||||
this.temp = (jsonObjTemp != null) ? new Temperature(jsonObjTemp) : new Temperature();
|
this.temp = (jsonObjTemp != null) ? new Temperature(jsonObjTemp) : new Temperature();
|
||||||
|
|
||||||
this.humidity = (jsonObj != null) ? (float) jsonObj.optDouble(this.JSON_FORECAST_HUMIDITY, Double.NaN) : Float.NaN;
|
this.humidity = (jsonObj != null) ? (float) jsonObj.optDouble(this.JSON_FORECAST_HUMIDITY, Double.NaN) : Float.NaN;
|
||||||
this.pressure = (jsonObj != null) ? (float) jsonObj.optDouble(this.JSON_FORECAST_PRESSURE, Double.NaN) : Float.NaN;
|
this.pressure = (jsonObj != null) ? (float) jsonObj.optDouble(this.JSON_FORECAST_PRESSURE, Double.NaN) : Float.NaN;
|
||||||
this.windSpeed = (jsonObj != null) ? (float) jsonObj.optDouble(this.JSON_FORECAST_WIND_SPEED, Double.NaN) : Float.NaN;
|
this.windSpeed = (jsonObj != null) ? (float) jsonObj.optDouble(this.JSON_FORECAST_WIND_SPEED, Double.NaN) : Float.NaN;
|
||||||
|
@ -532,8 +612,8 @@ public class DailyForecastData {
|
||||||
JSONArray jsonArrWeather = (jsonObj != null) ? jsonObj.optJSONArray(this.JSON_WEATHER) : null;
|
JSONArray jsonArrWeather = (jsonObj != null) ? jsonObj.optJSONArray(this.JSON_WEATHER) : null;
|
||||||
this.weatherList = (jsonArrWeather != null) ? new ArrayList<Weather>(jsonArrWeather.length()) : Collections.EMPTY_LIST;
|
this.weatherList = (jsonArrWeather != null) ? new ArrayList<Weather>(jsonArrWeather.length()) : Collections.EMPTY_LIST;
|
||||||
if (this.weatherList != Collections.EMPTY_LIST) {
|
if (this.weatherList != Collections.EMPTY_LIST) {
|
||||||
for (int i = 0; i < jsonArrWeather.length (); i++) {
|
for (int i = 0; i < jsonArrWeather.length(); i++) {
|
||||||
JSONObject jsonObjWeather = jsonArrWeather.optJSONObject (i);
|
JSONObject jsonObjWeather = jsonArrWeather.optJSONObject(i);
|
||||||
if (jsonObjWeather != null) {
|
if (jsonObjWeather != null) {
|
||||||
this.weatherList.add(new Weather(jsonObjWeather));
|
this.weatherList.add(new Weather(jsonObjWeather));
|
||||||
}
|
}
|
||||||
|
@ -541,55 +621,53 @@ public class DailyForecastData {
|
||||||
}
|
}
|
||||||
this.weatherListCount = this.weatherList.size();
|
this.weatherListCount = this.weatherList.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean hasHumidity() {
|
public boolean hasHumidity() {
|
||||||
return (this.humidity != Float.NaN);
|
return (this.humidity != Float.NaN);
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean hasPressure() {
|
public boolean hasPressure() {
|
||||||
return (this.pressure != Float.NaN);
|
return (this.pressure != Float.NaN);
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean hasWindSpeed() {
|
public boolean hasWindSpeed() {
|
||||||
return (this.windSpeed != Float.NaN);
|
return (this.windSpeed != Float.NaN);
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean hasWindDegree() {
|
public boolean hasWindDegree() {
|
||||||
return (this.windDegree != Float.NaN);
|
return (this.windDegree != Float.NaN);
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean hasPercentageOfClouds() {
|
public boolean hasPercentageOfClouds() {
|
||||||
return (this.cloudsPercent != Float.NaN);
|
return (this.cloudsPercent != Float.NaN);
|
||||||
}
|
}
|
||||||
|
|
||||||
public float getHumidity() {
|
public float getHumidity() {
|
||||||
return this.humidity;
|
return this.humidity;
|
||||||
}
|
}
|
||||||
|
|
||||||
public float getPressure() {
|
public float getPressure() {
|
||||||
return this.pressure;
|
return this.pressure;
|
||||||
}
|
}
|
||||||
|
|
||||||
public float getWindSpeed() {
|
public float getWindSpeed() {
|
||||||
return this.windSpeed;
|
return this.windSpeed;
|
||||||
}
|
}
|
||||||
|
|
||||||
public float getWindDegree() {
|
public float getWindDegree() {
|
||||||
return this.windDegree;
|
return this.windDegree;
|
||||||
}
|
}
|
||||||
|
|
||||||
public float getPercentageOfClouds() {
|
public float getPercentageOfClouds() {
|
||||||
return this.cloudsPercent;
|
return this.cloudsPercent;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Objects
|
// Objects
|
||||||
|
|
||||||
public Temperature getTemperature_Object() {
|
public Temperature getTemperature_Object() {
|
||||||
return this.temp;
|
return this.temp;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Lists
|
// Lists
|
||||||
|
|
||||||
public boolean hasWeather_List() {
|
public boolean hasWeather_List() {
|
||||||
return (this.weatherListCount != 0);
|
return (this.weatherListCount != 0);
|
||||||
}
|
}
|
||||||
|
@ -602,50 +680,64 @@ public class DailyForecastData {
|
||||||
return this.weatherList;
|
return this.weatherList;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
***********************
|
***********************
|
||||||
* Declaring this class
|
* Declaring this class
|
||||||
***********************
|
***********************
|
||||||
*/
|
*/
|
||||||
|
/**
|
||||||
/** Key for JSON variable <code>Response code</code> */
|
* Key for JSON variable <code>Response code</code>
|
||||||
|
*/
|
||||||
private final String JSON_RESPONSE_CODE = "cod";
|
private final String JSON_RESPONSE_CODE = "cod";
|
||||||
/** Key for JSON variable <code>Response time</code> */
|
/**
|
||||||
|
* Key for JSON variable <code>Response time</code>
|
||||||
|
*/
|
||||||
private final String JSON_RESPONSE_TIME = "message";
|
private final String JSON_RESPONSE_TIME = "message";
|
||||||
/** Key for JSON variable <code>Forecast count</code> */
|
/**
|
||||||
|
* Key for JSON variable <code>Forecast count</code>
|
||||||
|
*/
|
||||||
private final String JSON_RESPONSE_FORECAST_COUNT = "cnt";
|
private final String JSON_RESPONSE_FORECAST_COUNT = "cnt";
|
||||||
|
|
||||||
/** Response code */
|
/**
|
||||||
|
* Response code
|
||||||
|
*/
|
||||||
private final String responseCode;
|
private final String responseCode;
|
||||||
/** Response time */
|
/**
|
||||||
|
* Response time
|
||||||
|
*/
|
||||||
private final float responseTime;
|
private final float responseTime;
|
||||||
/** Forecast count */
|
/**
|
||||||
|
* Forecast count
|
||||||
|
*/
|
||||||
private final int responseForecastCount;
|
private final int responseForecastCount;
|
||||||
|
|
||||||
private final City city;
|
private final City city;
|
||||||
|
|
||||||
/** List of forecast information */
|
/**
|
||||||
|
* List of forecast information
|
||||||
|
*/
|
||||||
private final List<Forecast> forecastList;
|
private final List<Forecast> forecastList;
|
||||||
/** Count (number) of elements in list of forecast information */
|
/**
|
||||||
|
* Count (number) of elements in list of forecast information
|
||||||
|
*/
|
||||||
private final int forecastListCount;
|
private final int forecastListCount;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Parameterized constructor
|
* Parameterized constructor
|
||||||
*
|
* <p>
|
||||||
* Initializes variables from values from the given JSON object.
|
* Initializes variables from values from the given JSON object.
|
||||||
*
|
* <p>
|
||||||
* @param jsonObj JSON object containing data about daily forecasts
|
* @param jsonObj JSON object containing data about daily forecasts
|
||||||
*/
|
*/
|
||||||
public DailyForecastData(JSONObject jsonObj) {
|
public DailyForecastData(JSONObject jsonObj) {
|
||||||
this.responseCode = (jsonObj != null) ? jsonObj.optString(this.JSON_RESPONSE_CODE, null) : null;
|
this.responseCode = (jsonObj != null) ? jsonObj.optString(this.JSON_RESPONSE_CODE, null) : null;
|
||||||
this.responseTime = (jsonObj != null) ? (float) jsonObj.optDouble(this.JSON_RESPONSE_TIME, Double.NaN) : Float.NaN;
|
this.responseTime = (jsonObj != null) ? (float) jsonObj.optDouble(this.JSON_RESPONSE_TIME, Double.NaN) : Float.NaN;
|
||||||
this.responseForecastCount = (jsonObj != null) ? jsonObj.optInt(this.JSON_RESPONSE_FORECAST_COUNT, Integer.MIN_VALUE) : Integer.MIN_VALUE;
|
this.responseForecastCount = (jsonObj != null) ? jsonObj.optInt(this.JSON_RESPONSE_FORECAST_COUNT, Integer.MIN_VALUE) : Integer.MIN_VALUE;
|
||||||
|
|
||||||
JSONObject jsonObjCity = (jsonObj != null) ? jsonObj.optJSONObject(this.JSON_CITY) : null;
|
JSONObject jsonObjCity = (jsonObj != null) ? jsonObj.optJSONObject(this.JSON_CITY) : null;
|
||||||
this.city = (jsonObjCity != null) ? new City(jsonObjCity) : new City();
|
this.city = (jsonObjCity != null) ? new City(jsonObjCity) : new City();
|
||||||
|
|
||||||
JSONArray jsonArrForecast = (jsonObj != null) ? jsonObj.optJSONArray(this.JSON_FORECAST_LIST) : null;
|
JSONArray jsonArrForecast = (jsonObj != null) ? jsonObj.optJSONArray(this.JSON_FORECAST_LIST) : null;
|
||||||
this.forecastList = (jsonArrForecast != null) ? new ArrayList<Forecast>(jsonArrForecast.length()) : Collections.EMPTY_LIST;
|
this.forecastList = (jsonArrForecast != null) ? new ArrayList<Forecast>(jsonArrForecast.length()) : Collections.EMPTY_LIST;
|
||||||
if (this.forecastList != Collections.EMPTY_LIST) {
|
if (this.forecastList != Collections.EMPTY_LIST) {
|
||||||
|
@ -658,47 +750,45 @@ public class DailyForecastData {
|
||||||
}
|
}
|
||||||
this.forecastListCount = this.forecastList.size();
|
this.forecastListCount = this.forecastList.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean hasResponseCode() {
|
public boolean hasResponseCode() {
|
||||||
return (this.responseCode != null);
|
return (this.responseCode != null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean hasResponseTime() {
|
public boolean hasResponseTime() {
|
||||||
return (this.responseTime != Float.NaN);
|
return (this.responseTime != Float.NaN);
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean hasResponseForecastCount() {
|
public boolean hasResponseForecastCount() {
|
||||||
return (this.responseForecastCount != Integer.MIN_VALUE);
|
return (this.responseForecastCount != Integer.MIN_VALUE);
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getResponseCode() {
|
public String getResponseCode() {
|
||||||
return this.responseCode;
|
return this.responseCode;
|
||||||
}
|
}
|
||||||
|
|
||||||
public float getResponseTime() {
|
public float getResponseTime() {
|
||||||
return this.responseTime;
|
return this.responseTime;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getResponseForecastCount() {
|
public int getResponseForecastCount() {
|
||||||
return this.responseForecastCount;
|
return this.responseForecastCount;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Objects
|
// Objects
|
||||||
|
|
||||||
public City getCity_Object() {
|
public City getCity_Object() {
|
||||||
return this.city;
|
return this.city;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Lists
|
// Lists
|
||||||
|
|
||||||
public boolean hasForecast_List() {
|
public boolean hasForecast_List() {
|
||||||
return (this.forecastListCount != 0);
|
return (this.forecastListCount != 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getForecast_List_Count() {
|
public int getForecast_List_Count() {
|
||||||
return this.forecastListCount;
|
return this.forecastListCount;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<Forecast> getForecast_List() {
|
public List<Forecast> getForecast_List() {
|
||||||
return this.forecastList;
|
return this.forecastList;
|
||||||
}
|
}
|
||||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -30,7 +30,7 @@ import org.json.JSONObject;
|
||||||
/**
|
/**
|
||||||
* Provides methods to get weather, forecast, and other data from
|
* Provides methods to get weather, forecast, and other data from
|
||||||
* OpenWeatherMap.org
|
* OpenWeatherMap.org
|
||||||
*
|
* <p>
|
||||||
* @author Ashutosh Kumar Singh
|
* @author Ashutosh Kumar Singh
|
||||||
* @version 2013/08/05
|
* @version 2013/08/05
|
||||||
* @since 2.5.0.1
|
* @since 2.5.0.1
|
||||||
|
@ -69,7 +69,7 @@ public class OpenWeatherMap {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the parameter.
|
* Returns the parameter.
|
||||||
*
|
* <p>
|
||||||
* @return Parameter
|
* @return Parameter
|
||||||
*/
|
*/
|
||||||
public String getParameter() {
|
public String getParameter() {
|
||||||
|
@ -98,15 +98,15 @@ public class OpenWeatherMap {
|
||||||
String response;
|
String response;
|
||||||
|
|
||||||
String address = OWM_URL.BASE_URL.getParameter()
|
String address = OWM_URL.BASE_URL.getParameter()
|
||||||
+ OWM_URL.PARAMETER_CURRENT_WEATHER.getParameter()
|
+ OWM_URL.PARAMETER_CURRENT_WEATHER.getParameter()
|
||||||
+ OWM_URL.PARAMETER_CITY_NAME.getParameter()
|
+ OWM_URL.PARAMETER_CITY_NAME.getParameter()
|
||||||
+ URLEncoder.encode(cityName, "US-ASCII") + "&"
|
+ URLEncoder.encode(cityName, "US-ASCII") + "&"
|
||||||
+ OWM_URL.PARAMETER_MODE.getParameter()
|
+ OWM_URL.PARAMETER_MODE.getParameter()
|
||||||
+ this.OWM_MODE_VALUE + "&"
|
+ this.OWM_MODE_VALUE + "&"
|
||||||
+ OWM_URL.PARAMETER_UNITS.getParameter()
|
+ OWM_URL.PARAMETER_UNITS.getParameter()
|
||||||
+ this.OWM_UNITS_VALUE + "&"
|
+ this.OWM_UNITS_VALUE + "&"
|
||||||
+ OWM_URL.PARAMETER_APPID.getParameter()
|
+ OWM_URL.PARAMETER_APPID.getParameter()
|
||||||
+ this.OWM_APPID_VALUE;
|
+ this.OWM_APPID_VALUE;
|
||||||
|
|
||||||
response = Tools.Downloader.downloadPage(address);
|
response = Tools.Downloader.downloadPage(address);
|
||||||
|
|
||||||
|
@ -119,16 +119,16 @@ public class OpenWeatherMap {
|
||||||
String response;
|
String response;
|
||||||
|
|
||||||
address = OWM_URL.BASE_URL.getParameter()
|
address = OWM_URL.BASE_URL.getParameter()
|
||||||
+ OWM_URL.PARAMETER_CURRENT_WEATHER.getParameter()
|
+ OWM_URL.PARAMETER_CURRENT_WEATHER.getParameter()
|
||||||
+ OWM_URL.PARAMETER_CITY_NAME.getParameter()
|
+ OWM_URL.PARAMETER_CITY_NAME.getParameter()
|
||||||
+ URLEncoder.encode(cityName, "US-ASCII")
|
+ URLEncoder.encode(cityName, "US-ASCII")
|
||||||
+ "," + countryCode + "&"
|
+ "," + countryCode + "&"
|
||||||
+ OWM_URL.PARAMETER_MODE.getParameter()
|
+ OWM_URL.PARAMETER_MODE.getParameter()
|
||||||
+ this.OWM_MODE_VALUE + "&"
|
+ this.OWM_MODE_VALUE + "&"
|
||||||
+ OWM_URL.PARAMETER_UNITS.getParameter()
|
+ OWM_URL.PARAMETER_UNITS.getParameter()
|
||||||
+ this.OWM_UNITS_VALUE + "&"
|
+ this.OWM_UNITS_VALUE + "&"
|
||||||
+ OWM_URL.PARAMETER_APPID.getParameter()
|
+ OWM_URL.PARAMETER_APPID.getParameter()
|
||||||
+ this.OWM_APPID_VALUE;
|
+ this.OWM_APPID_VALUE;
|
||||||
|
|
||||||
response = Tools.Downloader.downloadPage(address);
|
response = Tools.Downloader.downloadPage(address);
|
||||||
|
|
||||||
|
@ -141,15 +141,15 @@ public class OpenWeatherMap {
|
||||||
String response;
|
String response;
|
||||||
|
|
||||||
address = OWM_URL.BASE_URL.getParameter()
|
address = OWM_URL.BASE_URL.getParameter()
|
||||||
+ OWM_URL.PARAMETER_CURRENT_WEATHER.getParameter()
|
+ OWM_URL.PARAMETER_CURRENT_WEATHER.getParameter()
|
||||||
+ OWM_URL.PARAMETER_CITY_ID.getParameter()
|
+ OWM_URL.PARAMETER_CITY_ID.getParameter()
|
||||||
+ Long.toString(cityCode) + "&"
|
+ Long.toString(cityCode) + "&"
|
||||||
+ OWM_URL.PARAMETER_MODE.getParameter()
|
+ OWM_URL.PARAMETER_MODE.getParameter()
|
||||||
+ this.OWM_MODE_VALUE + "&"
|
+ this.OWM_MODE_VALUE + "&"
|
||||||
+ OWM_URL.PARAMETER_UNITS.getParameter()
|
+ OWM_URL.PARAMETER_UNITS.getParameter()
|
||||||
+ this.OWM_UNITS_VALUE + "&"
|
+ this.OWM_UNITS_VALUE + "&"
|
||||||
+ OWM_URL.PARAMETER_APPID.getParameter()
|
+ OWM_URL.PARAMETER_APPID.getParameter()
|
||||||
+ this.OWM_APPID_VALUE;
|
+ this.OWM_APPID_VALUE;
|
||||||
|
|
||||||
response = Tools.Downloader.downloadPage(address);
|
response = Tools.Downloader.downloadPage(address);
|
||||||
|
|
||||||
|
@ -162,17 +162,17 @@ public class OpenWeatherMap {
|
||||||
String response;
|
String response;
|
||||||
|
|
||||||
address = OWM_URL.BASE_URL.getParameter()
|
address = OWM_URL.BASE_URL.getParameter()
|
||||||
+ OWM_URL.PARAMETER_CURRENT_WEATHER.getParameter()
|
+ OWM_URL.PARAMETER_CURRENT_WEATHER.getParameter()
|
||||||
+ OWM_URL.PARAMETER_LATITUDE.getParameter()
|
+ OWM_URL.PARAMETER_LATITUDE.getParameter()
|
||||||
+ Float.toString(latitude) + "&"
|
+ Float.toString(latitude) + "&"
|
||||||
+ OWM_URL.PARAMETER_LONGITUDE.getParameter()
|
+ OWM_URL.PARAMETER_LONGITUDE.getParameter()
|
||||||
+ Float.toString(longitude) + "&"
|
+ Float.toString(longitude) + "&"
|
||||||
+ OWM_URL.PARAMETER_MODE.getParameter()
|
+ OWM_URL.PARAMETER_MODE.getParameter()
|
||||||
+ this.OWM_MODE_VALUE + "&"
|
+ this.OWM_MODE_VALUE + "&"
|
||||||
+ OWM_URL.PARAMETER_UNITS.getParameter()
|
+ OWM_URL.PARAMETER_UNITS.getParameter()
|
||||||
+ this.OWM_UNITS_VALUE + "&"
|
+ this.OWM_UNITS_VALUE + "&"
|
||||||
+ OWM_URL.PARAMETER_APPID.getParameter()
|
+ OWM_URL.PARAMETER_APPID.getParameter()
|
||||||
+ this.OWM_APPID_VALUE;
|
+ this.OWM_APPID_VALUE;
|
||||||
|
|
||||||
response = Tools.Downloader.downloadPage(address);
|
response = Tools.Downloader.downloadPage(address);
|
||||||
|
|
||||||
|
@ -185,15 +185,15 @@ public class OpenWeatherMap {
|
||||||
String response;
|
String response;
|
||||||
|
|
||||||
address = OWM_URL.BASE_URL.getParameter()
|
address = OWM_URL.BASE_URL.getParameter()
|
||||||
+ OWM_URL.PARAMETER_FORECAST_WEATHER.getParameter()
|
+ OWM_URL.PARAMETER_FORECAST_WEATHER.getParameter()
|
||||||
+ OWM_URL.PARAMETER_CITY_NAME.getParameter()
|
+ OWM_URL.PARAMETER_CITY_NAME.getParameter()
|
||||||
+ URLEncoder.encode(cityName, "US-ASCII") + "&"
|
+ URLEncoder.encode(cityName, "US-ASCII") + "&"
|
||||||
+ OWM_URL.PARAMETER_MODE.getParameter()
|
+ OWM_URL.PARAMETER_MODE.getParameter()
|
||||||
+ this.OWM_MODE_VALUE + "&"
|
+ this.OWM_MODE_VALUE + "&"
|
||||||
+ OWM_URL.PARAMETER_UNITS.getParameter()
|
+ OWM_URL.PARAMETER_UNITS.getParameter()
|
||||||
+ this.OWM_UNITS_VALUE + "&"
|
+ this.OWM_UNITS_VALUE + "&"
|
||||||
+ OWM_URL.PARAMETER_APPID.getParameter()
|
+ OWM_URL.PARAMETER_APPID.getParameter()
|
||||||
+ this.OWM_APPID_VALUE;
|
+ this.OWM_APPID_VALUE;
|
||||||
|
|
||||||
response = Tools.Downloader.downloadPage(address);
|
response = Tools.Downloader.downloadPage(address);
|
||||||
|
|
||||||
|
@ -206,16 +206,16 @@ public class OpenWeatherMap {
|
||||||
String response;
|
String response;
|
||||||
|
|
||||||
address = OWM_URL.BASE_URL.getParameter()
|
address = OWM_URL.BASE_URL.getParameter()
|
||||||
+ OWM_URL.PARAMETER_FORECAST_WEATHER.getParameter()
|
+ OWM_URL.PARAMETER_FORECAST_WEATHER.getParameter()
|
||||||
+ OWM_URL.PARAMETER_CITY_NAME.getParameter()
|
+ OWM_URL.PARAMETER_CITY_NAME.getParameter()
|
||||||
+ URLEncoder.encode(cityName, "US-ASCII")
|
+ URLEncoder.encode(cityName, "US-ASCII")
|
||||||
+ "," + countryCode + "&"
|
+ "," + countryCode + "&"
|
||||||
+ OWM_URL.PARAMETER_MODE.getParameter()
|
+ OWM_URL.PARAMETER_MODE.getParameter()
|
||||||
+ this.OWM_MODE_VALUE + "&"
|
+ this.OWM_MODE_VALUE + "&"
|
||||||
+ OWM_URL.PARAMETER_UNITS.getParameter()
|
+ OWM_URL.PARAMETER_UNITS.getParameter()
|
||||||
+ this.OWM_UNITS_VALUE + "&"
|
+ this.OWM_UNITS_VALUE + "&"
|
||||||
+ OWM_URL.PARAMETER_APPID.getParameter()
|
+ OWM_URL.PARAMETER_APPID.getParameter()
|
||||||
+ this.OWM_APPID_VALUE;
|
+ this.OWM_APPID_VALUE;
|
||||||
|
|
||||||
response = Tools.Downloader.downloadPage(address);
|
response = Tools.Downloader.downloadPage(address);
|
||||||
|
|
||||||
|
@ -228,15 +228,15 @@ public class OpenWeatherMap {
|
||||||
String response;
|
String response;
|
||||||
|
|
||||||
address = OWM_URL.BASE_URL.getParameter()
|
address = OWM_URL.BASE_URL.getParameter()
|
||||||
+ OWM_URL.PARAMETER_FORECAST_WEATHER.getParameter()
|
+ OWM_URL.PARAMETER_FORECAST_WEATHER.getParameter()
|
||||||
+ OWM_URL.PARAMETER_CITY_ID.getParameter()
|
+ OWM_URL.PARAMETER_CITY_ID.getParameter()
|
||||||
+ Long.toString(cityCode) + "&"
|
+ Long.toString(cityCode) + "&"
|
||||||
+ OWM_URL.PARAMETER_MODE.getParameter()
|
+ OWM_URL.PARAMETER_MODE.getParameter()
|
||||||
+ this.OWM_MODE_VALUE + "&"
|
+ this.OWM_MODE_VALUE + "&"
|
||||||
+ OWM_URL.PARAMETER_UNITS.getParameter()
|
+ OWM_URL.PARAMETER_UNITS.getParameter()
|
||||||
+ this.OWM_UNITS_VALUE + "&"
|
+ this.OWM_UNITS_VALUE + "&"
|
||||||
+ OWM_URL.PARAMETER_APPID.getParameter()
|
+ OWM_URL.PARAMETER_APPID.getParameter()
|
||||||
+ this.OWM_APPID_VALUE;
|
+ this.OWM_APPID_VALUE;
|
||||||
|
|
||||||
response = Tools.Downloader.downloadPage(address);
|
response = Tools.Downloader.downloadPage(address);
|
||||||
|
|
||||||
|
@ -249,17 +249,17 @@ public class OpenWeatherMap {
|
||||||
String response;
|
String response;
|
||||||
|
|
||||||
address = OWM_URL.BASE_URL.getParameter()
|
address = OWM_URL.BASE_URL.getParameter()
|
||||||
+ OWM_URL.PARAMETER_FORECAST_WEATHER.getParameter()
|
+ OWM_URL.PARAMETER_FORECAST_WEATHER.getParameter()
|
||||||
+ OWM_URL.PARAMETER_LATITUDE.getParameter()
|
+ OWM_URL.PARAMETER_LATITUDE.getParameter()
|
||||||
+ Float.toString(latitude) + "&"
|
+ Float.toString(latitude) + "&"
|
||||||
+ OWM_URL.PARAMETER_LONGITUDE.getParameter()
|
+ OWM_URL.PARAMETER_LONGITUDE.getParameter()
|
||||||
+ Float.toString(longitude) + "&"
|
+ Float.toString(longitude) + "&"
|
||||||
+ OWM_URL.PARAMETER_MODE.getParameter()
|
+ OWM_URL.PARAMETER_MODE.getParameter()
|
||||||
+ this.OWM_MODE_VALUE + "&"
|
+ this.OWM_MODE_VALUE + "&"
|
||||||
+ OWM_URL.PARAMETER_UNITS.getParameter()
|
+ OWM_URL.PARAMETER_UNITS.getParameter()
|
||||||
+ this.OWM_UNITS_VALUE + "&"
|
+ this.OWM_UNITS_VALUE + "&"
|
||||||
+ OWM_URL.PARAMETER_APPID.getParameter()
|
+ OWM_URL.PARAMETER_APPID.getParameter()
|
||||||
+ this.OWM_APPID_VALUE;
|
+ this.OWM_APPID_VALUE;
|
||||||
|
|
||||||
response = Tools.Downloader.downloadPage(address);
|
response = Tools.Downloader.downloadPage(address);
|
||||||
|
|
||||||
|
@ -272,17 +272,17 @@ public class OpenWeatherMap {
|
||||||
String response;
|
String response;
|
||||||
|
|
||||||
address = OWM_URL.BASE_URL.getParameter()
|
address = OWM_URL.BASE_URL.getParameter()
|
||||||
+ OWM_URL.PARAMETER_DAILY_FORECAST.getParameter()
|
+ OWM_URL.PARAMETER_DAILY_FORECAST.getParameter()
|
||||||
+ OWM_URL.PARAMETER_CITY_NAME.getParameter()
|
+ OWM_URL.PARAMETER_CITY_NAME.getParameter()
|
||||||
+ URLEncoder.encode(cityName, "US-ASCII") + "&"
|
+ URLEncoder.encode(cityName, "US-ASCII") + "&"
|
||||||
+ OWM_URL.PARAMETER_COUNT.getParameter()
|
+ OWM_URL.PARAMETER_COUNT.getParameter()
|
||||||
+ Byte.toString(count) + "&"
|
+ Byte.toString(count) + "&"
|
||||||
+ OWM_URL.PARAMETER_MODE.getParameter()
|
+ OWM_URL.PARAMETER_MODE.getParameter()
|
||||||
+ this.OWM_MODE_VALUE + "&"
|
+ this.OWM_MODE_VALUE + "&"
|
||||||
+ OWM_URL.PARAMETER_UNITS.getParameter()
|
+ OWM_URL.PARAMETER_UNITS.getParameter()
|
||||||
+ this.OWM_UNITS_VALUE + "&"
|
+ this.OWM_UNITS_VALUE + "&"
|
||||||
+ OWM_URL.PARAMETER_APPID.getParameter()
|
+ OWM_URL.PARAMETER_APPID.getParameter()
|
||||||
+ this.OWM_APPID_VALUE;
|
+ this.OWM_APPID_VALUE;
|
||||||
|
|
||||||
response = Tools.Downloader.downloadPage(address);
|
response = Tools.Downloader.downloadPage(address);
|
||||||
|
|
||||||
|
@ -295,18 +295,18 @@ public class OpenWeatherMap {
|
||||||
String response;
|
String response;
|
||||||
|
|
||||||
address = OWM_URL.BASE_URL.getParameter()
|
address = OWM_URL.BASE_URL.getParameter()
|
||||||
+ OWM_URL.PARAMETER_DAILY_FORECAST.getParameter()
|
+ OWM_URL.PARAMETER_DAILY_FORECAST.getParameter()
|
||||||
+ OWM_URL.PARAMETER_CITY_NAME.getParameter()
|
+ OWM_URL.PARAMETER_CITY_NAME.getParameter()
|
||||||
+ URLEncoder.encode(cityName, "US-ASCII")
|
+ URLEncoder.encode(cityName, "US-ASCII")
|
||||||
+ "," + countryCode + "&"
|
+ "," + countryCode + "&"
|
||||||
+ OWM_URL.PARAMETER_COUNT.getParameter()
|
+ OWM_URL.PARAMETER_COUNT.getParameter()
|
||||||
+ Byte.toString(count) + "&"
|
+ Byte.toString(count) + "&"
|
||||||
+ OWM_URL.PARAMETER_MODE.getParameter()
|
+ OWM_URL.PARAMETER_MODE.getParameter()
|
||||||
+ this.OWM_MODE_VALUE + "&"
|
+ this.OWM_MODE_VALUE + "&"
|
||||||
+ OWM_URL.PARAMETER_UNITS.getParameter()
|
+ OWM_URL.PARAMETER_UNITS.getParameter()
|
||||||
+ this.OWM_UNITS_VALUE + "&"
|
+ this.OWM_UNITS_VALUE + "&"
|
||||||
+ OWM_URL.PARAMETER_APPID.getParameter()
|
+ OWM_URL.PARAMETER_APPID.getParameter()
|
||||||
+ this.OWM_APPID_VALUE;
|
+ this.OWM_APPID_VALUE;
|
||||||
|
|
||||||
response = Tools.Downloader.downloadPage(address);
|
response = Tools.Downloader.downloadPage(address);
|
||||||
|
|
||||||
|
@ -319,17 +319,17 @@ public class OpenWeatherMap {
|
||||||
String response;
|
String response;
|
||||||
|
|
||||||
address = OWM_URL.BASE_URL.getParameter()
|
address = OWM_URL.BASE_URL.getParameter()
|
||||||
+ OWM_URL.PARAMETER_DAILY_FORECAST.getParameter()
|
+ OWM_URL.PARAMETER_DAILY_FORECAST.getParameter()
|
||||||
+ OWM_URL.PARAMETER_CITY_ID.getParameter()
|
+ OWM_URL.PARAMETER_CITY_ID.getParameter()
|
||||||
+ Long.toString(cityCode) + "&"
|
+ Long.toString(cityCode) + "&"
|
||||||
+ OWM_URL.PARAMETER_COUNT.getParameter()
|
+ OWM_URL.PARAMETER_COUNT.getParameter()
|
||||||
+ Byte.toString(count) + "&"
|
+ Byte.toString(count) + "&"
|
||||||
+ OWM_URL.PARAMETER_MODE.getParameter()
|
+ OWM_URL.PARAMETER_MODE.getParameter()
|
||||||
+ this.OWM_MODE_VALUE + "&"
|
+ this.OWM_MODE_VALUE + "&"
|
||||||
+ OWM_URL.PARAMETER_UNITS.getParameter()
|
+ OWM_URL.PARAMETER_UNITS.getParameter()
|
||||||
+ this.OWM_UNITS_VALUE + "&"
|
+ this.OWM_UNITS_VALUE + "&"
|
||||||
+ OWM_URL.PARAMETER_APPID.getParameter()
|
+ OWM_URL.PARAMETER_APPID.getParameter()
|
||||||
+ this.OWM_APPID_VALUE;
|
+ this.OWM_APPID_VALUE;
|
||||||
|
|
||||||
response = Tools.Downloader.downloadPage(address);
|
response = Tools.Downloader.downloadPage(address);
|
||||||
|
|
||||||
|
@ -342,19 +342,19 @@ public class OpenWeatherMap {
|
||||||
String response;
|
String response;
|
||||||
|
|
||||||
address = OWM_URL.BASE_URL.getParameter()
|
address = OWM_URL.BASE_URL.getParameter()
|
||||||
+ OWM_URL.PARAMETER_DAILY_FORECAST.getParameter()
|
+ OWM_URL.PARAMETER_DAILY_FORECAST.getParameter()
|
||||||
+ OWM_URL.PARAMETER_LATITUDE.getParameter()
|
+ OWM_URL.PARAMETER_LATITUDE.getParameter()
|
||||||
+ Float.toString(latitude) + "&"
|
+ Float.toString(latitude) + "&"
|
||||||
+ OWM_URL.PARAMETER_COUNT.getParameter()
|
+ OWM_URL.PARAMETER_COUNT.getParameter()
|
||||||
+ Byte.toString(count) + "&"
|
+ Byte.toString(count) + "&"
|
||||||
+ OWM_URL.PARAMETER_LONGITUDE.getParameter()
|
+ OWM_URL.PARAMETER_LONGITUDE.getParameter()
|
||||||
+ Float.toString(longitude) + "&"
|
+ Float.toString(longitude) + "&"
|
||||||
+ OWM_URL.PARAMETER_MODE.getParameter()
|
+ OWM_URL.PARAMETER_MODE.getParameter()
|
||||||
+ this.OWM_MODE_VALUE + "&"
|
+ this.OWM_MODE_VALUE + "&"
|
||||||
+ OWM_URL.PARAMETER_UNITS.getParameter()
|
+ OWM_URL.PARAMETER_UNITS.getParameter()
|
||||||
+ this.OWM_UNITS_VALUE + "&"
|
+ this.OWM_UNITS_VALUE + "&"
|
||||||
+ OWM_URL.PARAMETER_APPID.getParameter()
|
+ OWM_URL.PARAMETER_APPID.getParameter()
|
||||||
+ this.OWM_APPID_VALUE;
|
+ this.OWM_APPID_VALUE;
|
||||||
|
|
||||||
response = Tools.Downloader.downloadPage(address);
|
response = Tools.Downloader.downloadPage(address);
|
||||||
|
|
||||||
|
@ -364,8 +364,7 @@ public class OpenWeatherMap {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* *********************
|
* *********************
|
||||||
* Declaring this class
|
* Declaring this class *********************
|
||||||
**********************
|
|
||||||
*/
|
*/
|
||||||
private final OWM_Response owmResponse;
|
private final OWM_Response owmResponse;
|
||||||
|
|
||||||
|
|
|
@ -28,15 +28,15 @@ import java.net.URL;
|
||||||
import java.util.Scanner;
|
import java.util.Scanner;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Provides various tools, which help doing tasks in this application.
|
* Provides various tools, which help doing tasks in this application. For
|
||||||
* For example, tool for downloading content from the Internet, tool for
|
* example, tool for downloading content from the Internet, tool for correcting,
|
||||||
* correcting, etc.
|
* etc.
|
||||||
*
|
* <p>
|
||||||
* <p>Note: This class directly do not provide any functions, but has
|
* <p>
|
||||||
* <code>static</code> sub-classes which provide various
|
* Note: This class directly do not provide any functions, but has
|
||||||
* related tools, i.e., this class only behaves as the container for those
|
* <code>static</code> sub-classes which provide various related tools, i.e.,
|
||||||
* classes.
|
* this class only behaves as the container for those classes.
|
||||||
*
|
* <p>
|
||||||
* @author Ashutosh Kumar Singh
|
* @author Ashutosh Kumar Singh
|
||||||
* @version 2014-07-01
|
* @version 2014-07-01
|
||||||
* @since 2.5.0.1
|
* @since 2.5.0.1
|
||||||
|
@ -45,7 +45,7 @@ public class Tools {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Provides methods to download data or files from the Internet.
|
* Provides methods to download data or files from the Internet.
|
||||||
*
|
* <p>
|
||||||
* @author Ashutosh Kumar Singh
|
* @author Ashutosh Kumar Singh
|
||||||
* @version 2013-07-24
|
* @version 2013-07-24
|
||||||
* @since 2.5.0.1
|
* @since 2.5.0.1
|
||||||
|
@ -53,123 +53,105 @@ public class Tools {
|
||||||
public static class Downloader {
|
public static class Downloader {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Downloads a page/content from the Internet.
|
* Downloads a page/content from the Internet. This method gets the
|
||||||
* This method gets the content of the web page, whose URL is given by
|
* content of the web page, whose URL is given by the
|
||||||
* the <code>pageAddress</code>.
|
* <code>pageAddress</code>.
|
||||||
*
|
* <p>
|
||||||
* <p>NOTE: <code>pageAddress</code> should be a correct URL, else
|
* <p>
|
||||||
* this method will throw {@link MalformedURLException}.
|
* NOTE: <code>pageAddress</code> should be a correct URL, else this
|
||||||
*
|
* method will throw {@link MalformedURLException}.
|
||||||
* @param pageAddress
|
* <p>
|
||||||
* Address of the web page to get from the Internet.
|
* @param pageAddress Address of the web page to get from the Internet.
|
||||||
*
|
* <p>
|
||||||
* @return Content of the web page
|
* @return Content of the web page
|
||||||
*
|
* <p>
|
||||||
* @throws MalformedURLException
|
* @throws MalformedURLException Address of the web page is not correct.
|
||||||
* Address of the web page is not correct.
|
* <p>
|
||||||
*
|
* @throws IOException Error while loading the page from the
|
||||||
* @throws IOException
|
* Internet or connection got
|
||||||
* Error while loading the page from the Internet or connection
|
* disconnected.
|
||||||
* got disconnected.
|
|
||||||
*/
|
*/
|
||||||
public static String downloadPage(String pageAddress)
|
public static String downloadPage(String pageAddress)
|
||||||
throws MalformedURLException, IOException {
|
throws MalformedURLException, IOException {
|
||||||
String webPage = null;
|
String webPage = null;
|
||||||
|
|
||||||
URL url = new URL(pageAddress);
|
URL url = new URL(pageAddress);
|
||||||
InputStream iStream = url.openStream();
|
InputStream iStream = url.openStream();
|
||||||
|
|
||||||
if (iStream != null) {
|
if (iStream != null) {
|
||||||
// converting InputStream to String (as we require String)
|
// converting InputStream to String (as we require String)
|
||||||
webPage = (new Scanner(iStream)).useDelimiter("\\A").next();
|
webPage = (new Scanner(iStream)).useDelimiter("\\A").next();
|
||||||
}
|
}
|
||||||
iStream.close();
|
iStream.close();
|
||||||
|
|
||||||
return webPage;
|
return webPage;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Provides methods to do conversions.
|
* Provides methods to do conversions. For example, converting degree to
|
||||||
* For example, converting degree to direction, etc.
|
* direction, etc.
|
||||||
*
|
* <p>
|
||||||
* @author Ashutosh Kumar Singh
|
* @author Ashutosh Kumar Singh
|
||||||
* @version 2013/08/05
|
* @version 2013/08/05
|
||||||
* @since 2.5.0.1
|
* @since 2.5.0.1
|
||||||
*/
|
*/
|
||||||
public static class Convertor {
|
public static class Convertor {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Converts degree to direction.
|
* Converts degree to direction.
|
||||||
* @param degree
|
* <p>
|
||||||
|
* @param degree <p>
|
||||||
* @return Direction
|
* @return Direction
|
||||||
*
|
* <p>
|
||||||
* @throws IllegalArgumentException
|
* @throws IllegalArgumentException Degree should be between 0 and 360.
|
||||||
* Degree should be between 0 and 360.
|
|
||||||
*/
|
*/
|
||||||
public String convertDegree2Direction(float degree)
|
public String convertDegree2Direction(float degree)
|
||||||
throws IllegalArgumentException{
|
throws IllegalArgumentException {
|
||||||
String direction;
|
String direction;
|
||||||
|
|
||||||
// degree should be between 0 and 360
|
// degree should be between 0 and 360
|
||||||
if ((degree < 0.0f) || (degree > 360.0f)) {
|
if ((degree < 0.0f) || (degree > 360.0f)) {
|
||||||
throw new IllegalArgumentException("Degree cannot be less than 0 or more than 360.");
|
throw new IllegalArgumentException("Degree cannot be less than 0 or more than 360.");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (degree <= 11.25f) {
|
if (degree <= 11.25f) {
|
||||||
direction = "N";
|
direction = "N";
|
||||||
}
|
} else if (degree <= 33.75f) {
|
||||||
else if (degree <= 33.75f) {
|
|
||||||
direction = "NNE";
|
direction = "NNE";
|
||||||
}
|
} else if (degree <= 56.25f) {
|
||||||
else if (degree <= 56.25f) {
|
|
||||||
direction = "NE";
|
direction = "NE";
|
||||||
}
|
} else if (degree <= 78.75f) {
|
||||||
else if (degree <= 78.75f) {
|
|
||||||
direction = "ENE";
|
direction = "ENE";
|
||||||
}
|
} else if (degree <= 101.25f) {
|
||||||
else if (degree <= 101.25f) {
|
|
||||||
direction = "E";
|
direction = "E";
|
||||||
}
|
} else if (degree <= 123.75f) {
|
||||||
else if (degree <= 123.75f) {
|
|
||||||
direction = "ESE";
|
direction = "ESE";
|
||||||
}
|
} else if (degree <= 146.25f) {
|
||||||
else if (degree <= 146.25f) {
|
|
||||||
direction = "SE";
|
direction = "SE";
|
||||||
}
|
} else if (degree <= 168.75f) {
|
||||||
else if (degree <= 168.75f) {
|
|
||||||
direction = "SSE";
|
direction = "SSE";
|
||||||
}
|
} else if (degree <= 191.25f) {
|
||||||
else if (degree <= 191.25f) {
|
|
||||||
direction = "S";
|
direction = "S";
|
||||||
}
|
} else if (degree <= 213.75f) {
|
||||||
else if (degree <= 213.75f) {
|
|
||||||
direction = "SSW";
|
direction = "SSW";
|
||||||
}
|
} else if (degree <= 236.25f) {
|
||||||
else if (degree <= 236.25f) {
|
|
||||||
direction = "SW";
|
direction = "SW";
|
||||||
}
|
} else if (degree <= 258.75f) {
|
||||||
else if (degree <= 258.75f) {
|
|
||||||
direction = "WSW";
|
direction = "WSW";
|
||||||
}
|
} else if (degree <= 281.25f) {
|
||||||
else if (degree <= 281.25f) {
|
|
||||||
direction = "W";
|
direction = "W";
|
||||||
}
|
} else if (degree <= 303.75f) {
|
||||||
else if (degree <= 303.75f) {
|
|
||||||
direction = "WNW";
|
direction = "WNW";
|
||||||
}
|
} else if (degree <= 326.25f) {
|
||||||
else if (degree <= 326.25f) {
|
|
||||||
direction = "NW";
|
direction = "NW";
|
||||||
}
|
} else if (degree <= 348.75f) {
|
||||||
else if (degree <= 348.75f) {
|
|
||||||
direction = "NNW";
|
direction = "NNW";
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
direction = "N";
|
direction = "N";
|
||||||
}
|
}
|
||||||
|
|
||||||
return direction;
|
return direction;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue