feat: documentation
This commit is contained in:
parent
1548da7b4b
commit
a7ec614471
@ -4,14 +4,18 @@ import java.time.Instant;
|
|||||||
import java.util.concurrent.locks.Condition;
|
import java.util.concurrent.locks.Condition;
|
||||||
|
|
||||||
public class WeatherData {
|
public class WeatherData {
|
||||||
enum Condition {
|
|
||||||
|
/**
|
||||||
|
* Representation of a weather condition (with a smiley for String representation)
|
||||||
|
*/
|
||||||
|
public enum Condition {
|
||||||
SUNNY("☀️"),
|
SUNNY("☀️"),
|
||||||
PARTIAL("🌤"),
|
PARTIAL("🌤"),
|
||||||
CLOUDY("☁️"),
|
CLOUDY("☁️"),
|
||||||
RAINY("🌧"),
|
RAINY("🌧"),
|
||||||
ERROR("E");
|
ERROR("E");
|
||||||
|
|
||||||
private String desc;
|
private final String desc;
|
||||||
Condition(String desc) { this.desc = desc; }
|
Condition(String desc) { this.desc = desc; }
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -20,7 +24,10 @@ public class WeatherData {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
enum WindDirection {
|
/**
|
||||||
|
* Representation of the wind direction with an arrow
|
||||||
|
*/
|
||||||
|
public enum WindDirection {
|
||||||
N("🡩"),
|
N("🡩"),
|
||||||
NE("🡭"),
|
NE("🡭"),
|
||||||
E("🡪"),
|
E("🡪"),
|
||||||
@ -31,7 +38,7 @@ public class WeatherData {
|
|||||||
NW("🡬"),
|
NW("🡬"),
|
||||||
ERROR("E");
|
ERROR("E");
|
||||||
|
|
||||||
private String desc;
|
private final String desc;
|
||||||
WindDirection(String desc) {this.desc = desc;}
|
WindDirection(String desc) {this.desc = desc;}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -45,9 +52,14 @@ public class WeatherData {
|
|||||||
private Condition condition; // cloudly, sunny ...
|
private Condition condition; // cloudly, sunny ...
|
||||||
private float windSpeed;
|
private float windSpeed;
|
||||||
private float windDirectionAngle;
|
private float windDirectionAngle;
|
||||||
private WindDirection windDirection;
|
private final WindDirection windDirection;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get wind direction representation based on the angle
|
||||||
|
* @param windDirectionAngle float representation of the wind direction
|
||||||
|
* @return wind direction representation
|
||||||
|
*/
|
||||||
private WindDirection getWindDirection(float windDirectionAngle) {
|
private WindDirection getWindDirection(float windDirectionAngle) {
|
||||||
if (windDirectionAngle >= 337.5 || windDirectionAngle <= 22.5)
|
if (windDirectionAngle >= 337.5 || windDirectionAngle <= 22.5)
|
||||||
return WindDirection.N;
|
return WindDirection.N;
|
||||||
@ -69,6 +81,7 @@ public class WeatherData {
|
|||||||
return WindDirection.ERROR;
|
return WindDirection.ERROR;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
WeatherData(City city, Instant date, float temp, float windSpeed, float windDirectionAngle, Condition condition) {
|
WeatherData(City city, Instant date, float temp, float windSpeed, float windDirectionAngle, Condition condition) {
|
||||||
this.city = city;
|
this.city = city;
|
||||||
this.date = date;
|
this.date = date;
|
||||||
@ -79,56 +92,104 @@ public class WeatherData {
|
|||||||
this.windDirection = this.getWindDirection(windDirectionAngle);
|
this.windDirection = this.getWindDirection(windDirectionAngle);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return city
|
||||||
|
*/
|
||||||
public City getCity() {
|
public City getCity() {
|
||||||
return city;
|
return city;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @return date of the Weather data
|
||||||
|
*/
|
||||||
public Instant getDate() {
|
public Instant getDate() {
|
||||||
return date;
|
return date;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return Weather Condition representation
|
||||||
|
*/
|
||||||
public Condition getCondition() {
|
public Condition getCondition() {
|
||||||
return condition;
|
return condition;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return float temperature
|
||||||
|
*/
|
||||||
public float getTemp() {
|
public float getTemp() {
|
||||||
return temp;
|
return temp;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return wind speed
|
||||||
|
*/
|
||||||
public float getWindSpeed() {
|
public float getWindSpeed() {
|
||||||
return windSpeed;
|
return windSpeed;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return Wind direction angle
|
||||||
|
*/
|
||||||
public float getWindDirectionAngle() {return this.windDirectionAngle;}
|
public float getWindDirectionAngle() {return this.windDirectionAngle;}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return wind direction representation
|
||||||
|
*/
|
||||||
public WindDirection getWindDirection() {
|
public WindDirection getWindDirection() {
|
||||||
return windDirection;
|
return windDirection;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set city
|
||||||
|
* @param city city of the weather representation
|
||||||
|
*/
|
||||||
public void setCity(City city) {
|
public void setCity(City city) {
|
||||||
this.city = city;
|
this.city = city;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set date of the weather data
|
||||||
|
* @param date date
|
||||||
|
*/
|
||||||
public void setDate(Instant date) {
|
public void setDate(Instant date) {
|
||||||
this.date = date;
|
this.date = date;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set weather data representation
|
||||||
|
* @param condition weather data representation
|
||||||
|
*/
|
||||||
public void setCondition(Condition condition) {
|
public void setCondition(Condition condition) {
|
||||||
this.condition = condition;
|
this.condition = condition;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param temp Weather data temperature
|
||||||
|
*/
|
||||||
public void setTemp(float temp) {
|
public void setTemp(float temp) {
|
||||||
this.temp = temp;
|
this.temp = temp;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param windSpeed Wind speed
|
||||||
|
*/
|
||||||
public void setWindSpeed(float windSpeed) {
|
public void setWindSpeed(float windSpeed) {
|
||||||
this.windSpeed = windSpeed;
|
this.windSpeed = windSpeed;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param windDirectionAngle wind direction angle
|
||||||
|
*/
|
||||||
public void setWindDirectionAngle(float windDirectionAngle) {
|
public void setWindDirectionAngle(float windDirectionAngle) {
|
||||||
this.windDirectionAngle = windDirectionAngle;
|
this.windDirectionAngle = windDirectionAngle;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* WeatherData representation
|
||||||
|
* 10,70° 🌧 25,80km/h 243,00° 🡯
|
||||||
|
* @return String representation of the WeatherData
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return String.format("%05.2f° %s %05.2fkm/h %06.2f° %s",
|
return String.format("%05.2f° %s %05.2fkm/h %06.2f° %s",
|
||||||
|
@ -3,6 +3,9 @@ package eirb.pg203;
|
|||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Interface to discuss with a weather API
|
||||||
|
*/
|
||||||
public interface WeatherDataAPI {
|
public interface WeatherDataAPI {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -24,6 +27,13 @@ public interface WeatherDataAPI {
|
|||||||
*/
|
*/
|
||||||
WeatherData getTemperature(int day, int hour, String city) throws IOException;
|
WeatherData getTemperature(int day, int hour, String city) throws IOException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Fetch the temperature for multiple day since today
|
||||||
|
* @param days number of days to fetch
|
||||||
|
* @param city name of te city
|
||||||
|
* @return List of WeatherData
|
||||||
|
* @throws IOException when request failed
|
||||||
|
*/
|
||||||
ArrayList<WeatherData> getTemperatures(int days, String city) throws IOException;
|
ArrayList<WeatherData> getTemperatures(int days, String city) throws IOException;
|
||||||
|
|
||||||
/***
|
/***
|
||||||
|
@ -4,12 +4,18 @@ import java.util.ArrayList;
|
|||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
|
||||||
class WeatherDisplayBasic implements WeatherDisplay {
|
class WeatherDisplayBasic implements WeatherDisplay {
|
||||||
private ArrayList<WeatherDataAPI> apis;
|
/**
|
||||||
|
* List of apis
|
||||||
WeatherDisplayBasic() {
|
*/
|
||||||
this.apis = new ArrayList<WeatherDataAPI>();
|
private final ArrayList<WeatherDataAPI> apis = new ArrayList<>();
|
||||||
}
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Display header
|
||||||
|
* Source J + 0 J + 1 J + 2
|
||||||
|
* @param days number of columns
|
||||||
|
* @param sourceColumnSize size of the first column
|
||||||
|
* @param dayColumnSize day column size
|
||||||
|
*/
|
||||||
private void displayHeader(int days, double sourceColumnSize, double dayColumnSize) {
|
private void displayHeader(int days, double sourceColumnSize, double dayColumnSize) {
|
||||||
StringBuilder line = new StringBuilder();
|
StringBuilder line = new StringBuilder();
|
||||||
line.append("Source\t");
|
line.append("Source\t");
|
||||||
@ -26,6 +32,13 @@ class WeatherDisplayBasic implements WeatherDisplay {
|
|||||||
System.out.println(line);
|
System.out.println(line);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Calculate column size based on the WeatherData
|
||||||
|
* Check the size of the string of the weather data and return the max for the column
|
||||||
|
* WARNING : Special chars in the WeatherData string will introduce an offset
|
||||||
|
* @param weatherDataAPIArrayListHashMap list of Weather data for every WeatherDataApi
|
||||||
|
* @return day column size
|
||||||
|
*/
|
||||||
private double getColumnSize(HashMap<WeatherDataAPI, ArrayList<WeatherData>> weatherDataAPIArrayListHashMap) {
|
private double getColumnSize(HashMap<WeatherDataAPI, ArrayList<WeatherData>> weatherDataAPIArrayListHashMap) {
|
||||||
double max = 0;
|
double max = 0;
|
||||||
for (WeatherDataAPI api: weatherDataAPIArrayListHashMap.keySet()) {
|
for (WeatherDataAPI api: weatherDataAPIArrayListHashMap.keySet()) {
|
||||||
@ -39,6 +52,15 @@ class WeatherDisplayBasic implements WeatherDisplay {
|
|||||||
return max;
|
return max;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Display a line of data with a column separator
|
||||||
|
* OpenWeatherMap | 14,49° ☁️ 07,71km/h 254,25° 🡨 | 11,29° ☁️ 04,33km/h 296,00° 🡬 | 12,06° ☁️ 07,53km/h 188,88° 🡫 |
|
||||||
|
* @param apiName Name of the api if the first column
|
||||||
|
* @param weatherDatas List of Weather data to display
|
||||||
|
* @param startColumnString Separator between column
|
||||||
|
* @param sourceColumnSize Size of the first column
|
||||||
|
* @param dayColumnSize Size for day columns
|
||||||
|
*/
|
||||||
private void displayWeatherDatas(String apiName, ArrayList<WeatherData> weatherDatas, String startColumnString, double sourceColumnSize, double dayColumnSize) {
|
private void displayWeatherDatas(String apiName, ArrayList<WeatherData> weatherDatas, String startColumnString, double sourceColumnSize, double dayColumnSize) {
|
||||||
StringBuilder line = new StringBuilder();
|
StringBuilder line = new StringBuilder();
|
||||||
String weatherDataString;
|
String weatherDataString;
|
||||||
@ -61,6 +83,13 @@ class WeatherDisplayBasic implements WeatherDisplay {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Display in stdout the line between apis
|
||||||
|
* -------------------------------+------------------------------+------------------------------+------------------------------+
|
||||||
|
* @param days number of days to display
|
||||||
|
* @param sourceColumnSize size for the first column (where the name of the api is display)
|
||||||
|
* @param dayColumnSize column size for the days (where the temperature is displayed)
|
||||||
|
*/
|
||||||
private void displaySeparatorLine(int days, double sourceColumnSize, double dayColumnSize) {
|
private void displaySeparatorLine(int days, double sourceColumnSize, double dayColumnSize) {
|
||||||
String mainSeparator = "-";
|
String mainSeparator = "-";
|
||||||
String secondSeparator = "+";
|
String secondSeparator = "+";
|
||||||
@ -77,6 +106,20 @@ class WeatherDisplayBasic implements WeatherDisplay {
|
|||||||
System.out.println(line);
|
System.out.println(line);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Display an array like this in stdout
|
||||||
|
* Source J + 0 J + 1 J + 2
|
||||||
|
* -------------------------------+------------------------------+------------------------------+------------------------------+
|
||||||
|
* OpenWeatherMap | 14,49° ☁️ 07,71km/h 254,25° 🡨 | 11,29° ☁️ 04,33km/h 296,00° 🡬 | 12,06° ☁️ 07,53km/h 188,88° 🡫 |
|
||||||
|
* -------------------------------+------------------------------+------------------------------+------------------------------+
|
||||||
|
* WeatherAPI | 12,50° 🌧 20,31km/h 238,67° 🡯 | 11,20° 🌧 17,23km/h 291,92° 🡨 | 11,00° 🌧 25,59km/h 256,88° 🡨 |
|
||||||
|
* -------------------------------+------------------------------+------------------------------+------------------------------+
|
||||||
|
* OpenMeteo | 10,70° 🌧 25,80km/h 243,00° 🡯 | 11,35° 🌧 24,30km/h 276,00° 🡨 | 11,00° 🌧 31,50km/h 238,00° 🡯 |
|
||||||
|
* -------------------------------+------------------------------+------------------------------+------------------------------+
|
||||||
|
*
|
||||||
|
* @param weatherDataAPIArrayListHashMap Hashmap with WeatherData array for each api
|
||||||
|
* @param days number of days to display
|
||||||
|
*/
|
||||||
private void displayAllWeatherDatas(HashMap<WeatherDataAPI, ArrayList<WeatherData>> weatherDataAPIArrayListHashMap, int days) {
|
private void displayAllWeatherDatas(HashMap<WeatherDataAPI, ArrayList<WeatherData>> weatherDataAPIArrayListHashMap, int days) {
|
||||||
double dayColumnSize = this.getColumnSize(weatherDataAPIArrayListHashMap);
|
double dayColumnSize = this.getColumnSize(weatherDataAPIArrayListHashMap);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user