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;
|
||||
|
||||
/**
|
||||
* This class provides default implementations for {@link net.aksingh.java.api.owm.CurrentWeatherData}
|
||||
* and {@link net.aksingh.java.api.owm.ForecastWeatherData} classes.
|
||||
* Standard behaviors like the <code>has</code> and the <code>get</code>
|
||||
* methods for information about weather or forecast (for example,
|
||||
* temperature, pressure, weather, clouds, wind, etc.) are defined here.
|
||||
*
|
||||
* This class provides default implementations for
|
||||
* {@link net.aksingh.java.api.owm.CurrentWeatherData} and
|
||||
* {@link net.aksingh.java.api.owm.ForecastWeatherData} classes. Standard
|
||||
* behaviors like the <code>has</code> and the <code>get</code> methods for
|
||||
* information about weather or forecast (for example, temperature, pressure,
|
||||
* weather, clouds, wind, etc.) are defined here.
|
||||
* <p>
|
||||
* @author Ashutosh Kumar Singh
|
||||
* @version 2013/07/26
|
||||
* @since 2.5.0.1
|
||||
*/
|
||||
abstract public class AbstractWeatherData {
|
||||
/** Key for JSON object - Clouds */
|
||||
protected final String JSON_CLOUDS = "clouds";
|
||||
/** Key for JSON object - Coordinates (Geographic coordinates) */
|
||||
protected final String JSON_COORD = "coord";
|
||||
/** Key for JSON object - Main (Temperature, pressure, etc.) */
|
||||
protected final String JSON_MAIN = "main";
|
||||
/** Key for JSON array - Weather (Weather name, description, etc.) */
|
||||
protected final String JSON_WEATHER = "weather";
|
||||
/** Key for JSON object - Wind */
|
||||
protected final String JSON_WIND = "wind";
|
||||
|
||||
/**
|
||||
* Key for JSON object - Clouds
|
||||
*/
|
||||
protected final String JSON_CLOUDS = "clouds";
|
||||
/**
|
||||
* Key for JSON object - Coordinates (Geographic coordinates)
|
||||
*/
|
||||
protected final String JSON_COORD = "coord";
|
||||
/**
|
||||
* Key for JSON object - Main (Temperature, pressure, etc.)
|
||||
*/
|
||||
protected final String JSON_MAIN = "main";
|
||||
/**
|
||||
* Key for JSON array - Weather (Weather name, description, etc.)
|
||||
*/
|
||||
protected final String JSON_WEATHER = "weather";
|
||||
/**
|
||||
* Key for JSON object - Wind
|
||||
*/
|
||||
protected final String JSON_WIND = "wind";
|
||||
|
||||
/*
|
||||
************************
|
||||
* Defining sub-classes
|
||||
************************
|
||||
*/
|
||||
|
||||
/**
|
||||
* This class provides default implementations for <code>Clouds</code>.
|
||||
* Standard behaviors like the <code>has</code> and the <code>get</code>
|
||||
* methods for information about clouds (for example, percentage of
|
||||
* clouds, etc.) are defined here.
|
||||
*
|
||||
* methods for information about clouds (for example, percentage of clouds,
|
||||
* etc.) are defined here.
|
||||
* <p>
|
||||
* @author Ashutosh Kumar Singh
|
||||
* @version 2013/07/27
|
||||
* @since 2.5.0.1
|
||||
*/
|
||||
abstract public static class Clouds {
|
||||
|
||||
/**
|
||||
* Key for JSON variable <code>Clouds -> All</code>
|
||||
* (percentage of all clouds)
|
||||
* Key for JSON variable <code>Clouds -> All</code> (percentage of all
|
||||
* clouds)
|
||||
*/
|
||||
private final String JSON_CLOUDS_ALL = "all";
|
||||
|
||||
/** Percentage of all clouds */
|
||||
/**
|
||||
* Percentage of all clouds
|
||||
*/
|
||||
private final float percentOfClouds;
|
||||
|
||||
/**
|
||||
* Non-parameterized constructor
|
||||
*
|
||||
* <p>Initializes variables as per following basis:<br>
|
||||
* <p>
|
||||
* <p>
|
||||
* Initializes variables as per following basis:<br>
|
||||
* Boolean: <code>false</code><br>
|
||||
* Integral: Minimum value (MIN_VALUE)<br>
|
||||
* Floating point: Not a number (NaN)<br>
|
||||
|
@ -89,9 +103,9 @@ abstract public class AbstractWeatherData {
|
|||
|
||||
/**
|
||||
* Parameterized constructor
|
||||
*
|
||||
* <p>
|
||||
* Initializes variables from values from the given JSON object.
|
||||
*
|
||||
* <p>
|
||||
* @param jsonObj JSON object containing data about clouds
|
||||
*/
|
||||
public Clouds(JSONObject jsonObj) {
|
||||
|
@ -100,7 +114,9 @@ abstract public class AbstractWeatherData {
|
|||
|
||||
/**
|
||||
* 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() {
|
||||
return (this.percentOfClouds != Float.NaN);
|
||||
|
@ -108,39 +124,49 @@ abstract public class AbstractWeatherData {
|
|||
|
||||
/**
|
||||
* Returns data for percentage of all clouds.
|
||||
* @return Percentage of all clouds if available,
|
||||
* otherwise <code>Float.NaN</code>, i.e., Not a Number.
|
||||
* <p>
|
||||
* @return Percentage of all clouds if available, otherwise
|
||||
* <code>Float.NaN</code>, i.e., Not a Number.
|
||||
*/
|
||||
public float getPercentageOfClouds() {
|
||||
return this.percentOfClouds;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* This class provides default implementations for <code>Coord</code>.
|
||||
* Standard behaviors like the <code>has</code> and the <code>get</code>
|
||||
* methods for information about geographic coordinates (latitude
|
||||
* and longitude) are defined here.
|
||||
*
|
||||
* methods for information about geographic coordinates (latitude and
|
||||
* longitude) are defined here.
|
||||
* <p>
|
||||
* @author Ashutosh Kumar Singh
|
||||
* @version 2013/07/28
|
||||
*/
|
||||
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";
|
||||
/** Key for JSON variable <code>Coord -> Longitude</code> */
|
||||
/**
|
||||
* Key for JSON variable <code>Coord -> Longitude</code>
|
||||
*/
|
||||
private final String JSON_COORD_LONGITUDE = "lon";
|
||||
|
||||
/** Latitude */
|
||||
/**
|
||||
* Latitude
|
||||
*/
|
||||
private final float lat;
|
||||
/** Longitude */
|
||||
/**
|
||||
* Longitude
|
||||
*/
|
||||
private final float lon;
|
||||
|
||||
/**
|
||||
* Non-parameterized constructor
|
||||
*
|
||||
* <p>Initializes variables as per following basis:<br>
|
||||
* <p>
|
||||
* <p>
|
||||
* Initializes variables as per following basis:<br>
|
||||
* Boolean: <code>false</code><br>
|
||||
* Integral: Minimum value (MIN_VALUE)<br>
|
||||
* Floating point: Not a number (NaN)<br>
|
||||
|
@ -153,9 +179,9 @@ abstract public class AbstractWeatherData {
|
|||
|
||||
/**
|
||||
* Parameterized constructor
|
||||
*
|
||||
* <p>
|
||||
* Initializes variables from values from the given JSON object.
|
||||
*
|
||||
* <p>
|
||||
* @param jsonObj JSON object containing data about coordinates
|
||||
*/
|
||||
public Coord(JSONObject jsonObj) {
|
||||
|
@ -165,7 +191,9 @@ abstract public class AbstractWeatherData {
|
|||
|
||||
/**
|
||||
* 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() {
|
||||
return (this.lat != Float.NaN);
|
||||
|
@ -173,7 +201,9 @@ abstract public class AbstractWeatherData {
|
|||
|
||||
/**
|
||||
* 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() {
|
||||
return (this.lon != Float.NaN);
|
||||
|
@ -181,8 +211,9 @@ abstract public class AbstractWeatherData {
|
|||
|
||||
/**
|
||||
* Returns data for latitude of the city.
|
||||
* @return Latitude of the city if available,
|
||||
* otherwise <code>Float.NaN</code>, i.e., Not a Number.
|
||||
* <p>
|
||||
* @return Latitude of the city if available, otherwise
|
||||
* <code>Float.NaN</code>, i.e., Not a Number.
|
||||
*/
|
||||
public float getLatitude() {
|
||||
return this.lat;
|
||||
|
@ -190,52 +221,74 @@ abstract public class AbstractWeatherData {
|
|||
|
||||
/**
|
||||
* Returns data for longitude of the city.
|
||||
* @return Longitude of the city if available,
|
||||
* otherwise <code>Float.NaN</code>, i.e., Not a Number.
|
||||
* <p>
|
||||
* @return Longitude of the city if available, otherwise
|
||||
* <code>Float.NaN</code>, i.e., Not a Number.
|
||||
*/
|
||||
public float getLongitude() {
|
||||
return this.lon;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* This class provides default implementations for <code>Main</code>.
|
||||
* Standard behaviors like the <code>has</code> and the <code>get</code>
|
||||
* methods for information about main weather elements (for example,
|
||||
* temperature, pressure, humidity, etc.) are defined here.
|
||||
*
|
||||
* <p>
|
||||
* @author Ashutosh Kumar Singh
|
||||
* @version 2013/07/28
|
||||
* @since 2.5.0.1
|
||||
*/
|
||||
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";
|
||||
/** 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";
|
||||
/** 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";
|
||||
/** Key for JSON variable <code>Main -> Pressure</code> */
|
||||
/**
|
||||
* Key for JSON variable <code>Main -> Pressure</code>
|
||||
*/
|
||||
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";
|
||||
|
||||
/** Temperature */
|
||||
/**
|
||||
* Temperature
|
||||
*/
|
||||
private final float temp;
|
||||
/** Minimum temperature */
|
||||
/**
|
||||
* Minimum temperature
|
||||
*/
|
||||
private final float minTemp;
|
||||
/** Maximum temperature */
|
||||
/**
|
||||
* Maximum temperature
|
||||
*/
|
||||
private final float maxTemp;
|
||||
/** Pressure */
|
||||
/**
|
||||
* Pressure
|
||||
*/
|
||||
private final float pressure;
|
||||
/** Humidity */
|
||||
/**
|
||||
* Humidity
|
||||
*/
|
||||
private final float humidity;
|
||||
|
||||
/**
|
||||
* Non-parameterized constructor
|
||||
*
|
||||
* <p>Initializes variables as per following basis:<br>
|
||||
* <p>
|
||||
* <p>
|
||||
* Initializes variables as per following basis:<br>
|
||||
* Boolean: <code>false</code><br>
|
||||
* Integral: Minimum value (MIN_VALUE)<br>
|
||||
* Floating point: Not a number (NaN)<br>
|
||||
|
@ -251,9 +304,9 @@ abstract public class AbstractWeatherData {
|
|||
|
||||
/**
|
||||
* Parameterized constructor
|
||||
*
|
||||
* <p>
|
||||
* Initializes variables from values from the given JSON object.
|
||||
*
|
||||
* <p>
|
||||
* @param jsonObj JSON object containing data about main weather
|
||||
* elements. For example, temperature, pressure, etc.
|
||||
*/
|
||||
|
@ -267,23 +320,31 @@ abstract public class AbstractWeatherData {
|
|||
|
||||
/**
|
||||
* 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() {
|
||||
return (this.temp != Float.NaN);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tells if the data for minimum temperature of the city is available or not.
|
||||
* @return <code>true</code> if data available, otherwise <code>false</code>
|
||||
* Tells if the data for minimum temperature of the city is available or
|
||||
* not.
|
||||
* <p>
|
||||
* @return <code>true</code> if data available, otherwise
|
||||
* <code>false</code>
|
||||
*/
|
||||
public boolean hasMinTemperature() {
|
||||
return (this.minTemp != Float.NaN);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tells if the data for maximum temperature of the city is available or not.
|
||||
* @return <code>true</code> if data available, otherwise <code>false</code>
|
||||
* Tells if the data for maximum temperature of the city is available or
|
||||
* not.
|
||||
* <p>
|
||||
* @return <code>true</code> if data available, otherwise
|
||||
* <code>false</code>
|
||||
*/
|
||||
public boolean hasMaxTemperature() {
|
||||
return (this.maxTemp != Float.NaN);
|
||||
|
@ -291,7 +352,9 @@ abstract public class AbstractWeatherData {
|
|||
|
||||
/**
|
||||
* 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() {
|
||||
return (this.pressure != Float.NaN);
|
||||
|
@ -299,7 +362,9 @@ abstract public class AbstractWeatherData {
|
|||
|
||||
/**
|
||||
* 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() {
|
||||
return (this.humidity != Float.NaN);
|
||||
|
@ -307,8 +372,9 @@ abstract public class AbstractWeatherData {
|
|||
|
||||
/**
|
||||
* Returns data for temperature of the city.
|
||||
* @return Temperature of the city if available,
|
||||
* otherwise <code>Float.NaN</code>, i.e., Not a Number.
|
||||
* <p>
|
||||
* @return Temperature of the city if available, otherwise
|
||||
* <code>Float.NaN</code>, i.e., Not a Number.
|
||||
*/
|
||||
public float getTemperature() {
|
||||
return this.temp;
|
||||
|
@ -316,8 +382,9 @@ abstract public class AbstractWeatherData {
|
|||
|
||||
/**
|
||||
* Returns data for minimum temperature of the city.
|
||||
* @return Minimum temperature of the city if available,
|
||||
* otherwise <code>Float.NaN</code>, i.e., Not a Number.
|
||||
* <p>
|
||||
* @return Minimum temperature of the city if available, otherwise
|
||||
* <code>Float.NaN</code>, i.e., Not a Number.
|
||||
*/
|
||||
public float getMinTemperature() {
|
||||
return this.minTemp;
|
||||
|
@ -325,8 +392,9 @@ abstract public class AbstractWeatherData {
|
|||
|
||||
/**
|
||||
* Returns data for maximum temperature of the city.
|
||||
* @return Maximum temperature of the city if available,
|
||||
* otherwise <code>Float.NaN</code>, i.e., Not a Number.
|
||||
* <p>
|
||||
* @return Maximum temperature of the city if available, otherwise
|
||||
* <code>Float.NaN</code>, i.e., Not a Number.
|
||||
*/
|
||||
public float getMaxTemperature() {
|
||||
return this.maxTemp;
|
||||
|
@ -334,8 +402,9 @@ abstract public class AbstractWeatherData {
|
|||
|
||||
/**
|
||||
* Returns data for pressure of the city.
|
||||
* @return Pressure of the city if available,
|
||||
* otherwise <code>Float.NaN</code>, i.e., Not a Number.
|
||||
* <p>
|
||||
* @return Pressure of the city if available, otherwise
|
||||
* <code>Float.NaN</code>, i.e., Not a Number.
|
||||
*/
|
||||
public float getPressure() {
|
||||
return this.pressure;
|
||||
|
@ -343,48 +412,67 @@ abstract public class AbstractWeatherData {
|
|||
|
||||
/**
|
||||
* Returns data for humidity of the city.
|
||||
* @return Humidity of the city if available,
|
||||
* otherwise <code>Float.NaN</code>, i.e., Not a Number.
|
||||
* <p>
|
||||
* @return Humidity of the city if available, otherwise
|
||||
* <code>Float.NaN</code>, i.e., Not a Number.
|
||||
*/
|
||||
public float getHumidity() {
|
||||
return this.humidity;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* This class provides default implementations for <code>Weather</code>.
|
||||
* Standard behaviors like the <code>has</code> and the <code>get</code>
|
||||
* methods for information about weather (for example, id, name,
|
||||
* description, icon, etc.) are defined here.
|
||||
*
|
||||
* <p>
|
||||
* @author Ashutosh Kumar Singh
|
||||
* @version 2013/07/28
|
||||
* @since 2.5.0.1
|
||||
*/
|
||||
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";
|
||||
/** 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";
|
||||
/** Key for JSON variable <code>Weather -> Description</code> */
|
||||
/**
|
||||
* Key for JSON variable <code>Weather -> Description</code>
|
||||
*/
|
||||
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";
|
||||
|
||||
/** Weather ID */
|
||||
/**
|
||||
* Weather ID
|
||||
*/
|
||||
private final int id;
|
||||
/** Weather name */
|
||||
/**
|
||||
* Weather name
|
||||
*/
|
||||
private final String name;
|
||||
/** Weather description */
|
||||
/**
|
||||
* Weather description
|
||||
*/
|
||||
private final String description;
|
||||
/** Weather icon */
|
||||
/**
|
||||
* Weather icon
|
||||
*/
|
||||
private final String icon;
|
||||
|
||||
/**
|
||||
* Non-parameterized constructor
|
||||
*
|
||||
* <p>Initializes variables as per following basis:<br>
|
||||
* <p>
|
||||
* <p>
|
||||
* Initializes variables as per following basis:<br>
|
||||
* Boolean: <code>false</code><br>
|
||||
* Integral: Minimum value (MIN_VALUE)<br>
|
||||
* Floating point: Not a number (NaN)<br>
|
||||
|
@ -399,10 +487,11 @@ abstract public class AbstractWeatherData {
|
|||
|
||||
/**
|
||||
* Parameterized constructor
|
||||
*
|
||||
* <p>
|
||||
* Initializes variables from values from the given JSON object.
|
||||
*
|
||||
* @param jsonObj JSON object containing data about weather id, name, etc.
|
||||
* <p>
|
||||
* @param jsonObj JSON object containing data about weather id, name,
|
||||
* etc.
|
||||
*/
|
||||
public Weather(JSONObject jsonObj) {
|
||||
this.id = jsonObj.optInt(this.JSON_WEATHER_ID, Integer.MIN_VALUE);
|
||||
|
@ -413,7 +502,9 @@ abstract public class AbstractWeatherData {
|
|||
|
||||
/**
|
||||
* 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() {
|
||||
return (this.id != Integer.MIN_VALUE);
|
||||
|
@ -421,7 +512,9 @@ abstract public class AbstractWeatherData {
|
|||
|
||||
/**
|
||||
* 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() {
|
||||
return (this.name != null);
|
||||
|
@ -429,7 +522,9 @@ abstract public class AbstractWeatherData {
|
|||
|
||||
/**
|
||||
* 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() {
|
||||
return (this.description != null);
|
||||
|
@ -437,7 +532,9 @@ abstract public class AbstractWeatherData {
|
|||
|
||||
/**
|
||||
* 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() {
|
||||
return (this.icon != null);
|
||||
|
@ -445,8 +542,9 @@ abstract public class AbstractWeatherData {
|
|||
|
||||
/**
|
||||
* Returns data for code for weather of the city.
|
||||
* @return Code for weather of the city if available,
|
||||
* otherwise <code>Integer.MIN_VALUE</code>
|
||||
* <p>
|
||||
* @return Code for weather of the city if available, otherwise
|
||||
* <code>Integer.MIN_VALUE</code>
|
||||
*/
|
||||
public int getWeatherCode() {
|
||||
return this.id;
|
||||
|
@ -454,8 +552,9 @@ abstract public class AbstractWeatherData {
|
|||
|
||||
/**
|
||||
* Returns data for name for weather of the city.
|
||||
* @return Name for weather of the city if available,
|
||||
* otherwise <code>null</code>
|
||||
* <p>
|
||||
* @return Name for weather of the city if available, otherwise
|
||||
* <code>null</code>
|
||||
*/
|
||||
public String getWeatherName() {
|
||||
return this.name;
|
||||
|
@ -463,8 +562,9 @@ abstract public class AbstractWeatherData {
|
|||
|
||||
/**
|
||||
* Returns data for description for weather of the city.
|
||||
* @return Description for weather of the city if available,
|
||||
* otherwise <code>null</code>
|
||||
* <p>
|
||||
* @return Description for weather of the city if available, otherwise
|
||||
* <code>null</code>
|
||||
*/
|
||||
public String getWeatherDescription() {
|
||||
return this.description;
|
||||
|
@ -472,40 +572,50 @@ abstract public class AbstractWeatherData {
|
|||
|
||||
/**
|
||||
* Returns data for name of icon for weather of the city.
|
||||
* @return Name of icon for weather of the city if available,
|
||||
* otherwise <code>null</code>
|
||||
* <p>
|
||||
* @return Name of icon for weather of the city if available, otherwise
|
||||
* <code>null</code>
|
||||
*/
|
||||
public String getWeatherIconName() {
|
||||
return this.icon;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* This class provides default implementations for <code>Wind</code>.
|
||||
* Standard behaviors like the <code>has</code> and the <code>get</code>
|
||||
* methods for information about wind (for example, speed, degree,
|
||||
* etc.) are defined here.
|
||||
*
|
||||
* methods for information about wind (for example, speed, degree, etc.) are
|
||||
* defined here.
|
||||
* <p>
|
||||
* @author Ashutosh Kumar Singh
|
||||
* @version 2013/07/28
|
||||
* @since 2.5.0.1
|
||||
*/
|
||||
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";
|
||||
/** Key for JSON variable <code>Wind -> Degree</code> */
|
||||
/**
|
||||
* Key for JSON variable <code>Wind -> Degree</code>
|
||||
*/
|
||||
private final String JSON_WIND_DEGREE = "deg";
|
||||
|
||||
/** Wind speed */
|
||||
/**
|
||||
* Wind speed
|
||||
*/
|
||||
private final float speed;
|
||||
/** Wind degree (direction of wind) */
|
||||
/**
|
||||
* Wind degree (direction of wind)
|
||||
*/
|
||||
private final float degree;
|
||||
|
||||
/**
|
||||
* Non-parameterized constructor
|
||||
*
|
||||
* <p>Initializes variables as per following basis:<br>
|
||||
* <p>
|
||||
* <p>
|
||||
* Initializes variables as per following basis:<br>
|
||||
* Boolean: <code>false</code><br>
|
||||
* Integral: Minimum value (MIN_VALUE)<br>
|
||||
* Floating point: Not a number (NaN)<br>
|
||||
|
@ -518,9 +628,9 @@ abstract public class AbstractWeatherData {
|
|||
|
||||
/**
|
||||
* Parameterized constructor
|
||||
*
|
||||
* <p>
|
||||
* Initializes variables from values from the given JSON object.
|
||||
*
|
||||
* <p>
|
||||
* @param jsonObj JSON object containing data about wind
|
||||
*/
|
||||
public Wind(JSONObject jsonObj) {
|
||||
|
@ -530,16 +640,20 @@ abstract public class AbstractWeatherData {
|
|||
|
||||
/**
|
||||
* 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() {
|
||||
return (this.speed != Float.NaN);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tells if the data for degree (degree gives direction) of wind
|
||||
* in the city is available or not.
|
||||
* @return <code>true</code> if data available, otherwise <code>false</code>
|
||||
* Tells if the data for degree (degree gives direction) of wind in the
|
||||
* city is available or not.
|
||||
* <p>
|
||||
* @return <code>true</code> if data available, otherwise
|
||||
* <code>false</code>
|
||||
*/
|
||||
public boolean hasWindDegree() {
|
||||
return (this.hasWindSpeed() && (this.degree != Float.NaN));
|
||||
|
@ -547,8 +661,9 @@ abstract public class AbstractWeatherData {
|
|||
|
||||
/**
|
||||
* Returns data for speed of wind in the city.
|
||||
* @return Speed of wind in the city if available,
|
||||
* otherwise <code>Float.NaN</code>, i.e., Not a Number.
|
||||
* <p>
|
||||
* @return Speed of wind in the city if available, otherwise
|
||||
* <code>Float.NaN</code>, i.e., Not a Number.
|
||||
*/
|
||||
public float getWindSpeed() {
|
||||
return this.speed;
|
||||
|
@ -556,34 +671,36 @@ abstract public class AbstractWeatherData {
|
|||
|
||||
/**
|
||||
* Returns data for degree of wind in the city.
|
||||
* @return Degree of wind in the city if available,
|
||||
* otherwise <code>Float.NaN</code>, i.e., Not a Number.
|
||||
* <p>
|
||||
* @return Degree of wind in the city if available, otherwise
|
||||
* <code>Float.NaN</code>, i.e., Not a Number.
|
||||
*/
|
||||
public float getWindDegree() {
|
||||
return this.degree;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
***********************
|
||||
* Declaring this class
|
||||
***********************
|
||||
*/
|
||||
|
||||
/** Key for JSON variable Date-Time (date & time of the weather) */
|
||||
/**
|
||||
* 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
|
||||
* when is/will be this weather.
|
||||
* Date and time of the weather. This is answer for the question that when
|
||||
* is/will be this weather.
|
||||
*/
|
||||
private final Date dateTime;
|
||||
|
||||
/**
|
||||
* Non-parameterized constructor
|
||||
*
|
||||
* <p>Initializes variables as per following basis:<br>
|
||||
* <p>
|
||||
* <p>
|
||||
* Initializes variables as per following basis:<br>
|
||||
* Boolean: <code>false</code><br>
|
||||
* Integral: Minimum value (MIN_VALUE)<br>
|
||||
* Floating point: Not a number (NaN)<br>
|
||||
|
@ -595,9 +712,9 @@ abstract public class AbstractWeatherData {
|
|||
|
||||
/**
|
||||
* Parameterized constructor
|
||||
*
|
||||
* <p>
|
||||
* Initializes variables from values from the given JSON object.
|
||||
*
|
||||
* <p>
|
||||
* @param jsonObj JSON object containing weather data
|
||||
*/
|
||||
public AbstractWeatherData(JSONObject jsonObj) {
|
||||
|
@ -621,6 +738,7 @@ abstract public class AbstractWeatherData {
|
|||
|
||||
/**
|
||||
* 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>
|
||||
*/
|
||||
public boolean hasDateTime() {
|
||||
|
@ -629,6 +747,7 @@ abstract public class AbstractWeatherData {
|
|||
|
||||
/**
|
||||
* Returns data for date and time of this weather.
|
||||
* <p>
|
||||
* @return Date and time (in object of {@link java.util.Date}) if available,
|
||||
* otherwise <code>null</code>
|
||||
*/
|
||||
|
|
|
@ -29,58 +29,62 @@ import org.json.JSONArray;
|
|||
import org.json.JSONObject;
|
||||
|
||||
/**
|
||||
* Parses current weather data (from the JSON data) and provides methods
|
||||
* to get/access the information about current weather.
|
||||
* 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
|
||||
* 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
|
||||
* exists, otherwise <code>get</code> methods will give value as per
|
||||
* following basis:<br>
|
||||
* Parses current weather data (from the JSON data) and provides methods to
|
||||
* get/access the information about current weather. 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>
|
||||
* Boolean: <code>false</code><br>
|
||||
* Integral: Minimum value (MIN_VALUE)<br>
|
||||
* Floating point: Not a number (NaN)<br>
|
||||
* Others: <code>null</code><br>
|
||||
*
|
||||
* <p>
|
||||
* @author Ashutosh Kumar Singh
|
||||
* @version 2013/08/07
|
||||
* @since 2.5.0.1
|
||||
*/
|
||||
public class CurrentWeatherData extends AbstractWeatherData {
|
||||
/** Key for JSON object - Rain */
|
||||
private final String JSON_RAIN = "rain";
|
||||
/** Key for JSON object - Sys */
|
||||
private final String JSON_SYS = "sys";
|
||||
|
||||
/**
|
||||
* Key for JSON object - Rain
|
||||
*/
|
||||
private final String JSON_RAIN = "rain";
|
||||
/**
|
||||
* Key for JSON object - Sys
|
||||
*/
|
||||
private final String JSON_SYS = "sys";
|
||||
|
||||
/*
|
||||
************************
|
||||
* Declaring sub-classes
|
||||
************************
|
||||
*/
|
||||
|
||||
/**
|
||||
* Parses data about clouds (from the JSON data) and provides methods
|
||||
* to get/access the information.
|
||||
* 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
|
||||
* 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 clouds (from the JSON data) and provides methods to
|
||||
* get/access the information. 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>
|
||||
* Boolean: <code>false</code><br>
|
||||
* Integral: Minimum value (MIN_VALUE)<br>
|
||||
* Floating point: Not a number (NaN)<br>
|
||||
* Others: <code>null</code><br>
|
||||
*
|
||||
* <p>
|
||||
* @author Ashutosh Kumar Singh
|
||||
* @version 2013/08/07
|
||||
* @since 2.5.0.1
|
||||
|
@ -89,8 +93,9 @@ public class CurrentWeatherData extends AbstractWeatherData {
|
|||
|
||||
/**
|
||||
* Non-parameterized constructor
|
||||
*
|
||||
* <p>Initializes variables as per following basis:<br>
|
||||
* <p>
|
||||
* <p>
|
||||
* Initializes variables as per following basis:<br>
|
||||
* Boolean: <code>false</code><br>
|
||||
* Integral: Minimum value (MIN_VALUE)<br>
|
||||
* Floating point: Not a number (NaN)<br>
|
||||
|
@ -102,9 +107,9 @@ public class CurrentWeatherData extends AbstractWeatherData {
|
|||
|
||||
/**
|
||||
* Parameterized constructor
|
||||
*
|
||||
* <p>
|
||||
* Initializes variables from values from the given JSON object.
|
||||
*
|
||||
* <p>
|
||||
* @param jsonObj JSON object containing data about clouds
|
||||
*/
|
||||
public Clouds(JSONObject jsonObj) {
|
||||
|
@ -112,25 +117,25 @@ public class CurrentWeatherData extends AbstractWeatherData {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Parses data about geographic coordinates (from the JSON data)
|
||||
* and provides methods to get/access the information.
|
||||
* 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
|
||||
* 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 geographic coordinates (from the JSON data) and
|
||||
* provides methods to get/access the information. 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>
|
||||
* Boolean: <code>false</code><br>
|
||||
* Integral: Minimum value (MIN_VALUE)<br>
|
||||
* Floating point: Not a number (NaN)<br>
|
||||
* Others: <code>null</code><br>
|
||||
*
|
||||
* <p>
|
||||
* @author Ashutosh Kumar Singh
|
||||
* @version 2013/08/07
|
||||
* @since 2.5.0.1
|
||||
|
@ -139,8 +144,9 @@ public class CurrentWeatherData extends AbstractWeatherData {
|
|||
|
||||
/**
|
||||
* Non-parameterized constructor
|
||||
*
|
||||
* <p>Initializes variables as per following basis:<br>
|
||||
* <p>
|
||||
* <p>
|
||||
* Initializes variables as per following basis:<br>
|
||||
* Boolean: <code>false</code><br>
|
||||
* Integral: Minimum value (MIN_VALUE)<br>
|
||||
* Floating point: Not a number (NaN)<br>
|
||||
|
@ -152,9 +158,9 @@ public class CurrentWeatherData extends AbstractWeatherData {
|
|||
|
||||
/**
|
||||
* Parameterized constructor
|
||||
*
|
||||
* <p>
|
||||
* Initializes variables from values from the given JSON object.
|
||||
*
|
||||
* <p>
|
||||
* @param jsonObj JSON object containing data about coordinates
|
||||
*/
|
||||
public Coord(JSONObject jsonObj) {
|
||||
|
@ -162,25 +168,25 @@ public class CurrentWeatherData extends AbstractWeatherData {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Parses data about main weather elements (from the JSON data) and
|
||||
* provides methods to get/access the information.
|
||||
* 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
|
||||
* 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 main weather elements (from the JSON data) and provides
|
||||
* methods to get/access the information. 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>
|
||||
* Boolean: <code>false</code><br>
|
||||
* Integral: Minimum value (MIN_VALUE)<br>
|
||||
* Floating point: Not a number (NaN)<br>
|
||||
* Others: <code>null</code><br>
|
||||
*
|
||||
* <p>
|
||||
* @author Ashutosh Kumar Singh
|
||||
* @version 2013/08/07
|
||||
* @since 2.5.0.1
|
||||
|
@ -189,8 +195,9 @@ public class CurrentWeatherData extends AbstractWeatherData {
|
|||
|
||||
/**
|
||||
* Non-parameterized constructor
|
||||
*
|
||||
* <p>Initializes variables as per following basis:<br>
|
||||
* <p>
|
||||
* <p>
|
||||
* Initializes variables as per following basis:<br>
|
||||
* Boolean: <code>false</code><br>
|
||||
* Integral: Minimum value (MIN_VALUE)<br>
|
||||
* Floating point: Not a number (NaN)<br>
|
||||
|
@ -202,51 +209,57 @@ public class CurrentWeatherData extends AbstractWeatherData {
|
|||
|
||||
/**
|
||||
* Parameterized constructor
|
||||
*
|
||||
* <p>
|
||||
* Initializes variables from values from the given JSON object.
|
||||
*
|
||||
* @param jsonObj JSON object containing data about main
|
||||
* weather elements (temperature, pressure, etc.)
|
||||
* <p>
|
||||
* @param jsonObj JSON object containing data about main weather
|
||||
* elements (temperature, pressure, etc.)
|
||||
*/
|
||||
public Main(JSONObject jsonObj) {
|
||||
super(jsonObj);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Parses data about rain (from the JSON data) and provides methods
|
||||
* to get/access the information.
|
||||
* 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
|
||||
* 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 rain (from the JSON data) and provides methods to
|
||||
* get/access the information. 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>
|
||||
* Boolean: <code>false</code><br>
|
||||
* Integral: Minimum value (MIN_VALUE)<br>
|
||||
* Floating point: Not a number (NaN)<br>
|
||||
* Others: <code>null</code><br>
|
||||
*
|
||||
* <p>
|
||||
* @author Ashutosh Kumar Singh
|
||||
* @version 2013/08/07
|
||||
* @since 2.5.0.1
|
||||
*/
|
||||
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";
|
||||
|
||||
/** Rain per 3 hours */
|
||||
/**
|
||||
* Rain per 3 hours
|
||||
*/
|
||||
private final float rain3h;
|
||||
|
||||
/**
|
||||
* Non-parameterized constructor
|
||||
*
|
||||
* <p>Initializes variables as per following basis:<br>
|
||||
* <p>
|
||||
* <p>
|
||||
* Initializes variables as per following basis:<br>
|
||||
* Boolean: <code>false</code><br>
|
||||
* Integral: Minimum value (MIN_VALUE)<br>
|
||||
* Floating point: Not a number (NaN)<br>
|
||||
|
@ -258,9 +271,9 @@ public class CurrentWeatherData extends AbstractWeatherData {
|
|||
|
||||
/**
|
||||
* Parameterized constructor
|
||||
*
|
||||
* <p>
|
||||
* Initializes variables from values from the given JSON object.
|
||||
*
|
||||
* <p>
|
||||
* @param jsonObj JSON object containing data about rain
|
||||
*/
|
||||
public Rain(JSONObject jsonObj) {
|
||||
|
@ -276,48 +289,62 @@ public class CurrentWeatherData extends AbstractWeatherData {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Parses data about country, sunrise, and sunset (from the JSON data)
|
||||
* and provides methods to get/access the information.
|
||||
* 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
|
||||
* 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 country, sunrise, and sunset (from the JSON data) and
|
||||
* provides methods to get/access the information. 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>
|
||||
* Boolean: <code>false</code><br>
|
||||
* Integral: Minimum value (MIN_VALUE)<br>
|
||||
* Floating point: Not a number (NaN)<br>
|
||||
* Others: <code>null</code><br>
|
||||
*
|
||||
* <p>
|
||||
* @author Ashutosh Kumar Singh
|
||||
* @version 2013/08/07
|
||||
* @since 2.5.0.1
|
||||
*/
|
||||
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";
|
||||
/** Key for JSON variable <code>Sys -> Sunrise</code> */
|
||||
/**
|
||||
* Key for JSON variable <code>Sys -> Sunrise</code>
|
||||
*/
|
||||
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";
|
||||
|
||||
/** Country code for the city */
|
||||
/**
|
||||
* Country code for the city
|
||||
*/
|
||||
private final String countryCode;
|
||||
/** Sunrise time */
|
||||
/**
|
||||
* Sunrise time
|
||||
*/
|
||||
private final Date sunrise;
|
||||
/** Sunset time */
|
||||
/**
|
||||
* Sunset time
|
||||
*/
|
||||
private final Date sunset;
|
||||
|
||||
/**
|
||||
* Non-parameterized constructor
|
||||
*
|
||||
* <p>Initializes variables as per following basis:<br>
|
||||
* <p>
|
||||
* <p>
|
||||
* Initializes variables as per following basis:<br>
|
||||
* Boolean: <code>false</code><br>
|
||||
* Integral: Minimum value (MIN_VALUE)<br>
|
||||
* Floating point: Not a number (NaN)<br>
|
||||
|
@ -331,9 +358,9 @@ public class CurrentWeatherData extends AbstractWeatherData {
|
|||
|
||||
/**
|
||||
* Parameterized constructor
|
||||
*
|
||||
* <p>
|
||||
* Initializes variables from values from the given JSON object.
|
||||
*
|
||||
* <p>
|
||||
* @param jsonObj JSON object containing data about country, sunrise,
|
||||
* and sunset.
|
||||
*/
|
||||
|
@ -342,14 +369,28 @@ public class CurrentWeatherData extends AbstractWeatherData {
|
|||
|
||||
long sr_secs = jsonObj.optLong(this.JSON_SYS_SUNRISE, 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 {
|
||||
this.sunrise = null;
|
||||
}
|
||||
|
||||
long ss_secs = jsonObj.optLong(this.JSON_SYS_SUNSET, 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 {
|
||||
this.sunset = null;
|
||||
}
|
||||
|
@ -380,25 +421,25 @@ public class CurrentWeatherData extends AbstractWeatherData {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Parses data about weather code, name, etc. (from the JSON data)
|
||||
* and provides methods to get/access the information.
|
||||
* 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
|
||||
* 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 code, name, etc. (from the JSON data) and
|
||||
* provides methods to get/access the information. 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>
|
||||
* Boolean: <code>false</code><br>
|
||||
* Integral: Minimum value (MIN_VALUE)<br>
|
||||
* Floating point: Not a number (NaN)<br>
|
||||
* Others: <code>null</code><br>
|
||||
*
|
||||
* <p>
|
||||
* @author Ashutosh Kumar Singh
|
||||
* @version 2013/08/07
|
||||
* @since 2.5.0.1
|
||||
|
@ -407,83 +448,91 @@ public class CurrentWeatherData extends AbstractWeatherData {
|
|||
|
||||
/**
|
||||
* Non-parameterized constructor
|
||||
*
|
||||
* <p>Initializes variables as per following basis:<br>
|
||||
* <p>
|
||||
* <p>
|
||||
* Initializes variables as per following basis:<br>
|
||||
* Boolean: <code>false</code><br>
|
||||
* Integral: Minimum value (MIN_VALUE)<br>
|
||||
* Floating point: Not a number (NaN)<br>
|
||||
* Others: <code>null</code><br>
|
||||
*/
|
||||
public Weather () {
|
||||
public Weather() {
|
||||
super();
|
||||
}
|
||||
|
||||
/**
|
||||
* Parameterized constructor
|
||||
*
|
||||
* <p>
|
||||
* Initializes variables from values from the given JSON object.
|
||||
*
|
||||
* @param jsonObj JSON object containing data about weather id, name, etc.
|
||||
* <p>
|
||||
* @param jsonObj JSON object containing data about weather id, name,
|
||||
* etc.
|
||||
*/
|
||||
public Weather (JSONObject jsonObj) {
|
||||
public Weather(JSONObject jsonObj) {
|
||||
super(jsonObj);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Parses data about winds (from the JSON data) and provides methods
|
||||
* to get/access the information.
|
||||
* 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
|
||||
* 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 winds (from the JSON data) and provides methods to
|
||||
* get/access the information. 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>
|
||||
* Boolean: <code>false</code><br>
|
||||
* Integral: Minimum value (MIN_VALUE)<br>
|
||||
* Floating point: Not a number (NaN)<br>
|
||||
* Others: <code>null</code><br>
|
||||
*
|
||||
* <p>
|
||||
* @author Ashutosh Kumar Singh
|
||||
* @version 2013/08/07
|
||||
* @since 2.5.0.1
|
||||
*/
|
||||
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";
|
||||
|
||||
/** Wind gust */
|
||||
/**
|
||||
* Wind gust
|
||||
*/
|
||||
private final float gust;
|
||||
|
||||
/**
|
||||
* Non-parameterized constructor
|
||||
*
|
||||
* <p>Initializes variables as per following basis:<br>
|
||||
* <p>
|
||||
* <p>
|
||||
* Initializes variables as per following basis:<br>
|
||||
* Boolean: <code>false</code><br>
|
||||
* Integral: Minimum value (MIN_VALUE)<br>
|
||||
* Floating point: Not a number (NaN)<br>
|
||||
* Others: <code>null</code><br>
|
||||
*/
|
||||
public Wind () {
|
||||
super ();
|
||||
public Wind() {
|
||||
super();
|
||||
|
||||
this.gust = Float.NaN;
|
||||
}
|
||||
|
||||
/**
|
||||
* Parameterized constructor
|
||||
*
|
||||
* <p>
|
||||
* Initializes variables from values from the given JSON object.
|
||||
*
|
||||
* <p>
|
||||
* @param jsonObj JSON object containing data about wind
|
||||
*/
|
||||
public Wind (JSONObject jsonObj) {
|
||||
super (jsonObj);
|
||||
public Wind(JSONObject jsonObj) {
|
||||
super(jsonObj);
|
||||
|
||||
this.gust = (float) jsonObj.optDouble(this.JSON_WIND_GUST, Double.NaN);
|
||||
}
|
||||
|
@ -497,29 +546,43 @@ public class CurrentWeatherData extends AbstractWeatherData {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
***********************
|
||||
* Declaring this class
|
||||
***********************
|
||||
*/
|
||||
|
||||
/** Key for JSON variable <code>Base</code> */
|
||||
/**
|
||||
* Key for JSON variable <code>Base</code>
|
||||
*/
|
||||
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";
|
||||
/** Key for JSON variable <code>City name</code> */
|
||||
/**
|
||||
* Key for JSON variable <code>City name</code>
|
||||
*/
|
||||
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";
|
||||
|
||||
/** Base */
|
||||
/**
|
||||
* Base
|
||||
*/
|
||||
private final String base;
|
||||
/** City code (ID) */
|
||||
/**
|
||||
* City code (ID)
|
||||
*/
|
||||
private final long cityID;
|
||||
/** City name */
|
||||
/**
|
||||
* City name
|
||||
*/
|
||||
private final String cityName;
|
||||
/** Response code */
|
||||
/**
|
||||
* Response code
|
||||
*/
|
||||
private final int responseCode;
|
||||
|
||||
private final Clouds clouds;
|
||||
|
@ -529,16 +592,20 @@ public class CurrentWeatherData extends AbstractWeatherData {
|
|||
private final Sys sys;
|
||||
private final Wind wind;
|
||||
|
||||
/** List of weather information (code, name, etc.) */
|
||||
/**
|
||||
* List of weather information (code, name, etc.)
|
||||
*/
|
||||
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;
|
||||
|
||||
/**
|
||||
* Parameterized constructor
|
||||
*
|
||||
* <p>
|
||||
* Initializes variables from values from the given JSON object.
|
||||
*
|
||||
* <p>
|
||||
* @param jsonObj JSON object containing current weather data
|
||||
*/
|
||||
public CurrentWeatherData(JSONObject jsonObj) {
|
||||
|
@ -568,7 +635,7 @@ public class CurrentWeatherData extends AbstractWeatherData {
|
|||
this.weatherList = (jsonArrWeather != null) ? new ArrayList<Weather>(jsonArrWeather.length()) : Collections.EMPTY_LIST;
|
||||
if (this.weatherList != Collections.EMPTY_LIST) {
|
||||
for (int i = 0; i < jsonArrWeather.length(); i++) {
|
||||
JSONObject jsonObjWeather = jsonArrWeather.optJSONObject (i);
|
||||
JSONObject jsonObjWeather = jsonArrWeather.optJSONObject(i);
|
||||
if (jsonObjWeather != null) {
|
||||
this.weatherList.add(new Weather(jsonObjWeather));
|
||||
}
|
||||
|
@ -613,7 +680,6 @@ public class CurrentWeatherData extends AbstractWeatherData {
|
|||
}
|
||||
|
||||
// Objects
|
||||
|
||||
public Clouds getClouds_Object() {
|
||||
return this.clouds;
|
||||
}
|
||||
|
@ -639,7 +705,6 @@ public class CurrentWeatherData extends AbstractWeatherData {
|
|||
}
|
||||
|
||||
// Lists
|
||||
|
||||
public boolean hasWeather_List() {
|
||||
return (this.weatherListCount != 0);
|
||||
}
|
||||
|
|
|
@ -28,87 +28,96 @@ import org.json.JSONArray;
|
|||
import org.json.JSONObject;
|
||||
|
||||
/**
|
||||
* Parses daily forecast data (from the JSON data) and provides methods
|
||||
* to get/access the information about daily forecasted weather.
|
||||
* 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
|
||||
* 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
|
||||
* exists, otherwise <code>get</code> methods will give value as per
|
||||
* following basis:<br>
|
||||
* Parses daily forecast data (from the JSON data) and provides methods to
|
||||
* get/access the information about daily forecasted weather. 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>
|
||||
* Boolean: <code>false</code><br>
|
||||
* Integral: Minimum value (MIN_VALUE)<br>
|
||||
* Floating point: Not a number (NaN)<br>
|
||||
* Objects: Data initialized with default/non-parameterized constructor<br>
|
||||
* Others: <code>null</code><br>
|
||||
*
|
||||
* <p>
|
||||
* @author Ashutosh Kumar Singh
|
||||
* @version 2013/08/07
|
||||
* @since 2.5.0.1
|
||||
*/
|
||||
public class DailyForecastData {
|
||||
/** Key for JSON object - City */
|
||||
private final String JSON_CITY = "city";
|
||||
/** Key for JSON object - List of forecasts */
|
||||
private final String JSON_FORECAST_LIST = "list";
|
||||
|
||||
/**
|
||||
* Key for JSON object - City
|
||||
*/
|
||||
private final String JSON_CITY = "city";
|
||||
/**
|
||||
* Key for JSON object - List of forecasts
|
||||
*/
|
||||
private final String JSON_FORECAST_LIST = "list";
|
||||
|
||||
/*
|
||||
************************
|
||||
* Declaring sub-classes
|
||||
************************
|
||||
*/
|
||||
|
||||
/**
|
||||
* Parses data about city (from the JSON data)
|
||||
* and provides methods to get/access the information.
|
||||
* For example, city name, coordinates, country name, population, etc.
|
||||
* 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
|
||||
* 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 city (from the JSON data) and provides methods to
|
||||
* get/access the information. For example, city name, coordinates, country
|
||||
* name, population, 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>
|
||||
* Boolean: <code>false</code><br>
|
||||
* Integral: Minimum value (MIN_VALUE)<br>
|
||||
* Floating point: Not a number (NaN)<br>
|
||||
* Others: <code>null</code><br>
|
||||
*
|
||||
* <p>
|
||||
* @author Ashutosh Kumar Singh
|
||||
* @version 2013/08/07
|
||||
* @since 2.5.0.1
|
||||
*/
|
||||
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)
|
||||
* and provides methods to get/access the information.
|
||||
* 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
|
||||
* 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
|
||||
* Key for JSON object - Coordinates
|
||||
*/
|
||||
private final String JSON_CITY_COORD = "coord";
|
||||
|
||||
/**
|
||||
* Parses data about geographic coordinates (from the JSON data) and
|
||||
* provides methods to get/access the information. 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>
|
||||
* Boolean: <code>false</code><br>
|
||||
* Integral: Minimum value (MIN_VALUE)<br>
|
||||
* Floating point: Not a number (NaN)<br>
|
||||
* Others: <code>null</code><br>
|
||||
*
|
||||
* <p>
|
||||
* @author Ashutosh Kumar Singh
|
||||
* @version 2013/08/07
|
||||
* @since 2.5.0.1
|
||||
|
@ -117,8 +126,9 @@ public class DailyForecastData {
|
|||
|
||||
/**
|
||||
* Non-parameterized constructor
|
||||
*
|
||||
* <p>Initializes variables as per following basis:<br>
|
||||
* <p>
|
||||
* <p>
|
||||
* Initializes variables as per following basis:<br>
|
||||
* Boolean: <code>false</code><br>
|
||||
* Integral: Minimum value (MIN_VALUE)<br>
|
||||
* Floating point: Not a number (NaN)<br>
|
||||
|
@ -130,9 +140,9 @@ public class DailyForecastData {
|
|||
|
||||
/**
|
||||
* Parameterized constructor
|
||||
*
|
||||
* <p>
|
||||
* Initializes variables from values from the given JSON object.
|
||||
*
|
||||
* <p>
|
||||
* @param jsonObj JSON object containing data about clouds
|
||||
*/
|
||||
public Coord(JSONObject jsonObj) {
|
||||
|
@ -140,31 +150,47 @@ public class DailyForecastData {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
/** 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";
|
||||
/** Key for JSON variable <code>City name</code> */
|
||||
/**
|
||||
* Key for JSON variable <code>City name</code>
|
||||
*/
|
||||
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";
|
||||
/** 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";
|
||||
|
||||
/** City code (ID) */
|
||||
/**
|
||||
* City code (ID)
|
||||
*/
|
||||
private final long cityID;
|
||||
/** City name */
|
||||
/**
|
||||
* City name
|
||||
*/
|
||||
private final String cityName;
|
||||
/** Country code of city */
|
||||
/**
|
||||
* Country code of city
|
||||
*/
|
||||
private final String countryCode;
|
||||
/** Population of city */
|
||||
/**
|
||||
* Population of city
|
||||
*/
|
||||
private final long population;
|
||||
|
||||
private final Coord coord;
|
||||
|
||||
/**
|
||||
* Non-parameterized constructor
|
||||
*
|
||||
* <p>Initializes variables as per following basis:<br>
|
||||
* <p>
|
||||
* <p>
|
||||
* Initializes variables as per following basis:<br>
|
||||
* Boolean: <code>false</code><br>
|
||||
* Integral: Minimum value (MIN_VALUE)<br>
|
||||
* Floating point: Not a number (NaN)<br>
|
||||
|
@ -181,9 +207,9 @@ public class DailyForecastData {
|
|||
|
||||
/**
|
||||
* Parameterized constructor
|
||||
*
|
||||
* <p>
|
||||
* Initializes variables from values from the given JSON object.
|
||||
*
|
||||
* <p>
|
||||
* @param jsonObj JSON object containing data about city
|
||||
*/
|
||||
public City(JSONObject jsonObj) {
|
||||
|
@ -229,37 +255,39 @@ public class DailyForecastData {
|
|||
}
|
||||
|
||||
// Objects
|
||||
|
||||
public Coord getCoordinates_Object() {
|
||||
return this.coord;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Parses data about forecasts (from the JSON data)
|
||||
* and provides methods to get/access the information.
|
||||
* 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
|
||||
* 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 forecasts (from the JSON data) and provides methods to
|
||||
* get/access the information. 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>
|
||||
* Boolean: <code>false</code><br>
|
||||
* Integral: Minimum value (MIN_VALUE)<br>
|
||||
* Floating point: Not a number (NaN)<br>
|
||||
* Others: <code>null</code><br>
|
||||
*
|
||||
* <p>
|
||||
* @author Ashutosh Kumar Singh
|
||||
* @version 2013/08/07
|
||||
* @since 2.5.0.1
|
||||
*/
|
||||
public static class Forecast extends AbstractWeatherData {
|
||||
/** Key for JSON object - Temperature */
|
||||
|
||||
/**
|
||||
* Key for JSON object - Temperature
|
||||
*/
|
||||
public final String JSON_TEMP = "temp";
|
||||
|
||||
/*
|
||||
|
@ -267,26 +295,26 @@ public class DailyForecastData {
|
|||
* Declaring sub-sub-classes
|
||||
***************************
|
||||
*/
|
||||
|
||||
/**
|
||||
* Parses data about weather (from the JSON data)
|
||||
* and provides methods 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><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><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
|
||||
* 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>
|
||||
* Boolean: <code>false</code><br>
|
||||
* Integral: Minimum value (MIN_VALUE)<br>
|
||||
* Floating point: Not a number (NaN)<br>
|
||||
* Others: <code>null</code><br>
|
||||
*
|
||||
* <p>
|
||||
* @author Ashutosh Kumar Singh
|
||||
* @version 2013/08/07
|
||||
* @since 2.5.0.1
|
||||
|
@ -295,83 +323,111 @@ public class DailyForecastData {
|
|||
|
||||
/**
|
||||
* Non-parameterized constructor
|
||||
*
|
||||
* <p>Initializes variables as per following basis:<br>
|
||||
* <p>
|
||||
* <p>
|
||||
* Initializes variables as per following basis:<br>
|
||||
* Boolean: <code>false</code><br>
|
||||
* Integral: Minimum value (MIN_VALUE)<br>
|
||||
* Floating point: Not a number (NaN)<br>
|
||||
* Others: <code>null</code><br>
|
||||
*/
|
||||
public Weather () {
|
||||
public Weather() {
|
||||
super();
|
||||
}
|
||||
|
||||
/**
|
||||
* Parameterized constructor
|
||||
*
|
||||
* <p>
|
||||
* Initializes variables from values from the given JSON object.
|
||||
*
|
||||
* <p>
|
||||
* @param jsonObj JSON object containing data about weather
|
||||
*/
|
||||
public Weather (JSONObject jsonObj) {
|
||||
public Weather(JSONObject jsonObj) {
|
||||
super(jsonObj);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Parses data about temperature (from the JSON data)
|
||||
* and provides methods 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><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><code>get</code> methods can be used to access the data, if the data
|
||||
* Parses data about temperature (from the JSON data) and provides
|
||||
* methods 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>
|
||||
* Boolean: <code>false</code><br>
|
||||
* Integral: Minimum value (MIN_VALUE)<br>
|
||||
* Floating point: Not a number (NaN)<br>
|
||||
* Others: <code>null</code><br>
|
||||
*
|
||||
* <p>
|
||||
* @author Ashutosh Kumar Singh
|
||||
* @version 2013/08/07
|
||||
* @since 2.5.0.1
|
||||
*/
|
||||
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";
|
||||
/** Key for JSON variable <code>Temp -> Minimum</code> */
|
||||
/**
|
||||
* Key for JSON variable <code>Temp -> Minimum</code>
|
||||
*/
|
||||
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";
|
||||
/** Key for JSON variable <code>Temp -> Night</code> */
|
||||
/**
|
||||
* Key for JSON variable <code>Temp -> Night</code>
|
||||
*/
|
||||
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";
|
||||
/** Key for JSON variable <code>Temp -> Morning</code> */
|
||||
/**
|
||||
* Key for JSON variable <code>Temp -> Morning</code>
|
||||
*/
|
||||
public final String JSON_TEMP_MORNING = "morn";
|
||||
|
||||
/** Day temperature */
|
||||
/**
|
||||
* Day temperature
|
||||
*/
|
||||
private final float dayTemp;
|
||||
/** Minimum temperature */
|
||||
/**
|
||||
* Minimum temperature
|
||||
*/
|
||||
private final float minTemp;
|
||||
/** Maximum temperature */
|
||||
/**
|
||||
* Maximum temperature
|
||||
*/
|
||||
private final float maxTemp;
|
||||
/** Night temperature */
|
||||
/**
|
||||
* Night temperature
|
||||
*/
|
||||
private final float nightTemp;
|
||||
/** Evening temperature */
|
||||
/**
|
||||
* Evening temperature
|
||||
*/
|
||||
private final float eveTemp;
|
||||
/** Morning temperature */
|
||||
/**
|
||||
* Morning temperature
|
||||
*/
|
||||
private final float mornTemp;
|
||||
|
||||
/**
|
||||
* Non-parameterized constructor
|
||||
*
|
||||
* <p>Initializes variables as per following basis:<br>
|
||||
* <p>
|
||||
* <p>
|
||||
* Initializes variables as per following basis:<br>
|
||||
* Boolean: <code>false</code><br>
|
||||
* Integral: Minimum value (MIN_VALUE)<br>
|
||||
* Floating point: Not a number (NaN)<br>
|
||||
|
@ -388,9 +444,9 @@ public class DailyForecastData {
|
|||
|
||||
/**
|
||||
* Parameterized constructor
|
||||
*
|
||||
* <p>
|
||||
* Initializes variables from values from the given JSON object.
|
||||
*
|
||||
* <p>
|
||||
* @param jsonObj JSON object containing data about temperature
|
||||
*/
|
||||
public Temperature(JSONObject jsonObj) {
|
||||
|
@ -456,40 +512,64 @@ public class DailyForecastData {
|
|||
* 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";
|
||||
/** Key for JSON variable <code>Humidity</code> */
|
||||
/**
|
||||
* Key for JSON variable <code>Humidity</code>
|
||||
*/
|
||||
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";
|
||||
/** Key for JSON variable <code>Wind degree</code> */
|
||||
/**
|
||||
* Key for JSON variable <code>Wind degree</code>
|
||||
*/
|
||||
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";
|
||||
|
||||
/** Pressure */
|
||||
/**
|
||||
* Pressure
|
||||
*/
|
||||
private final float pressure;
|
||||
/** Humidity */
|
||||
/**
|
||||
* Humidity
|
||||
*/
|
||||
private final float humidity;
|
||||
/** Wind speed */
|
||||
/**
|
||||
* Wind speed
|
||||
*/
|
||||
private final float windSpeed;
|
||||
/** Wind degree */
|
||||
/**
|
||||
* Wind degree
|
||||
*/
|
||||
private final float windDegree;
|
||||
/** Percentage of clouds */
|
||||
/**
|
||||
* Percentage of clouds
|
||||
*/
|
||||
private final float cloudsPercent;
|
||||
|
||||
private final Temperature temp;
|
||||
|
||||
/** List of weather information (code, name, etc.) */
|
||||
/**
|
||||
* List of weather information (code, name, etc.)
|
||||
*/
|
||||
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;
|
||||
|
||||
/**
|
||||
* Non-parameterized constructor
|
||||
*
|
||||
* <p>Initializes variables as per following basis:<br>
|
||||
* <p>
|
||||
* <p>
|
||||
* Initializes variables as per following basis:<br>
|
||||
* Boolean: <code>false</code><br>
|
||||
* Integral: Minimum value (MIN_VALUE)<br>
|
||||
* Floating point: Not a number (NaN)<br>
|
||||
|
@ -512,9 +592,9 @@ public class DailyForecastData {
|
|||
|
||||
/**
|
||||
* Parameterized constructor
|
||||
*
|
||||
* <p>
|
||||
* Initializes variables from values from the given JSON object.
|
||||
*
|
||||
* <p>
|
||||
* @param jsonObj JSON object containing data about forecasts
|
||||
*/
|
||||
public Forecast(JSONObject jsonObj) {
|
||||
|
@ -532,8 +612,8 @@ public class DailyForecastData {
|
|||
JSONArray jsonArrWeather = (jsonObj != null) ? jsonObj.optJSONArray(this.JSON_WEATHER) : null;
|
||||
this.weatherList = (jsonArrWeather != null) ? new ArrayList<Weather>(jsonArrWeather.length()) : Collections.EMPTY_LIST;
|
||||
if (this.weatherList != Collections.EMPTY_LIST) {
|
||||
for (int i = 0; i < jsonArrWeather.length (); i++) {
|
||||
JSONObject jsonObjWeather = jsonArrWeather.optJSONObject (i);
|
||||
for (int i = 0; i < jsonArrWeather.length(); i++) {
|
||||
JSONObject jsonObjWeather = jsonArrWeather.optJSONObject(i);
|
||||
if (jsonObjWeather != null) {
|
||||
this.weatherList.add(new Weather(jsonObjWeather));
|
||||
}
|
||||
|
@ -583,13 +663,11 @@ public class DailyForecastData {
|
|||
}
|
||||
|
||||
// Objects
|
||||
|
||||
public Temperature getTemperature_Object() {
|
||||
return this.temp;
|
||||
}
|
||||
|
||||
// Lists
|
||||
|
||||
public boolean hasWeather_List() {
|
||||
return (this.weatherListCount != 0);
|
||||
}
|
||||
|
@ -603,39 +681,53 @@ public class DailyForecastData {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
***********************
|
||||
* 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";
|
||||
/** Key for JSON variable <code>Response time</code> */
|
||||
/**
|
||||
* Key for JSON variable <code>Response time</code>
|
||||
*/
|
||||
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";
|
||||
|
||||
/** Response code */
|
||||
/**
|
||||
* Response code
|
||||
*/
|
||||
private final String responseCode;
|
||||
/** Response time */
|
||||
/**
|
||||
* Response time
|
||||
*/
|
||||
private final float responseTime;
|
||||
/** Forecast count */
|
||||
/**
|
||||
* Forecast count
|
||||
*/
|
||||
private final int responseForecastCount;
|
||||
|
||||
private final City city;
|
||||
|
||||
/** List of forecast information */
|
||||
/**
|
||||
* List of forecast information
|
||||
*/
|
||||
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;
|
||||
|
||||
/**
|
||||
* Parameterized constructor
|
||||
*
|
||||
* <p>
|
||||
* Initializes variables from values from the given JSON object.
|
||||
*
|
||||
* <p>
|
||||
* @param jsonObj JSON object containing data about daily forecasts
|
||||
*/
|
||||
public DailyForecastData(JSONObject jsonObj) {
|
||||
|
@ -684,13 +776,11 @@ public class DailyForecastData {
|
|||
}
|
||||
|
||||
// Objects
|
||||
|
||||
public City getCity_Object() {
|
||||
return this.city;
|
||||
}
|
||||
|
||||
// Lists
|
||||
|
||||
public boolean hasForecast_List() {
|
||||
return (this.forecastListCount != 0);
|
||||
}
|
||||
|
|
|
@ -28,86 +28,95 @@ import org.json.JSONArray;
|
|||
import org.json.JSONObject;
|
||||
|
||||
/**
|
||||
* Parses forecast weather data (from the JSON data) and provides methods
|
||||
* to get/access the information about forecasted weather.
|
||||
* 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
|
||||
* 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
|
||||
* exists, otherwise <code>get</code> methods will give value as per
|
||||
* following basis:<br>
|
||||
* Parses forecast weather data (from the JSON data) and provides methods to
|
||||
* get/access the information about forecasted weather. 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>
|
||||
* Boolean: <code>false</code><br>
|
||||
* Integral: Minimum value (MIN_VALUE)<br>
|
||||
* Floating point: Not a number (NaN)<br>
|
||||
* Objects: Data initialized with default/non-parameterized constructor<br>
|
||||
* Others: <code>null</code><br>
|
||||
*
|
||||
* <p>
|
||||
* @author Ashutosh Kumar Singh
|
||||
* @version 2013/08/07
|
||||
* @since 2.5.0.1
|
||||
*/
|
||||
public class ForecastWeatherData {
|
||||
/** Key for JSON object - City */
|
||||
private final String JSON_CITY = "city";
|
||||
/** Key for JSON object - List of forecasts */
|
||||
private final String JSON_FORECAST_LIST = "list";
|
||||
|
||||
/**
|
||||
* Key for JSON object - City
|
||||
*/
|
||||
private final String JSON_CITY = "city";
|
||||
/**
|
||||
* Key for JSON object - List of forecasts
|
||||
*/
|
||||
private final String JSON_FORECAST_LIST = "list";
|
||||
|
||||
/*
|
||||
************************
|
||||
* Declaring sub-classes
|
||||
************************
|
||||
*/
|
||||
|
||||
/**
|
||||
* Parses data about city (from the JSON data)
|
||||
* and provides methods to get/access the information.
|
||||
* For example, city name, coordinates, country name, population, etc.
|
||||
* 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
|
||||
* 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 city (from the JSON data) and provides methods to
|
||||
* get/access the information. For example, city name, coordinates, country
|
||||
* name, population, 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>
|
||||
* Boolean: <code>false</code><br>
|
||||
* Integral: Minimum value (MIN_VALUE)<br>
|
||||
* Floating point: Not a number (NaN)<br>
|
||||
* Others: <code>null</code><br>
|
||||
*
|
||||
* <p>
|
||||
* @author Ashutosh Kumar Singh
|
||||
* @version 2013/08/07
|
||||
* @since 2.5.0.1
|
||||
*/
|
||||
public static class City {
|
||||
/** Key for JSON object - Coordinates */
|
||||
|
||||
/**
|
||||
* Key for JSON object - Coordinates
|
||||
*/
|
||||
private final String JSON_CITY_COORD = "coord";
|
||||
|
||||
/**
|
||||
* Parses data about geographic coordinates (from the JSON data)
|
||||
* and provides methods to get/access the information.
|
||||
* 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
|
||||
* 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 geographic coordinates (from the JSON data) and
|
||||
* provides methods to get/access the information. 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>
|
||||
* Boolean: <code>false</code><br>
|
||||
* Integral: Minimum value (MIN_VALUE)<br>
|
||||
* Floating point: Not a number (NaN)<br>
|
||||
* Others: <code>null</code><br>
|
||||
*
|
||||
* <p>
|
||||
* @author Ashutosh Kumar Singh
|
||||
* @version 2013/08/07
|
||||
* @since 2.5.0.1
|
||||
|
@ -116,8 +125,9 @@ public class ForecastWeatherData {
|
|||
|
||||
/**
|
||||
* Non-parameterized constructor
|
||||
*
|
||||
* <p>Initializes variables as per following basis:<br>
|
||||
* <p>
|
||||
* <p>
|
||||
* Initializes variables as per following basis:<br>
|
||||
* Boolean: <code>false</code><br>
|
||||
* Integral: Minimum value (MIN_VALUE)<br>
|
||||
* Floating point: Not a number (NaN)<br>
|
||||
|
@ -129,9 +139,9 @@ public class ForecastWeatherData {
|
|||
|
||||
/**
|
||||
* Parameterized constructor
|
||||
*
|
||||
* <p>
|
||||
* Initializes variables from values from the given JSON object.
|
||||
*
|
||||
* <p>
|
||||
* @param jsonObj JSON object containing data about clouds
|
||||
*/
|
||||
public Coord(JSONObject jsonObj) {
|
||||
|
@ -139,31 +149,47 @@ public class ForecastWeatherData {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
/** 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";
|
||||
/** Key for JSON variable <code>City name</code> */
|
||||
/**
|
||||
* Key for JSON variable <code>City name</code>
|
||||
*/
|
||||
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";
|
||||
/** 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";
|
||||
|
||||
/** City code (ID) */
|
||||
/**
|
||||
* City code (ID)
|
||||
*/
|
||||
private final long cityID;
|
||||
/** City name */
|
||||
/**
|
||||
* City name
|
||||
*/
|
||||
private final String cityName;
|
||||
/** Country code of city */
|
||||
/**
|
||||
* Country code of city
|
||||
*/
|
||||
private final String countryCode;
|
||||
/** Population of city */
|
||||
/**
|
||||
* Population of city
|
||||
*/
|
||||
private final long population;
|
||||
|
||||
private final Coord coord;
|
||||
|
||||
/**
|
||||
* Non-parameterized constructor
|
||||
*
|
||||
* <p>Initializes variables as per following basis:<br>
|
||||
* <p>
|
||||
* <p>
|
||||
* Initializes variables as per following basis:<br>
|
||||
* Boolean: <code>false</code><br>
|
||||
* Integral: Minimum value (MIN_VALUE)<br>
|
||||
* Floating point: Not a number (NaN)<br>
|
||||
|
@ -180,9 +206,9 @@ public class ForecastWeatherData {
|
|||
|
||||
/**
|
||||
* Parameterized constructor
|
||||
*
|
||||
* <p>
|
||||
* Initializes variables from values from the given JSON object.
|
||||
*
|
||||
* <p>
|
||||
* @param jsonObj JSON object containing data about city
|
||||
*/
|
||||
public City(JSONObject jsonObj) {
|
||||
|
@ -228,37 +254,39 @@ public class ForecastWeatherData {
|
|||
}
|
||||
|
||||
// Objects
|
||||
|
||||
public Coord getCoordinates_Object() {
|
||||
return this.coord;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Parses data about forecasts (from the JSON data)
|
||||
* and provides methods to get/access the information.
|
||||
* 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
|
||||
* 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 forecasts (from the JSON data) and provides methods to
|
||||
* get/access the information. 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>
|
||||
* Boolean: <code>false</code><br>
|
||||
* Integral: Minimum value (MIN_VALUE)<br>
|
||||
* Floating point: Not a number (NaN)<br>
|
||||
* Others: <code>null</code><br>
|
||||
*
|
||||
* <p>
|
||||
* @author Ashutosh Kumar Singh
|
||||
* @version 2013/08/07
|
||||
* @since 2.5.0.1
|
||||
*/
|
||||
public static class Forecast extends AbstractWeatherData {
|
||||
/** Key for JSON object - Sys (pod, etc.) */
|
||||
|
||||
/**
|
||||
* Key for JSON object - Sys (pod, etc.)
|
||||
*/
|
||||
private final String JSON_SYS = "sys";
|
||||
|
||||
/*
|
||||
|
@ -266,25 +294,25 @@ public class ForecastWeatherData {
|
|||
* Declaring sub-sub-classes
|
||||
***************************
|
||||
*/
|
||||
|
||||
/**
|
||||
* Parses data about clouds (from the JSON data)
|
||||
* and provides methods to get/access the information.
|
||||
* 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
|
||||
* 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 clouds (from the JSON data) and provides methods to
|
||||
* get/access the information. 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>
|
||||
* Boolean: <code>false</code><br>
|
||||
* Integral: Minimum value (MIN_VALUE)<br>
|
||||
* Floating point: Not a number (NaN)<br>
|
||||
* Others: <code>null</code><br>
|
||||
*
|
||||
* <p>
|
||||
* @author Ashutosh Kumar Singh
|
||||
* @version 2013/08/07
|
||||
* @since 2.5.0.1
|
||||
|
@ -293,8 +321,9 @@ public class ForecastWeatherData {
|
|||
|
||||
/**
|
||||
* Non-parameterized constructor
|
||||
*
|
||||
* <p>Initializes variables as per following basis:<br>
|
||||
* <p>
|
||||
* <p>
|
||||
* Initializes variables as per following basis:<br>
|
||||
* Boolean: <code>false</code><br>
|
||||
* Integral: Minimum value (MIN_VALUE)<br>
|
||||
* Floating point: Not a number (NaN)<br>
|
||||
|
@ -306,9 +335,9 @@ public class ForecastWeatherData {
|
|||
|
||||
/**
|
||||
* Parameterized constructor
|
||||
*
|
||||
* <p>
|
||||
* Initializes variables from values from the given JSON object.
|
||||
*
|
||||
* <p>
|
||||
* @param jsonObj JSON object containing data about clouds
|
||||
*/
|
||||
public Clouds(JSONObject jsonObj) {
|
||||
|
@ -317,47 +346,63 @@ public class ForecastWeatherData {
|
|||
}
|
||||
|
||||
/**
|
||||
* Parses data about main weather elements (from the JSON data)
|
||||
* and provides methods to get/access the information.
|
||||
* For example, temperature, pressure, sea level, etc.
|
||||
* 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
|
||||
* 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 main weather elements (from the JSON data) and
|
||||
* provides methods to get/access the information. For example,
|
||||
* temperature, pressure, sea level, 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>
|
||||
* Boolean: <code>false</code><br>
|
||||
* Integral: Minimum value (MIN_VALUE)<br>
|
||||
* Floating point: Not a number (NaN)<br>
|
||||
* Others: <code>null</code><br>
|
||||
*
|
||||
* <p>
|
||||
* @author Ashutosh Kumar Singh
|
||||
* @version 2013/08/07
|
||||
* @since 2.5.0.1
|
||||
*/
|
||||
public static class Main extends AbstractWeatherData.Main {
|
||||
/** Key for JSON variable <code>Main -> Sea level</code> */
|
||||
|
||||
/**
|
||||
* Key for JSON variable <code>Main -> Sea level</code>
|
||||
*/
|
||||
private final String JSON_MAIN_SEA_LEVEL = "sea_level";
|
||||
/** Key for JSON variable <code>Main -> Ground level</code> */
|
||||
/**
|
||||
* Key for JSON variable <code>Main -> Ground level</code>
|
||||
*/
|
||||
private final String JSON_MAIN_GRND_LEVEL = "grnd_level";
|
||||
/** Key for JSON variable <code>Main -> Temperature KF</code> */
|
||||
/**
|
||||
* Key for JSON variable <code>Main -> Temperature KF</code>
|
||||
*/
|
||||
private final String JSON_MAIN_TMP_KF = "temp_kf";
|
||||
|
||||
/** Sea level */
|
||||
/**
|
||||
* Sea level
|
||||
*/
|
||||
private final float seaLevel;
|
||||
/** Ground level */
|
||||
/**
|
||||
* Ground level
|
||||
*/
|
||||
private final float groundLevel;
|
||||
/** Temperature KF */
|
||||
/**
|
||||
* Temperature KF
|
||||
*/
|
||||
private final float tempKF;
|
||||
|
||||
/**
|
||||
* Non-parameterized constructor
|
||||
*
|
||||
* <p>Initializes variables as per following basis:<br>
|
||||
* <p>
|
||||
* <p>
|
||||
* Initializes variables as per following basis:<br>
|
||||
* Boolean: <code>false</code><br>
|
||||
* Integral: Minimum value (MIN_VALUE)<br>
|
||||
* Floating point: Not a number (NaN)<br>
|
||||
|
@ -373,11 +418,11 @@ public class ForecastWeatherData {
|
|||
|
||||
/**
|
||||
* Parameterized constructor
|
||||
*
|
||||
* <p>
|
||||
* Initializes variables from values from the given JSON object.
|
||||
*
|
||||
* @param jsonObj JSON object containing data about main
|
||||
* weather elements
|
||||
* <p>
|
||||
* @param jsonObj JSON object containing data about main weather
|
||||
* elements
|
||||
*/
|
||||
public Main(JSONObject jsonObj) {
|
||||
super(jsonObj);
|
||||
|
@ -413,39 +458,47 @@ public class ForecastWeatherData {
|
|||
}
|
||||
|
||||
/**
|
||||
* Parses data about main weather elements (from the JSON data)
|
||||
* and provides methods to get/access the information.
|
||||
* For example, temperature, pressure, sea level, etc.
|
||||
* 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
|
||||
* 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 main weather elements (from the JSON data) and
|
||||
* provides methods to get/access the information. For example,
|
||||
* temperature, pressure, sea level, 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>
|
||||
* Boolean: <code>false</code><br>
|
||||
* Integral: Minimum value (MIN_VALUE)<br>
|
||||
* Floating point: Not a number (NaN)<br>
|
||||
* Others: <code>null</code><br>
|
||||
*
|
||||
* <p>
|
||||
* @author Ashutosh Kumar Singh
|
||||
* @version 2013/08/07
|
||||
* @since 2.5.0.1
|
||||
*/
|
||||
public static class Sys {
|
||||
/** Key for JSON variable <code>Sys -> Pod</code> */
|
||||
|
||||
/**
|
||||
* Key for JSON variable <code>Sys -> Pod</code>
|
||||
*/
|
||||
private final String JSON_SYS_POD = "pod";
|
||||
|
||||
/** Pod */
|
||||
/**
|
||||
* Pod
|
||||
*/
|
||||
private final String pod;
|
||||
|
||||
/**
|
||||
* Non-parameterized constructor
|
||||
*
|
||||
* <p>Initializes variables as per following basis:<br>
|
||||
* <p>
|
||||
* <p>
|
||||
* Initializes variables as per following basis:<br>
|
||||
* Boolean: <code>false</code><br>
|
||||
* Integral: Minimum value (MIN_VALUE)<br>
|
||||
* Floating point: Not a number (NaN)<br>
|
||||
|
@ -457,11 +510,11 @@ public class ForecastWeatherData {
|
|||
|
||||
/**
|
||||
* Parameterized constructor
|
||||
*
|
||||
* <p>
|
||||
* Initializes variables from values from the given JSON object.
|
||||
*
|
||||
* @param jsonObj JSON object containing data about sys.
|
||||
* For example, pod, etc.
|
||||
* <p>
|
||||
* @param jsonObj JSON object containing data about sys. For
|
||||
* example, pod, etc.
|
||||
*/
|
||||
public Sys(JSONObject jsonObj) {
|
||||
this.pod = (jsonObj != null) ? jsonObj.optString(this.JSON_SYS_POD, null) : null;
|
||||
|
@ -477,24 +530,25 @@ public class ForecastWeatherData {
|
|||
}
|
||||
|
||||
/**
|
||||
* Parses data about weather (from the JSON data)
|
||||
* and provides methods 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><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><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
|
||||
* 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>
|
||||
* Boolean: <code>false</code><br>
|
||||
* Integral: Minimum value (MIN_VALUE)<br>
|
||||
* Floating point: Not a number (NaN)<br>
|
||||
* Others: <code>null</code><br>
|
||||
*
|
||||
* <p>
|
||||
* @author Ashutosh Kumar Singh
|
||||
* @version 2013/08/07
|
||||
* @since 2.5.0.1
|
||||
|
@ -503,48 +557,50 @@ public class ForecastWeatherData {
|
|||
|
||||
/**
|
||||
* Non-parameterized constructor
|
||||
*
|
||||
* <p>Initializes variables as per following basis:<br>
|
||||
* <p>
|
||||
* <p>
|
||||
* Initializes variables as per following basis:<br>
|
||||
* Boolean: <code>false</code><br>
|
||||
* Integral: Minimum value (MIN_VALUE)<br>
|
||||
* Floating point: Not a number (NaN)<br>
|
||||
* Others: <code>null</code><br>
|
||||
*/
|
||||
public Weather () {
|
||||
public Weather() {
|
||||
super();
|
||||
}
|
||||
|
||||
/**
|
||||
* Parameterized constructor
|
||||
*
|
||||
* <p>
|
||||
* Initializes variables from values from the given JSON object.
|
||||
*
|
||||
* @param jsonObj JSON object containing data about weather
|
||||
* code, name, etc.
|
||||
* <p>
|
||||
* @param jsonObj JSON object containing data about weather code,
|
||||
* name, etc.
|
||||
*/
|
||||
public Weather (JSONObject jsonObj) {
|
||||
public Weather(JSONObject jsonObj) {
|
||||
super(jsonObj);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Parses data about wind (from the JSON data)
|
||||
* and provides methods to get/access the information.
|
||||
* 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
|
||||
* 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 wind (from the JSON data) and provides methods to
|
||||
* get/access the information. 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>
|
||||
* Boolean: <code>false</code><br>
|
||||
* Integral: Minimum value (MIN_VALUE)<br>
|
||||
* Floating point: Not a number (NaN)<br>
|
||||
* Others: <code>null</code><br>
|
||||
*
|
||||
* <p>
|
||||
* @author Ashutosh Kumar Singh
|
||||
* @version 2013/08/07
|
||||
* @since 2.5.0.1
|
||||
|
@ -553,26 +609,27 @@ public class ForecastWeatherData {
|
|||
|
||||
/**
|
||||
* Non-parameterized constructor
|
||||
*
|
||||
* <p>Initializes variables as per following basis:<br>
|
||||
* <p>
|
||||
* <p>
|
||||
* Initializes variables as per following basis:<br>
|
||||
* Boolean: <code>false</code><br>
|
||||
* Integral: Minimum value (MIN_VALUE)<br>
|
||||
* Floating point: Not a number (NaN)<br>
|
||||
* Others: <code>null</code><br>
|
||||
*/
|
||||
public Wind () {
|
||||
super ();
|
||||
public Wind() {
|
||||
super();
|
||||
}
|
||||
|
||||
/**
|
||||
* Parameterized constructor
|
||||
*
|
||||
* <p>
|
||||
* Initializes variables from values from the given JSON object.
|
||||
*
|
||||
* <p>
|
||||
* @param jsonObj JSON object containing data about wind
|
||||
*/
|
||||
public Wind (JSONObject jsonObj) {
|
||||
super (jsonObj);
|
||||
public Wind(JSONObject jsonObj) {
|
||||
super(jsonObj);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -581,12 +638,14 @@ public class ForecastWeatherData {
|
|||
* Declaring this sub-class
|
||||
************************
|
||||
*/
|
||||
|
||||
|
||||
/** Key for JSON variable <code>Date time text</code> */
|
||||
/**
|
||||
* Key for JSON variable <code>Date time text</code>
|
||||
*/
|
||||
private final String JSON_DATE_TIME_TEXT = "dt_txt";
|
||||
|
||||
/** Date time text */
|
||||
/**
|
||||
* Date time text
|
||||
*/
|
||||
private final String dateTimeText;
|
||||
|
||||
private final Clouds clouds;
|
||||
|
@ -594,15 +653,20 @@ public class ForecastWeatherData {
|
|||
private final Sys sys;
|
||||
private final Wind wind;
|
||||
|
||||
/** List of weather information (code, name, etc.) */
|
||||
/**
|
||||
* List of weather information (code, name, etc.)
|
||||
*/
|
||||
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;
|
||||
|
||||
/**
|
||||
* Non-parameterized constructor
|
||||
*
|
||||
* <p>Initializes variables as per following basis:<br>
|
||||
* <p>
|
||||
* <p>
|
||||
* Initializes variables as per following basis:<br>
|
||||
* Boolean: <code>false</code><br>
|
||||
* Integral: Minimum value (MIN_VALUE)<br>
|
||||
* Floating point: Not a number (NaN)<br>
|
||||
|
@ -623,9 +687,9 @@ public class ForecastWeatherData {
|
|||
|
||||
/**
|
||||
* Parameterized constructor
|
||||
*
|
||||
* <p>
|
||||
* Initializes variables from values from the given JSON object.
|
||||
*
|
||||
* <p>
|
||||
* @param jsonObj JSON object containing data about forecasts
|
||||
*/
|
||||
public Forecast(JSONObject jsonObj) {
|
||||
|
@ -645,8 +709,8 @@ public class ForecastWeatherData {
|
|||
JSONArray jsonArrWeather = (jsonObj != null) ? jsonObj.optJSONArray(this.JSON_WEATHER) : null;
|
||||
this.weatherList = (jsonArrWeather != null) ? new ArrayList<Weather>(jsonArrWeather.length()) : Collections.EMPTY_LIST;
|
||||
if (this.weatherList != Collections.EMPTY_LIST) {
|
||||
for (int i = 0; i < jsonArrWeather.length (); i++) {
|
||||
JSONObject jsonObjWeather = jsonArrWeather.optJSONObject (i);
|
||||
for (int i = 0; i < jsonArrWeather.length(); i++) {
|
||||
JSONObject jsonObjWeather = jsonArrWeather.optJSONObject(i);
|
||||
if (jsonObjWeather != null) {
|
||||
this.weatherList.add(new Weather(jsonObjWeather));
|
||||
}
|
||||
|
@ -667,7 +731,6 @@ public class ForecastWeatherData {
|
|||
}
|
||||
|
||||
// Objects
|
||||
|
||||
public Clouds getClouds_Object() {
|
||||
return this.clouds;
|
||||
}
|
||||
|
@ -685,7 +748,6 @@ public class ForecastWeatherData {
|
|||
}
|
||||
|
||||
// Lists
|
||||
|
||||
public boolean hasWeather_List() {
|
||||
return (this.weatherListCount != 0);
|
||||
}
|
||||
|
@ -699,39 +761,53 @@ public class ForecastWeatherData {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
***********************
|
||||
* 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";
|
||||
/** Key for JSON variable <code>Response time</code> */
|
||||
/**
|
||||
* Key for JSON variable <code>Response time</code>
|
||||
*/
|
||||
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";
|
||||
|
||||
/** Response code */
|
||||
/**
|
||||
* Response code
|
||||
*/
|
||||
private final String responseCode;
|
||||
/** Response time */
|
||||
/**
|
||||
* Response time
|
||||
*/
|
||||
private final float responseTime;
|
||||
/** Forecast count */
|
||||
/**
|
||||
* Forecast count
|
||||
*/
|
||||
private final int responseForecastCount;
|
||||
|
||||
private final City city;
|
||||
|
||||
/** List of forecast information */
|
||||
/**
|
||||
* List of forecast information
|
||||
*/
|
||||
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;
|
||||
|
||||
/**
|
||||
* Parameterized constructor
|
||||
*
|
||||
* <p>
|
||||
* Initializes variables from values from the given JSON object.
|
||||
*
|
||||
* <p>
|
||||
* @param jsonObj JSON object containing data about clouds
|
||||
*/
|
||||
public ForecastWeatherData(JSONObject jsonObj) {
|
||||
|
@ -780,13 +856,11 @@ public class ForecastWeatherData {
|
|||
}
|
||||
|
||||
// Objects
|
||||
|
||||
public City getCity_Object() {
|
||||
return this.city;
|
||||
}
|
||||
|
||||
// Lists
|
||||
|
||||
public boolean hasForecast_List() {
|
||||
return (this.forecastListCount != 0);
|
||||
}
|
||||
|
|
|
@ -30,7 +30,7 @@ import org.json.JSONObject;
|
|||
/**
|
||||
* Provides methods to get weather, forecast, and other data from
|
||||
* OpenWeatherMap.org
|
||||
*
|
||||
* <p>
|
||||
* @author Ashutosh Kumar Singh
|
||||
* @version 2013/08/05
|
||||
* @since 2.5.0.1
|
||||
|
@ -69,7 +69,7 @@ public class OpenWeatherMap {
|
|||
|
||||
/**
|
||||
* Returns the parameter.
|
||||
*
|
||||
* <p>
|
||||
* @return Parameter
|
||||
*/
|
||||
public String getParameter() {
|
||||
|
@ -364,8 +364,7 @@ public class OpenWeatherMap {
|
|||
|
||||
/**
|
||||
* *********************
|
||||
* Declaring this class
|
||||
**********************
|
||||
* Declaring this class *********************
|
||||
*/
|
||||
private final OWM_Response owmResponse;
|
||||
|
||||
|
|
|
@ -28,15 +28,15 @@ import java.net.URL;
|
|||
import java.util.Scanner;
|
||||
|
||||
/**
|
||||
* Provides various tools, which help doing tasks in this application.
|
||||
* For example, tool for downloading content from the Internet, tool for
|
||||
* correcting, etc.
|
||||
*
|
||||
* <p>Note: This class directly do not provide any functions, but has
|
||||
* <code>static</code> sub-classes which provide various
|
||||
* related tools, i.e., this class only behaves as the container for those
|
||||
* classes.
|
||||
*
|
||||
* Provides various tools, which help doing tasks in this application. For
|
||||
* example, tool for downloading content from the Internet, tool for correcting,
|
||||
* etc.
|
||||
* <p>
|
||||
* <p>
|
||||
* Note: This class directly do not provide any functions, but has
|
||||
* <code>static</code> sub-classes which provide various related tools, i.e.,
|
||||
* this class only behaves as the container for those classes.
|
||||
* <p>
|
||||
* @author Ashutosh Kumar Singh
|
||||
* @version 2014-07-01
|
||||
* @since 2.5.0.1
|
||||
|
@ -45,7 +45,7 @@ public class Tools {
|
|||
|
||||
/**
|
||||
* Provides methods to download data or files from the Internet.
|
||||
*
|
||||
* <p>
|
||||
* @author Ashutosh Kumar Singh
|
||||
* @version 2013-07-24
|
||||
* @since 2.5.0.1
|
||||
|
@ -53,24 +53,23 @@ public class Tools {
|
|||
public static class Downloader {
|
||||
|
||||
/**
|
||||
* Downloads a page/content from the Internet.
|
||||
* This method gets the content of the web page, whose URL is given by
|
||||
* the <code>pageAddress</code>.
|
||||
*
|
||||
* <p>NOTE: <code>pageAddress</code> should be a correct URL, else
|
||||
* this method will throw {@link MalformedURLException}.
|
||||
*
|
||||
* @param pageAddress
|
||||
* Address of the web page to get from the Internet.
|
||||
*
|
||||
* Downloads a page/content from the Internet. This method gets the
|
||||
* content of the web page, whose URL is given by the
|
||||
* <code>pageAddress</code>.
|
||||
* <p>
|
||||
* <p>
|
||||
* NOTE: <code>pageAddress</code> should be a correct URL, else this
|
||||
* method will throw {@link MalformedURLException}.
|
||||
* <p>
|
||||
* @param pageAddress Address of the web page to get from the Internet.
|
||||
* <p>
|
||||
* @return Content of the web page
|
||||
*
|
||||
* @throws MalformedURLException
|
||||
* Address of the web page is not correct.
|
||||
*
|
||||
* @throws IOException
|
||||
* Error while loading the page from the Internet or connection
|
||||
* got disconnected.
|
||||
* <p>
|
||||
* @throws MalformedURLException Address of the web page is not correct.
|
||||
* <p>
|
||||
* @throws IOException Error while loading the page from the
|
||||
* Internet or connection got
|
||||
* disconnected.
|
||||
*/
|
||||
public static String downloadPage(String pageAddress)
|
||||
throws MalformedURLException, IOException {
|
||||
|
@ -89,11 +88,10 @@ public class Tools {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Provides methods to do conversions.
|
||||
* For example, converting degree to direction, etc.
|
||||
*
|
||||
* Provides methods to do conversions. For example, converting degree to
|
||||
* direction, etc.
|
||||
* <p>
|
||||
* @author Ashutosh Kumar Singh
|
||||
* @version 2013/08/05
|
||||
* @since 2.5.0.1
|
||||
|
@ -102,14 +100,14 @@ public class Tools {
|
|||
|
||||
/**
|
||||
* Converts degree to direction.
|
||||
* @param degree
|
||||
* <p>
|
||||
* @param degree <p>
|
||||
* @return Direction
|
||||
*
|
||||
* @throws IllegalArgumentException
|
||||
* Degree should be between 0 and 360.
|
||||
* <p>
|
||||
* @throws IllegalArgumentException Degree should be between 0 and 360.
|
||||
*/
|
||||
public String convertDegree2Direction(float degree)
|
||||
throws IllegalArgumentException{
|
||||
throws IllegalArgumentException {
|
||||
String direction;
|
||||
|
||||
// degree should be between 0 and 360
|
||||
|
@ -119,53 +117,37 @@ public class Tools {
|
|||
|
||||
if (degree <= 11.25f) {
|
||||
direction = "N";
|
||||
}
|
||||
else if (degree <= 33.75f) {
|
||||
} else if (degree <= 33.75f) {
|
||||
direction = "NNE";
|
||||
}
|
||||
else if (degree <= 56.25f) {
|
||||
} else if (degree <= 56.25f) {
|
||||
direction = "NE";
|
||||
}
|
||||
else if (degree <= 78.75f) {
|
||||
} else if (degree <= 78.75f) {
|
||||
direction = "ENE";
|
||||
}
|
||||
else if (degree <= 101.25f) {
|
||||
} else if (degree <= 101.25f) {
|
||||
direction = "E";
|
||||
}
|
||||
else if (degree <= 123.75f) {
|
||||
} else if (degree <= 123.75f) {
|
||||
direction = "ESE";
|
||||
}
|
||||
else if (degree <= 146.25f) {
|
||||
} else if (degree <= 146.25f) {
|
||||
direction = "SE";
|
||||
}
|
||||
else if (degree <= 168.75f) {
|
||||
} else if (degree <= 168.75f) {
|
||||
direction = "SSE";
|
||||
}
|
||||
else if (degree <= 191.25f) {
|
||||
} else if (degree <= 191.25f) {
|
||||
direction = "S";
|
||||
}
|
||||
else if (degree <= 213.75f) {
|
||||
} else if (degree <= 213.75f) {
|
||||
direction = "SSW";
|
||||
}
|
||||
else if (degree <= 236.25f) {
|
||||
} else if (degree <= 236.25f) {
|
||||
direction = "SW";
|
||||
}
|
||||
else if (degree <= 258.75f) {
|
||||
} else if (degree <= 258.75f) {
|
||||
direction = "WSW";
|
||||
}
|
||||
else if (degree <= 281.25f) {
|
||||
} else if (degree <= 281.25f) {
|
||||
direction = "W";
|
||||
}
|
||||
else if (degree <= 303.75f) {
|
||||
} else if (degree <= 303.75f) {
|
||||
direction = "WNW";
|
||||
}
|
||||
else if (degree <= 326.25f) {
|
||||
} else if (degree <= 326.25f) {
|
||||
direction = "NW";
|
||||
}
|
||||
else if (degree <= 348.75f) {
|
||||
} else if (degree <= 348.75f) {
|
||||
direction = "NNW";
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
direction = "N";
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue