diff --git a/.github/stale.yml b/.github/stale.yml new file mode 100644 index 00000000..dc90e5a1 --- /dev/null +++ b/.github/stale.yml @@ -0,0 +1,17 @@ +# Number of days of inactivity before an issue becomes stale +daysUntilStale: 60 +# Number of days of inactivity before a stale issue is closed +daysUntilClose: 7 +# Issues with these labels will never be considered stale +exemptLabels: + - pinned + - security +# Label to use when marking an issue as stale +staleLabel: wontfix +# Comment to post when marking an issue as stale. Set to `false` to disable +markComment: > + This issue has been automatically marked as stale because it has not had + recent activity. It will be closed if no further activity occurs. Thank you + for your contributions. +# Comment to post when closing a stale issue. Set to `false` to disable +closeComment: false diff --git a/.travis.yml b/.travis.yml index a5d1f127..d915a91c 100644 --- a/.travis.yml +++ b/.travis.yml @@ -29,7 +29,8 @@ before_deploy: deploy: provider: releases - file: target/metarParser-${VERSION}.jar + file_glob: true + file: /**/target/*.jar api_key: $GITHUB_OATH skip_cleanup: true draft: true diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 8b652c90..6ce82ea6 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -3,7 +3,7 @@ **Have you found a bug** -Open an issue describing the bug and the steps to reproduce it. +Open an issue describing the bug, and the steps to reproduce it. If you are willing to fix the bug: * Open a Github Pull request @@ -21,7 +21,7 @@ The keywords feature, bugfix and clean are mandatory for branch name. * Do bot update the pom.xml, it will be updated accordingly to the branch name -* Add new code and the tests +* Add new code and tests * Push code and create the pull request towards the master branch @@ -29,6 +29,6 @@ The keywords feature, bugfix and clean are mandatory for branch name. This project currently supports English and French languages. If you are willing to add a new language, please use https://poeditor.com/join/project/kWbkKRuHlr to register and contribute. -Once a language is completed at 100%, the file will be added to the project. +Once a language is complete at 100%, the file will be added to the project. Thank you diff --git a/README.md b/README.md index 4165caed..29eacd97 100644 --- a/README.md +++ b/README.md @@ -1,12 +1,12 @@ -[![Build Status](https://travis-ci.org/mivek/MetarParser.svg?branch=master)](https://travis-ci.org/mivek/MetarParser) +[![Build Status](https://travis-ci.com/mivek/MetarParser.svg?branch=master)](https://travis-ci.org/mivek/MetarParser) [![Quality Gate Status](https://sonarcloud.io/api/project_badges/measure?project=io.github.mivek%3AmetarParser&metric=alert_status)](https://sonarcloud.io/dashboard?id=io.github.mivek%3AmetarParser) [![Coverage](https://sonarcloud.io/api/project_badges/measure?project=io.github.mivek%3AmetarParser&metric=coverage)](https://sonarcloud.io/dashboard?id=io.github.mivek%3AmetarParser) [![GitHub license](https://img.shields.io/github/license/mivek/MetarParser.svg)](https://github.com/mivek/MetarParser/blob/master/LICENSE) -![Maven Central](https://img.shields.io/maven-central/v/io.github.mivek/metarParser.svg) +[![Maven Central](https://img.shields.io/maven-central/v/io.github.mivek/metarParser.svg)](https://search.maven.org/artifact/io.github.mivek/metarParser/) ![](jetbrains_small.png) -# MetarParser +# MetarParser This java lib provides a Metar and TAF decoder. @@ -15,135 +15,177 @@ Use the MetarFacade class and its method retrieveFromAirport to get the metar of The trends of the metar are not parsed. ## Table of content -1. [Adding dependency](https://github.com/mivek/MetarParser#adding-the-dependency) -2. [Model](https://github.com/mivek/MetarParser#model) - 1. [Enumerations](https://github.com/mivek/MetarParser#enumerations) - 2. [Classes](https://github.com/mivek/MetarParser#classes) -3. [Examples](https://github.com/mivek/MetarParser#examples) - 1. [Parse a metar](https://github.com/mivek/MetarParser#parse-a-metar) - 2. [Retrieve a metar](https://github.com/mivek/MetarParser#retrieve-the-metar-of-an-airport) - 3. [Parse a taf](https://github.com/mivek/MetarParser#parse-a-taf) - 4. [Retrieve a taf](https://github.com/mivek/MetarParser#retrieve-a-taf) -4. [Internationalization](https://github.com/mivek/MetarParser#internationalization) + +1. [Adding dependency](#adding-the-dependency) +2. [Model](#model) + 1. [Enumerations](#enumerations) + 2. [Classes](#classes) +3. [Examples](#examples) + 1. [Parse a metar](#parse-a-metar) + 2. [Retrieve a metar](#retrieve-the-metar-of-an-airport) + 3. [Parse a taf](#parse-a-taf) + 4. [Retrieve a taf](#retrieve-a-taf) +4. [Internationalization](#internationalization) + +## Architecture of the project + +This project is divided into multiple maven module + +- metarParser-entities: Contains the model and the enumerations +- metarParser-parsers: Contains the parsers and the commands +- metarParser-services: Contains a service allowing you to parse or retrieve METAR and TAF +- metarParser-spi: Contains the SPI +- metarParser-commons: Contains utility and internationalization classes ## Adding the dependency + +To add the service module : + ```xml io.github.mivek - metarParser + metarParser-services latest ``` Or check [here](https://search.maven.org/artifact/io.github.mivek/metarParser/) if you are not using maven. + ## Model -The model is generated by using the Eclipse visualization tool [ObjectAid](http://www.objectaid.com/home). -When updating classes in packages io.github.mivek.enums or io.github.mivek.model, the class diagram is also updated. -When added a new class/enumeration in one of those package, drag and drop the new class to model.ucls and generate a new jpeg of the class diagram. + +The class diagrams are generated by IntelliJ +When updating classes, regenerate the diagrams and save the images in the project. ![class diagram](model.jpg) + ### Enumerations The application contains numerous enumerations to represent data. - - CloudType: to represent the type of cloud. - - CloudQuantity: to represent the amount of clouds. - - Intensity: to represent the intensity of a meteorological phenomenon. - - Descriptive: to represent the descriptive of a meteorological phenomenon. - - Phenomenon: to represent a phenomenon. - - WeatherChangeTime: to represent a trend. - - TimeIndicator: to represent the time of the trend. - + +- CloudType: to represent the type of cloud. +- CloudQuantity: to represent the amount of clouds. +- Intensity: to represent the intensity of a meteorological phenomenon. +- Descriptive: to represent the descriptive of a meteorological phenomenon. +- Phenomenon: to represent a phenomenon. +- WeatherChangeTime: to represent a trend. +- TimeIndicator: to represent the time of the trend. + ### Classes #### Airport + The airport class is composed of - - Name - - City - - Country - - IATA code - - ICAO code - - latitude - - longitude - - altitude - - timezone - -#### Cloud + +- Name +- City +- Country +- IATA code +- ICAO code +- latitude +- longitude +- altitude +- timezone + Note: Depending on the source for the airports, fields can be null + +#### Cloud + In this application a cloud is composed of - - CloudQuantity - - CloudType (optional) - - height (optional) - + +- CloudQuantity +- CloudType (optional) +- height (optional) + #### Country + A country is represented by its name. #### Runway information The runway information is composed of - - The name of the runway - - The minimal visibility on the runway - - The maximal visibility on the runway (optional) - - The trend of the visibility (optional) + +- The name of the runway +- The minimal visibility on the runway +- The maximal visibility on the runway (optional) +- The trend of the visibility (optional) #### Visibility The visibility class is composed of - - The main visibility - - The minimal visibility (optional) - - The direction of the minimal visibility (optional) + +- The main visibility +- The minimal visibility (optional) +- The direction of the minimal visibility (optional) #### WeatherCondition + The weather condition is class to represent a meteorological phenomenon. A weather condition is composed of - - an intensity (optional) - - a descriptive (optional) - - a list of phenomenon - + +- an intensity (optional) +- a descriptive (optional) +- a list of phenomenon + #### Wind + The wind class is composed of - - the speed - - the direction - - the speed of the gust - - the minimal wind variation in degrees - - the maximal wind variation in degrees - - the unit of the wind's speed - + +- the speed +- the direction +- the speed of the gust +- the minimal wind variation in degrees +- the maximal wind variation in degrees +- the unit of the wind's speed + #### WindShear + This class is a subclass of Wind. It is composed of - - the height of the wind shear. +- the height of the wind shear. ### Trends + ![trends diagram](trend.jpg) Numerous classes represents the trends. Trends are stored inside a list of the metar object `Metar.getTrends()`. Trends are composed of - - a Type (BECMG or TEMPO) - - a wind - - a visibility and vertical visibility - - a list of clouds - - a list of weather conditions - - a list of `AbstractMetarTrendTime` to represent the time with its type (AT, FM, TL) +- a Type (BECMG or TEMPO) +- a wind +- a visibility and vertical visibility +- a list of clouds +- a list of weather conditions +- a list of `AbstractMetarTrendTime` to represent the time with its type (AT, FM, TL) + +## Airports loading + +By default, airports are loaded from the temporary file [airport.dat](metarParser-spi/src/main/resources/data/airports.dat) +It is possible to provide your own source of airports via spi. +See [spi](metarParser-spi/README.md) module for details. ## Examples + ### Parse a metar + Instantiate the metarFacade and use its method parse. ```java String code = "LFPG 131830Z 19005KT 170V250 9999 -SHRA FEW040TCU SCT086 16/08 Q1011"; -MetarFacade facade = MetarFacade.getInstance(); -Metar metar = facade.decode(code); +MetarService service = MetarService.getInstance(); +Metar metar = service.decode(code); ``` ### Retrieve the metar of an airport + Instantiate the metarFacade. Use the its method retrieveFromAirport with the ICAO code of the airport. ```java String icao = "LFPG"; -MetarFacade facade = MetarFacade.getInstance(); -Metar metar = facade.retrieveFromAirport(icao); +MetarService service = MetarService.getInstance(); +Metar metar = service.retrieveFromAirport(icao); ``` + ### Parse a taf + Use the TAFFacade to decode the taf. ```java @@ -154,29 +196,35 @@ String message = "TAF LFPG 150500Z 1506/1612 17005KT 6000 SCT012 \n" +"BECMG 1520/1522 CAVOK \n" +"TEMPO 1603/1608 3000 BR BKN006 PROB40 \n" +"TEMPO 1604/1607 0400 BCFG BKN002 TX17/1512Z TN07/1605Z"; -TAFFacade facade = TAFFacade.getInstance(); -TAF taf = facade.decode(message); +TAFService service = TAFService.getInstance(); +TAF taf = service.decode(message); ``` -Lines of the message have to be separated by a "\n" character. + +Lines of the message have to be separated by a "\\n" character. ### Retrieve a taf + Use the TAFFacade and the method retrieveFromAirport with the ICAO code of the airport. ```java String icao = "LFPG"; -TAFFacade facade = TAFFacade.getInstance(); -TAF taf = facade.retrieveFromAirport(icao); +TAFService service = TAFService.getInstance(); +TAF taf = service.retrieveFromAirport(icao); ``` ### Internationalization + English and french locales are supported by the library. The library uses the user's locale. The default locale is english. #### Change the locale and contributing + To change the locale use the method `setLocale(Locale)` of the class `Messages.java` + ```(java) Messages.getInstance().setLocale(Locale.FRENCH); // Changes the locale to french. ``` + If you are willing to add a new locale or contribute to the project please see [Contributing.md file](CONTRIBUTING.md). [Jetbrains](https://www.jetbrains.com/?from=metarParser) open source project. diff --git a/checkstyle.xml b/checkstyle.xml index 96a6132b..e0612958 100644 --- a/checkstyle.xml +++ b/checkstyle.xml @@ -1,6 +1,9 @@ + - + @@ -27,7 +30,9 @@ Checkstyle configuration that checks the sun coding conventions. + + @@ -55,8 +60,8 @@ Checkstyle configuration that checks the sun coding conventions. - + @@ -81,6 +86,7 @@ Checkstyle configuration that checks the sun coding conventions. + diff --git a/metarParser-commons/README.md b/metarParser-commons/README.md new file mode 100644 index 00000000..5995e7bf --- /dev/null +++ b/metarParser-commons/README.md @@ -0,0 +1,3 @@ +# MetarParser-common module + +This module contains utility classes and i18n classes. diff --git a/metarParser-commons/pom.xml b/metarParser-commons/pom.xml new file mode 100644 index 00000000..d8dd5ebd --- /dev/null +++ b/metarParser-commons/pom.xml @@ -0,0 +1,21 @@ + + + + metarParser + io.github.mivek + 1.10.5 + + 4.0.0 + + metarParser-commons + Module containing utility classes + + + 0.99 + 0.99 + 0.99 + + + diff --git a/src/main/java/io/github/mivek/internationalization/Messages.java b/metarParser-commons/src/main/java/io/github/mivek/internationalization/Messages.java similarity index 59% rename from src/main/java/io/github/mivek/internationalization/Messages.java rename to metarParser-commons/src/main/java/io/github/mivek/internationalization/Messages.java index 44b1e8f3..6378e35f 100644 --- a/src/main/java/io/github/mivek/internationalization/Messages.java +++ b/metarParser-commons/src/main/java/io/github/mivek/internationalization/Messages.java @@ -1,58 +1,61 @@ -package io.github.mivek.internationalization; - -import java.text.MessageFormat; -import java.util.Locale; -import java.util.ResourceBundle; - -/** - * Messages class for internationalization. - * @author mivek - */ -public final class Messages { - /** The singleton instance. */ - private static final Messages INSTANCE = new Messages(); - /** Name of the bundle. */ - private static final String BUNDLE_NAME = "internationalization.messages"; //$NON-NLS-1$ - /** Bundle variable. */ - private ResourceBundle fResourceBundle; - /** - * Private constructor. - */ - private Messages() { - fResourceBundle = ResourceBundle.getBundle(BUNDLE_NAME); - } - - /** - * @return the Messages instance. - */ - public static Messages getInstance() { - return INSTANCE; - } - /** - * Sets the locale of the bundle. - * @param pLocale the locale to set. - */ - public void setLocale(final Locale pLocale) { - Locale.setDefault(pLocale); - ResourceBundle.clearCache(); - fResourceBundle = ResourceBundle.getBundle(BUNDLE_NAME, pLocale); - } - - - /** - * @param pString the string to get - * @return the translation of pString - */ - public String getString(final String pString) { - return fResourceBundle.getString(pString); - } - - /** - * @param pString the translation to get - * @param pArguments the arguments to fill - * @return the translation of pString with the arguments. - */ - public String getString(final String pString, final Object... pArguments) { - return MessageFormat.format(getString(pString), pArguments); - } -} +package io.github.mivek.internationalization; + +import java.text.MessageFormat; +import java.util.Locale; +import java.util.ResourceBundle; + +/** + * Messages class for internationalization. + * + * @author mivek + */ +public final class Messages { + /** The singleton instance. */ + private static final Messages INSTANCE = new Messages(); + /** Name of the bundle. */ + private static final String BUNDLE_NAME = "internationalization.messages"; //$NON-NLS-1$ + /** Bundle variable. */ + private ResourceBundle fResourceBundle; + + /** + * Private constructor. + */ + private Messages() { + fResourceBundle = ResourceBundle.getBundle(BUNDLE_NAME); + } + + /** + * @return the Messages instance. + */ + public static Messages getInstance() { + return INSTANCE; + } + + /** + * Sets the locale of the bundle. + * + * @param locale the locale to set. + */ + public void setLocale(final Locale locale) { + Locale.setDefault(locale); + ResourceBundle.clearCache(); + fResourceBundle = ResourceBundle.getBundle(BUNDLE_NAME, locale); + } + + /** + * @param message the string to get + * @return the translation of message + */ + public String getString(final String message) { + return fResourceBundle.getString(message); + } + + /** + * @param message the translation to get + * @param arguments the arguments to fill + * @return the translation of ;essqge with the arguments. + */ + public String getString(final String message, final Object... arguments) { + return MessageFormat.format(getString(message), arguments); + } +} diff --git a/src/main/java/io/github/mivek/internationalization/package-info.java b/metarParser-commons/src/main/java/io/github/mivek/internationalization/package-info.java similarity index 89% rename from src/main/java/io/github/mivek/internationalization/package-info.java rename to metarParser-commons/src/main/java/io/github/mivek/internationalization/package-info.java index 3b2b18a3..5bf64864 100644 --- a/src/main/java/io/github/mivek/internationalization/package-info.java +++ b/metarParser-commons/src/main/java/io/github/mivek/internationalization/package-info.java @@ -1,5 +1,4 @@ -/** - * @author mivek - * - */ -package io.github.mivek.internationalization; +/** + * @author mivek + */ +package io.github.mivek.internationalization; diff --git a/src/main/java/io/github/mivek/utils/Converter.java b/metarParser-commons/src/main/java/io/github/mivek/utils/Converter.java similarity index 66% rename from src/main/java/io/github/mivek/utils/Converter.java rename to metarParser-commons/src/main/java/io/github/mivek/utils/Converter.java index 7ba276a9..806eed3f 100644 --- a/src/main/java/io/github/mivek/utils/Converter.java +++ b/metarParser-commons/src/main/java/io/github/mivek/utils/Converter.java @@ -1,151 +1,155 @@ -package io.github.mivek.utils; - -import io.github.mivek.internationalization.Messages; - -import java.time.LocalTime; - -/** - * This class is used to convert data. - * @author mivek - */ -public final class Converter { - - /** North East minimal degrees. */ - private static final double NORTH_EAST_MIN = 22.5; - /** North east maximal degrees. */ - private static final double NORTH_EAST_MAX = 67.5; - /** East degrees. */ - private static final double EAST = 112.5; - /** South East degrees. */ - private static final double SOUTH_EAST = 157.5; - /** South degrees. */ - private static final double SOUTH = 202.5; - /** North West degrees. */ - private static final double NORTH_WEST = 337.5; - /** West degrees. */ - private static final double WEST = 292.5; - /** South west degrees. */ - private static final double SOUTH_WEST = 247.5; - - /** - * Private constructor. - */ - private Converter() { - } - - /** - * This method converter degrees to direction. - * @param pDegreesStr a string representing the degrees. - * @return A string for the direction. - */ - public static String degreesToDirection(final String pDegreesStr) { - double degrees; - String res; - try { - degrees = Double.parseDouble(pDegreesStr); - } catch (NumberFormatException e) { - return Messages.getInstance().getString("Converter.VRB"); - } - - if (isBetween(degrees, NORTH_EAST_MIN, SOUTH)) { - if (isBetween(degrees, NORTH_EAST_MIN, NORTH_EAST_MAX)) { - res = Messages.getInstance().getString("Converter.NE"); - } else if (isBetween(degrees, NORTH_EAST_MAX, EAST)) { - res = Messages.getInstance().getString("Converter.E"); - } else if (isBetween(degrees, EAST, SOUTH_EAST)) { - res = Messages.getInstance().getString("Converter.SE"); - } else { - res = Messages.getInstance().getString("Converter.S"); - } - } else { - if (isBetween(degrees, SOUTH, SOUTH_WEST)) { - res = Messages.getInstance().getString("Converter.SW"); - } else if (isBetween(degrees, SOUTH_WEST, WEST)) { - res = Messages.getInstance().getString("Converter.W"); - } else if (isBetween(degrees, WEST, NORTH_WEST)) { - res = Messages.getInstance().getString("Converter.NW"); - } else { - res = Messages.getInstance().getString("Converter.N"); - } - } - return res; - } - - /** - * Checks if num is between lower and max. - * @param pNum - * double to test - * @param pLower - * the minimum value, included. - * @param pMax - * The maximum value, exluded. - * @return true if num is between lower and max, false otherwise. - */ - static boolean isBetween(final double pNum, final double pLower, final double pMax) { - return pLower <= pNum && pMax > pNum; - } - - /** - * Converts a string representing the visibility into a real visibility. - * @param pInput - * A string. - * @return a string correctly formatted. - */ - public static String convertVisibility(final String pInput) { - if ("9999".equals(pInput)) { //$NON-NLS-1$ - return ">10km"; //$NON-NLS-1$ - } else { - return Integer.parseInt(pInput) + "m"; //$NON-NLS-1$ - } - } - - /** - * Converts the metar part of temperature into integer. - * @param pInput The metar part of the temperature. - * @return an integer of the temperature. - */ - public static int convertTemperature(final String pInput) { - if (pInput.startsWith("M")) { //$NON-NLS-1$ - return -(Integer.parseInt(pInput.substring(1, 3))); - } else { - return Integer.parseInt(pInput); - } - } - - /** - * Converts the trend of clouds. - * @param pInput Single character string representing the trend. - * @return The signification of the single caracter. - */ - public static String convertTrend(final String pInput) { - if ("U".equals(pInput)) { //$NON-NLS-1$ - return Messages.getInstance().getString("Converter.U"); - } else if ("D".equals(pInput)) { //$NON-NLS-1$ - return Messages.getInstance().getString("Converter.D"); - } else if ("N".equals(pInput)) { //$NON-NLS-1$ - return Messages.getInstance().getString("Converter.NSC"); - } - return ""; //$NON-NLS-1$ - } - - /** - * Converts inches of mercury pressure into hecto pascals. - * @param pInchesMercury string of mercury. - * @return double of the pressure in Pascals. - */ - public static double inchesMercuryToHPascal(final double pInchesMercury) { - return 33.8639 * pInchesMercury; - } - - /** - * Converts a string representing a time to a LocalTime. - * Eg: "0830" returns a LocalTime of 08:30. - * @param pInput the string to convert. - * @return the corresponding time. - */ - public static LocalTime stringToTime(final String pInput) { - int hours = Integer.parseInt(pInput.substring(0, 2)); - int minutes = Integer.parseInt(pInput.substring(2)); - return LocalTime.of(hours, minutes); - } -} +package io.github.mivek.utils; + +import io.github.mivek.internationalization.Messages; + +import java.time.LocalTime; + +/** + * This class is used to convert data. + * + * @author mivek + */ +public final class Converter { + + /** North East minimal degrees. */ + private static final double NORTH_EAST_MIN = 22.5; + /** North east maximal degrees. */ + private static final double NORTH_EAST_MAX = 67.5; + /** East degrees. */ + private static final double EAST = 112.5; + /** South East degrees. */ + private static final double SOUTH_EAST = 157.5; + /** South degrees. */ + private static final double SOUTH = 202.5; + /** North West degrees. */ + private static final double NORTH_WEST = 337.5; + /** West degrees. */ + private static final double WEST = 292.5; + /** South west degrees. */ + private static final double SOUTH_WEST = 247.5; + + /** + * Private constructor. + */ + private Converter() { + } + + /** + * This method converter degrees to direction. + * + * @param degreesStr a string representing the degrees. + * @return A string for the direction. + */ + public static String degreesToDirection(final String degreesStr) { + double degrees; + String res; + try { + degrees = Double.parseDouble(degreesStr); + } catch (NumberFormatException e) { + return Messages.getInstance().getString("Converter.VRB"); + } + + if (isBetween(degrees, NORTH_EAST_MIN, SOUTH)) { + if (isBetween(degrees, NORTH_EAST_MIN, NORTH_EAST_MAX)) { + res = Messages.getInstance().getString("Converter.NE"); + } else if (isBetween(degrees, NORTH_EAST_MAX, EAST)) { + res = Messages.getInstance().getString("Converter.E"); + } else if (isBetween(degrees, EAST, SOUTH_EAST)) { + res = Messages.getInstance().getString("Converter.SE"); + } else { + res = Messages.getInstance().getString("Converter.S"); + } + } else { + if (isBetween(degrees, SOUTH, SOUTH_WEST)) { + res = Messages.getInstance().getString("Converter.SW"); + } else if (isBetween(degrees, SOUTH_WEST, WEST)) { + res = Messages.getInstance().getString("Converter.W"); + } else if (isBetween(degrees, WEST, NORTH_WEST)) { + res = Messages.getInstance().getString("Converter.NW"); + } else { + res = Messages.getInstance().getString("Converter.N"); + } + } + return res; + } + + /** + * Checks if num is between lower and max. + * + * @param num double to test + * @param lower the minimum value, included. + * @param max The maximum value, exluded. + * @return true if num is between lower and max, false otherwise. + */ + static boolean isBetween(final double num, final double lower, final double max) { + return lower <= num && max > num; + } + + /** + * Converts a string representing the visibility into a real visibility. + * + * @param input A string. + * @return a string correctly formatted. + */ + public static String convertVisibility(final String input) { + if ("9999".equals(input)) { //$NON-NLS-1$ + return ">10km"; //$NON-NLS-1$ + } else { + return Integer.parseInt(input) + "m"; //$NON-NLS-1$ + } + } + + /** + * Converts the metar part of temperature into integer. + * + * @param input The metar part of the temperature. + * @return an integer of the temperature. + */ + public static int convertTemperature(final String input) { + if (input.startsWith("M")) { //$NON-NLS-1$ + return -(Integer.parseInt(input.substring(1, 3))); + } else { + return Integer.parseInt(input); + } + } + + /** + * Converts the trend of clouds. + * + * @param input Single character string representing the trend. + * @return The signification of the single caracter. + */ + public static String convertTrend(final String input) { + if ("U".equals(input)) { //$NON-NLS-1$ + return Messages.getInstance().getString("Converter.U"); + } else if ("D".equals(input)) { //$NON-NLS-1$ + return Messages.getInstance().getString("Converter.D"); + } else if ("N".equals(input)) { //$NON-NLS-1$ + return Messages.getInstance().getString("Converter.NSC"); + } + return ""; //$NON-NLS-1$ + } + + /** + * Converts inches of mercury pressure into hecto pascals. + * + * @param inchesMercury string of mercury. + * @return double of the pressure in Pascals. + */ + public static double inchesMercuryToHPascal(final double inchesMercury) { + return 33.8639 * inchesMercury; + } + + /** + * Converts a string representing a time to a LocalTime. + * Eg: "0830" returns a LocalTime of 08:30. + * + * @param input the string to convert. + * @return the corresponding time. + */ + public static LocalTime stringToTime(final String input) { + int hours = Integer.parseInt(input.substring(0, 2)); + int minutes = Integer.parseInt(input.substring(2)); + return LocalTime.of(hours, minutes); + } +} diff --git a/src/main/java/io/github/mivek/utils/Regex.java b/metarParser-commons/src/main/java/io/github/mivek/utils/Regex.java similarity index 54% rename from src/main/java/io/github/mivek/utils/Regex.java rename to metarParser-commons/src/main/java/io/github/mivek/utils/Regex.java index 729b7121..11af0e67 100644 --- a/src/main/java/io/github/mivek/utils/Regex.java +++ b/metarParser-commons/src/main/java/io/github/mivek/utils/Regex.java @@ -1,87 +1,90 @@ -package io.github.mivek.utils; - -import java.util.regex.Matcher; -import java.util.regex.Pattern; - -/** - * Regex utility class. - * @author mivek - */ -public final class Regex { - - /** - * Private constructor. - */ - private Regex() { - } - - /** - * Similar to PHP function preg_match. Search a match between the pattern - * (regex) and the subject (input) and returns an array of string results. - * @param pPattern The pattern - * @param pInput - * The subject. - * @return Array of matches. - */ - public static String[] pregMatch(final Pattern pPattern, final String pInput) { - Matcher m = init(pPattern, pInput); - - if (m.find()) { - int length = m.groupCount() + 1; - String[] matches = new String[length]; - for (int i = 0; i < length; i++) { - matches[i] = m.group(i); - } - return matches; - } - return new String[0]; - } - - /** - * Tries to match the regex and the input. - * @param pPattern The compiled pattern - * @param pInput - * the input to test. - * @return true if the input matches the regex. - */ - public static boolean find(final Pattern pPattern, final String pInput) { - Matcher m = init(pPattern, pInput); - return m.find(); - } - - /** - * Returns the subsequence captured if the regex and the input matches. - * @param pPattern The compiled pattern. - * @param pInput - * The input string - * @return the finding string. - */ - public static String findString(final Pattern pPattern, final String pInput) { - Matcher m = init(pPattern, pInput); - if (m.find()) { - return m.group(1); - } - return null; - } - - /** - * Initiates and returns a matcher of the compiled pattern. - * @param pPattern the compiled pattern regex. - * @param pInput the input to test. - * @return the initiated matcher. - */ - private static Matcher init(final Pattern pPattern, final String pInput) { - return pPattern.matcher(pInput); - } - - /** - * Checks if the input matches the regex. - * @param pPattern the compiled pattern regex. - * @param pInput the input to test - * @return true if the input matches the regex. - */ - public static boolean match(final Pattern pPattern, final String pInput) { - Matcher m = init(pPattern, pInput); - return m.matches(); - } -} +package io.github.mivek.utils; + +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +/** + * Regex utility class. + * + * @author mivek + */ +public final class Regex { + + /** + * Private constructor. + */ + private Regex() { + } + + /** + * Similar to PHP function preg_match. Search a match between the pattern + * (regex) and the subject (input) and returns an array of string results. + * + * @param pattern The pattern + * @param input The subject. + * @return Array of matches. + */ + public static String[] pregMatch(final Pattern pattern, final String input) { + Matcher m = init(pattern, input); + + if (m.find()) { + int length = m.groupCount() + 1; + String[] matches = new String[length]; + for (int i = 0; i < length; i++) { + matches[i] = m.group(i); + } + return matches; + } + return new String[0]; + } + + /** + * Tries to match the regex and the input. + * + * @param pattern The compiled pattern + * @param input the input to test. + * @return true if the input matches the regex. + */ + public static boolean find(final Pattern pattern, final String input) { + Matcher m = init(pattern, input); + return m.find(); + } + + /** + * Returns the subsequence captured if the regex and the input matches. + * + * @param pattern The compiled pattern. + * @param input The input string + * @return the finding string. + */ + public static String findString(final Pattern pattern, final String input) { + Matcher m = init(pattern, input); + if (m.find()) { + return m.group(1); + } + return null; + } + + /** + * Initiates and returns a matcher of the compiled pattern. + * + * @param pattern the compiled pattern regex. + * @param input the input to test. + * @return the initiated matcher. + */ + private static Matcher init(final Pattern pattern, final String input) { + return pattern.matcher(input); + } + + /** + * Checks if the input matches the regex. + * + * @param pattern the compiled pattern regex. + * @param input the input to test + * @return true if the input matches the regex. + */ + public static boolean match(final Pattern pattern, final String input) { + Matcher m = init(pattern, input); + return m.matches(); + } +} diff --git a/src/main/java/io/github/mivek/utils/package-info.java b/metarParser-commons/src/main/java/io/github/mivek/utils/package-info.java similarity index 93% rename from src/main/java/io/github/mivek/utils/package-info.java rename to metarParser-commons/src/main/java/io/github/mivek/utils/package-info.java index 48733636..0c2f3d97 100644 --- a/src/main/java/io/github/mivek/utils/package-info.java +++ b/metarParser-commons/src/main/java/io/github/mivek/utils/package-info.java @@ -1,6 +1,6 @@ -/** - * Contains helper classes. - * - * @author mivek - */ -package io.github.mivek.utils; +/** + * Contains helper classes. + * + * @author mivek + */ +package io.github.mivek.utils; diff --git a/src/main/resources/internationalization/messages.properties b/metarParser-commons/src/main/resources/internationalization/messages.properties similarity index 97% rename from src/main/resources/internationalization/messages.properties rename to metarParser-commons/src/main/resources/internationalization/messages.properties index 5d300b19..b2f7690c 100644 --- a/src/main/resources/internationalization/messages.properties +++ b/metarParser-commons/src/main/resources/internationalization/messages.properties @@ -1,170 +1,170 @@ -CloudQuantity.BKN=broken -CloudQuantity.FEW=few -CloudQuantity.NSC=no significant clouds. -CloudQuantity.OVC=overcast -CloudQuantity.SCT=scattered -CloudQuantity.SKC=sky clear - -CloudType.AC=Altocumulus -CloudType.AS=Altostratus -CloudType.CB=Cumulonimbus -CloudType.CC=CirroCumulus -CloudType.CI=Cirrus -CloudType.CS=Cirrostratus -CloudType.CU=Cumulus -CloudType.NS=Nimbostratus -CloudType.SC=Stratocumulus -CloudType.ST=Stratus -CloudType.TCU=Towering cumulus - -Descriptive.BC=patches -Descriptive.BL=blowing -Descriptive.DR=low drifting -Descriptive.FZ=freezing -Descriptive.MI=shallow -Descriptive.PR=partial -Descriptive.SH=showers of -Descriptive.TS=thunderstorm -Error.prefix=An error occured. Error code n° -ErrorCode.AirportNotFound=The airport was not found for this message. -ErrorCode.InvalidMessage=The entered message is invalid. - -Intensity.-=Light -Intensity.+=Heavy -Intensity.VC=In the vicinity - -Phenomenon.BR=mist -Phenomenon.DS=duststorm -Phenomenon.DU=widespread dust -Phenomenon.DZ=drizzle -Phenomenon.FC=funnel cloud -Phenomenon.FG=fog -Phenomenon.FU=smoke -Phenomenon.GR=hail -Phenomenon.GS=small hail and/or snow pellets -Phenomenon.HZ=haze -Phenomenon.IC=ice crystals -Phenomenon.PL=ice pellets -Phenomenon.PO=dust or sand whirls -Phenomenon.PY=spray -Phenomenon.RA=rain -Phenomenon.SA=sand -Phenomenon.SG=snow grains -Phenomenon.SN=snow -Phenomenon.SQ=squall -Phenomenon.SS=sandstorm -Phenomenon.UP=unknown precipitation -Phenomenon.VA=volcanic ash -Phenomenon.TS=thunderstorm - -Remark.AO1=automated stations without a precipitation discriminator -Remark.AO2=automated station with a precipitation discriminator -Remark.BASED=based -Remark.Ceiling.Height=ceiling varying between {0} and {1} feet -Remark.Ceiling.Second.Location=ceiling of {0} feet mesured by a second sensor located at {1} -Remark.FCST=forecast -Remark.FUNNELCLOUD=funnel cloud -Remark.Hail=largest hailstones with a diameter of {0} inches -Remark.Hail.LesserThan=largest hailstones with a diameter less than {0} inches -Remark.HVY=heavy -Remark.LGT=light -Remark.MOD=moderate -Remark.Obscuration={0} layer at {1} feet composed of {2} -Remark.ON=on -Remark.NXT=next -Remark.PeakWind=peak wind of {1} knots from {0} degrees at {2}:{3} -Remark.Precipitation.Beg.End={0} {1} beginning at {2}:{3} ending at {4}:{5} -Remark.PRESFR=pressure falling rapidly -Remark.PRESRR=pressure rising rapidly -Remark.Second.Location.Visibility=visibility of {0} SM mesured by a second sensor located at {1} -Remark.Sea.Level.Pressure=sea level pressure of {0} HPa -Remark.Sector.Visibility=visibility of {1} SM in the {0} direction -Remark.SLPNO=sea level pressure not available -Remark.Snow.Increasing.Rapidly=snow depth increase of {0} inches in the past hour with a total depth on the ground of {1} inches -Remark.Snow.Pellets={0} snow pellets -Remark.Surface.Visibility=surface visibility of {0} statute miles -Remark.Thunderstorm.Location=thunderstorm {0} of the station -Remark.Thunderstorm.Location.Moving=thunderstorm {0} of the station moving towards {1} -Remark.Tornadic.Activity.Beginning={0} beginning at {1}:{2} {3} SM {4} of the station -Remark.Tornadic.Activity.BegEnd={0} beginning at {1}:{2} ending at {3}:{4} {5} SM {6} of the station -Remark.Tornadic.Activity.Ending={0} ending at {1}:{2} {3} SM {4} of the station -Remark.TORNADO=tornado -Remark.Tower.Visibility=control tower visibility of {0} statute miles -Remark.Variable.Prevailing.Visibility=variable prevailing visibility between {0} and {1} SM -Remark.Variable.Sky.Condition=cloud layer varying between {0} and {1} -Remark.Variable.Sky.Condition.Height=cloud layer at {0} feet varying between {1} and {2} -Remark.VIRGA=virga -Remark.Virga.Direction=virga {0} from the station -Remark.WATERSPOUT=waterspout -Remark.WindShift=wind shift at {0}:{1} -Remark.WindShift.FROPA=wind shift accompanied by frontal passage at {0}:{1} - - -MetarFacade.InvalidIcao=Icao code is invalid. - -Converter.D=decreasing -Converter.E=East -Converter.N=North -Converter.NE=North East -Converter.NSC=no significant change -Converter.NW=North West -Converter.S=South -Converter.SE=South East -Converter.SW=South West -Converter.U=up rising -Converter.VRB=Variable -Converter.W=West - -WeatherChangeType.FM=From -WeatherChangeType.BECMG=Becoming -WeatherChangeType.TEMPO=Temporary -WeatherChangeType.PROB=Probability - -TimeIndicator.AT=at -TimeIndicator.TL=until -ToString.airport=airport -ToString.altimeter=altimeter (hPa) -ToString.amendment=amendment -ToString.auto=auto -ToString.cavok=cavok -ToString.clouds=clouds -ToString.day.month=day of the month -ToString.day.hour=hour of the day -ToString.descriptive=descriptive -ToString.dew.point=dew point -ToString.end.day.month=end day of the month -ToString.end.hour.day=end hour of the day -ToString.height.feet=height (ft) -ToString.height.meter=height (m) -ToString.intensity=intensity -ToString.message=original message -ToString.name=name -ToString.nosig=nosig -ToString.phenomenons=phenomenons -ToString.probability=probability -ToString.quantity=quantity -ToString.remark=remarks -ToString.report.time=time of report -ToString.runway.info=runways information -ToString.start.day.month=starting day of the month -ToString.start.hour.day=starting hour of the day -ToString.start.minute=starting minute -ToString.temperature=temperature (°C) -ToString.temperature.max=maximum temperature (°C) -ToString.temperature.min=minimum temperature (°C) -ToString.trend=trend -ToString.trends=trends -ToString.type=type -ToString.visibility.main=main visibility -ToString.visibility.min=minimum visibility -ToString.visibility.min.direction=minimum visibility direction -ToString.visibility.max=maximum visibility -ToString.vertical.visibility=vertical visibility (ft) -ToString.weather.conditions=weather conditions -ToString.wind.direction=direction -ToString.wind.direction.degrees=direction (degrees) -ToString.wind.gusts=gusts -ToString.wind.min.variation=minimal wind variation -ToString.wind.max.variation=maximal wind variation -ToString.wind.speed=speed -ToString.wind.unit=unit +CloudQuantity.BKN=broken +CloudQuantity.FEW=few +CloudQuantity.NSC=no significant clouds. +CloudQuantity.OVC=overcast +CloudQuantity.SCT=scattered +CloudQuantity.SKC=sky clear + +CloudType.AC=Altocumulus +CloudType.AS=Altostratus +CloudType.CB=Cumulonimbus +CloudType.CC=CirroCumulus +CloudType.CI=Cirrus +CloudType.CS=Cirrostratus +CloudType.CU=Cumulus +CloudType.NS=Nimbostratus +CloudType.SC=Stratocumulus +CloudType.ST=Stratus +CloudType.TCU=Towering cumulus + +Descriptive.BC=patches +Descriptive.BL=blowing +Descriptive.DR=low drifting +Descriptive.FZ=freezing +Descriptive.MI=shallow +Descriptive.PR=partial +Descriptive.SH=showers of +Descriptive.TS=thunderstorm +Error.prefix=An error occured. Error code n° +ErrorCode.AirportNotFound=The airport was not found for this message. +ErrorCode.InvalidMessage=The entered message is invalid. + +Intensity.-=Light +Intensity.+=Heavy +Intensity.VC=In the vicinity + +Phenomenon.BR=mist +Phenomenon.DS=duststorm +Phenomenon.DU=widespread dust +Phenomenon.DZ=drizzle +Phenomenon.FC=funnel cloud +Phenomenon.FG=fog +Phenomenon.FU=smoke +Phenomenon.GR=hail +Phenomenon.GS=small hail and/or snow pellets +Phenomenon.HZ=haze +Phenomenon.IC=ice crystals +Phenomenon.PL=ice pellets +Phenomenon.PO=dust or sand whirls +Phenomenon.PY=spray +Phenomenon.RA=rain +Phenomenon.SA=sand +Phenomenon.SG=snow grains +Phenomenon.SN=snow +Phenomenon.SQ=squall +Phenomenon.SS=sandstorm +Phenomenon.UP=unknown precipitation +Phenomenon.VA=volcanic ash +Phenomenon.TS=thunderstorm + +Remark.AO1=automated stations without a precipitation discriminator +Remark.AO2=automated station with a precipitation discriminator +Remark.BASED=based +Remark.Ceiling.Height=ceiling varying between {0} and {1} feet +Remark.Ceiling.Second.Location=ceiling of {0} feet mesured by a second sensor located at {1} +Remark.FCST=forecast +Remark.FUNNELCLOUD=funnel cloud +Remark.Hail=largest hailstones with a diameter of {0} inches +Remark.Hail.LesserThan=largest hailstones with a diameter less than {0} inches +Remark.HVY=heavy +Remark.LGT=light +Remark.MOD=moderate +Remark.Obscuration={0} layer at {1} feet composed of {2} +Remark.ON=on +Remark.NXT=next +Remark.PeakWind=peak wind of {1} knots from {0} degrees at {2}:{3} +Remark.Precipitation.Beg.End={0} {1} beginning at {2}:{3} ending at {4}:{5} +Remark.PRESFR=pressure falling rapidly +Remark.PRESRR=pressure rising rapidly +Remark.Second.Location.Visibility=visibility of {0} SM mesured by a second sensor located at {1} +Remark.Sea.Level.Pressure=sea level pressure of {0} HPa +Remark.Sector.Visibility=visibility of {1} SM in the {0} direction +Remark.SLPNO=sea level pressure not available +Remark.Snow.Increasing.Rapidly=snow depth increase of {0} inches in the past hour with a total depth on the ground of {1} inches +Remark.Snow.Pellets={0} snow pellets +Remark.Surface.Visibility=surface visibility of {0} statute miles +Remark.Thunderstorm.Location=thunderstorm {0} of the station +Remark.Thunderstorm.Location.Moving=thunderstorm {0} of the station moving towards {1} +Remark.Tornadic.Activity.Beginning={0} beginning at {1}:{2} {3} SM {4} of the station +Remark.Tornadic.Activity.BegEnd={0} beginning at {1}:{2} ending at {3}:{4} {5} SM {6} of the station +Remark.Tornadic.Activity.Ending={0} ending at {1}:{2} {3} SM {4} of the station +Remark.TORNADO=tornado +Remark.Tower.Visibility=control tower visibility of {0} statute miles +Remark.Variable.Prevailing.Visibility=variable prevailing visibility between {0} and {1} SM +Remark.Variable.Sky.Condition=cloud layer varying between {0} and {1} +Remark.Variable.Sky.Condition.Height=cloud layer at {0} feet varying between {1} and {2} +Remark.VIRGA=virga +Remark.Virga.Direction=virga {0} from the station +Remark.WATERSPOUT=waterspout +Remark.WindShift=wind shift at {0}:{1} +Remark.WindShift.FROPA=wind shift accompanied by frontal passage at {0}:{1} + + +MetarFacade.InvalidIcao=Icao code is invalid. + +Converter.D=decreasing +Converter.E=East +Converter.N=North +Converter.NE=North East +Converter.NSC=no significant change +Converter.NW=North West +Converter.S=South +Converter.SE=South East +Converter.SW=South West +Converter.U=up rising +Converter.VRB=Variable +Converter.W=West + +WeatherChangeType.FM=From +WeatherChangeType.BECMG=Becoming +WeatherChangeType.TEMPO=Temporary +WeatherChangeType.PROB=Probability + +TimeIndicator.AT=at +TimeIndicator.TL=until +ToString.airport=airport +ToString.altimeter=altimeter (hPa) +ToString.amendment=amendment +ToString.auto=auto +ToString.cavok=cavok +ToString.clouds=clouds +ToString.day.month=day of the month +ToString.day.hour=hour of the day +ToString.descriptive=descriptive +ToString.dew.point=dew point +ToString.end.day.month=end day of the month +ToString.end.hour.day=end hour of the day +ToString.height.feet=height (ft) +ToString.height.meter=height (m) +ToString.intensity=intensity +ToString.message=original message +ToString.name=name +ToString.nosig=nosig +ToString.phenomenons=phenomenons +ToString.probability=probability +ToString.quantity=quantity +ToString.remark=remarks +ToString.report.time=time of report +ToString.runway.info=runways information +ToString.start.day.month=starting day of the month +ToString.start.hour.day=starting hour of the day +ToString.start.minute=starting minute +ToString.temperature=temperature (°C) +ToString.temperature.max=maximum temperature (°C) +ToString.temperature.min=minimum temperature (°C) +ToString.trend=trend +ToString.trends=trends +ToString.type=type +ToString.visibility.main=main visibility +ToString.visibility.min=minimum visibility +ToString.visibility.min.direction=minimum visibility direction +ToString.visibility.max=maximum visibility +ToString.vertical.visibility=vertical visibility (ft) +ToString.weather.conditions=weather conditions +ToString.wind.direction=direction +ToString.wind.direction.degrees=direction (degrees) +ToString.wind.gusts=gusts +ToString.wind.min.variation=minimal wind variation +ToString.wind.max.variation=maximal wind variation +ToString.wind.speed=speed +ToString.wind.unit=unit diff --git a/src/main/resources/internationalization/messages_ pl_PL.properties b/metarParser-commons/src/main/resources/internationalization/messages_ pl_PL.properties similarity index 96% rename from src/main/resources/internationalization/messages_ pl_PL.properties rename to metarParser-commons/src/main/resources/internationalization/messages_ pl_PL.properties index 6ec01905..fc3a2af9 100644 --- a/src/main/resources/internationalization/messages_ pl_PL.properties +++ b/metarParser-commons/src/main/resources/internationalization/messages_ pl_PL.properties @@ -1,84 +1,84 @@ -# There is no other translation in wikipedia and/or known resources to translate cloud quantity without numerals. I can translate it to common levels, but I think that this is not common way of naming those levels in aviation domain. -CloudQuantity.BKN = Od 5/8 do 7/8 -CloudQuantity.FEW = Od 1/8 do 2/8 -CloudQuantity.NSC = Nieznaczne zachmurzenie. -CloudQuantity.OVC = 8/8 -CloudQuantity.SCT = Od 3/8 do 4/8 -CloudQuantity.SKC = Czyste niebo -# Fuzzy -CloudType.AC = Średnie kłębiaste -# Fuzzy -CloudType.AS = Średnia warstwowa -# Fuzzy -CloudType.CB = Kłębiasta deszczowa -# Fuzzy -CloudType.CC = Piętra wysokiego rodzaj kłębiasto-pierzaste -# Fuzzy -CloudType.CI = Pierzasta -# Fuzzy -CloudType.CS = Warstwowo - pierzasta -# Fuzzy -CloudType.CU = Kłębiasta -# Fuzzy -CloudType.NS = Warstwowa deszczowa -# Fuzzy -CloudType.SC = Kłębiasto warstwowa -# Fuzzy -CloudType.ST = Warstwowa -# Fuzzy -CloudType.TCU = Wypiętrzona chmura kłębiasta -Descriptive.BC = płaty -Descriptive.BL = zawieja -Descriptive.DR = zamieć przyziemna -Descriptive.FZ = opad marznący -Descriptive.MI = niskie -Descriptive.PR = częściowe -Descriptive.SH = opad przelotny -Descriptive.TS = burza -Error.prefix = Wystąpił błąd. Kod błędu numer -ErrorCode.AirportNotFound = Nie znaleziono lotniska w tej depeszy. -ErrorCode.InvalidMessage = Wprowadzona depesza jest nieprawidłowa. -Intensity.- = Słaby -Intensity.+ = Silny -Intensity.VC = W pobliżu -Phenomenon.BR = zamglenie -Phenomenon.DS = burza piaskowa -Phenomenon.DU = pył -Phenomenon.DZ = mżawka -Phenomenon.FC = trąba powietrzna -Phenomenon.FG = mgła -Phenomenon.FU = dym -Phenomenon.GR = grad -Phenomenon.GS = krupa śnieżna -Phenomenon.HZ = zmętnienie -Phenomenon.IC = słupki lodowe -Phenomenon.PL = deszcz lodowy -Phenomenon.PO = wiry pyłowe -Phenomenon.PY = aerozol -Phenomenon.RA = deszcz -Phenomenon.SA = piasek -Phenomenon.SG = śnieg ziarnisty -Phenomenon.SN = śnieg -Phenomenon.SQ = nawałnica -Phenomenon.SS = burza piaskowa -Phenomenon.UP = marznący deszcz -Phenomenon.VA = popiół wulkaniczny -MetarFacade.InvalidIcao = Kod Icao jest nieprawidłowy -Converter.D = malejący -Converter.E = wschód -Converter.N = północ -Converter.NE = północny wschód -Converter.NSC = nieznaczna zmiana -Converter.NW = północny zachód -Converter.S = południe -Converter.SE = południowy zachód -Converter.SW = połódniowy wschód -Converter.U = rosnący -Converter.VRB = Zmienny -Converter.W = zachód -WeatherChangeType.FM = od -WeatherChangeType.BECMG = Nadchodząca -WeatherChangeType.TEMPO = Tymczasowa -WeatherChangeType.PROB = Prawdopodobieństwo -TimeIndicator.AT = o -TimeIndicator.TL = do +# There is no other translation in wikipedia and/or known resources to translate cloud quantity without numerals. I can translate it to common levels, but I think that this is not common way of naming those levels in aviation domain. +CloudQuantity.BKN = Od 5/8 do 7/8 +CloudQuantity.FEW = Od 1/8 do 2/8 +CloudQuantity.NSC = Nieznaczne zachmurzenie. +CloudQuantity.OVC = 8/8 +CloudQuantity.SCT = Od 3/8 do 4/8 +CloudQuantity.SKC = Czyste niebo +# Fuzzy +CloudType.AC = Średnie kłębiaste +# Fuzzy +CloudType.AS = Średnia warstwowa +# Fuzzy +CloudType.CB = Kłębiasta deszczowa +# Fuzzy +CloudType.CC = Piętra wysokiego rodzaj kłębiasto-pierzaste +# Fuzzy +CloudType.CI = Pierzasta +# Fuzzy +CloudType.CS = Warstwowo - pierzasta +# Fuzzy +CloudType.CU = Kłębiasta +# Fuzzy +CloudType.NS = Warstwowa deszczowa +# Fuzzy +CloudType.SC = Kłębiasto warstwowa +# Fuzzy +CloudType.ST = Warstwowa +# Fuzzy +CloudType.TCU = Wypiętrzona chmura kłębiasta +Descriptive.BC = płaty +Descriptive.BL = zawieja +Descriptive.DR = zamieć przyziemna +Descriptive.FZ = opad marznący +Descriptive.MI = niskie +Descriptive.PR = częściowe +Descriptive.SH = opad przelotny +Descriptive.TS = burza +Error.prefix = Wystąpił błąd. Kod błędu numer +ErrorCode.AirportNotFound = Nie znaleziono lotniska w tej depeszy. +ErrorCode.InvalidMessage = Wprowadzona depesza jest nieprawidłowa. +Intensity.- = Słaby +Intensity.+ = Silny +Intensity.VC = W pobliżu +Phenomenon.BR = zamglenie +Phenomenon.DS = burza piaskowa +Phenomenon.DU = pył +Phenomenon.DZ = mżawka +Phenomenon.FC = trąba powietrzna +Phenomenon.FG = mgła +Phenomenon.FU = dym +Phenomenon.GR = grad +Phenomenon.GS = krupa śnieżna +Phenomenon.HZ = zmętnienie +Phenomenon.IC = słupki lodowe +Phenomenon.PL = deszcz lodowy +Phenomenon.PO = wiry pyłowe +Phenomenon.PY = aerozol +Phenomenon.RA = deszcz +Phenomenon.SA = piasek +Phenomenon.SG = śnieg ziarnisty +Phenomenon.SN = śnieg +Phenomenon.SQ = nawałnica +Phenomenon.SS = burza piaskowa +Phenomenon.UP = marznący deszcz +Phenomenon.VA = popiół wulkaniczny +MetarFacade.InvalidIcao = Kod Icao jest nieprawidłowy +Converter.D = malejący +Converter.E = wschód +Converter.N = północ +Converter.NE = północny wschód +Converter.NSC = nieznaczna zmiana +Converter.NW = północny zachód +Converter.S = południe +Converter.SE = południowy zachód +Converter.SW = połódniowy wschód +Converter.U = rosnący +Converter.VRB = Zmienny +Converter.W = zachód +WeatherChangeType.FM = od +WeatherChangeType.BECMG = Nadchodząca +WeatherChangeType.TEMPO = Tymczasowa +WeatherChangeType.PROB = Prawdopodobieństwo +TimeIndicator.AT = o +TimeIndicator.TL = do diff --git a/src/main/resources/internationalization/messages_de.properties b/metarParser-commons/src/main/resources/internationalization/messages_de.properties similarity index 100% rename from src/main/resources/internationalization/messages_de.properties rename to metarParser-commons/src/main/resources/internationalization/messages_de.properties diff --git a/src/main/resources/internationalization/messages_fr.properties b/metarParser-commons/src/main/resources/internationalization/messages_fr.properties similarity index 97% rename from src/main/resources/internationalization/messages_fr.properties rename to metarParser-commons/src/main/resources/internationalization/messages_fr.properties index 895a6b1d..cecfad56 100644 --- a/src/main/resources/internationalization/messages_fr.properties +++ b/metarParser-commons/src/main/resources/internationalization/messages_fr.properties @@ -1,163 +1,163 @@ -CloudQuantity.BKN=nuages fragment\u00e9s -CloudQuantity.FEW=peu -CloudQuantity.NSC=pas de nuages significatifs. -CloudQuantity.OVC=ciel couvert -CloudQuantity.SCT=nuages \u00e9pars -CloudQuantity.SKC=pas de nuage - -CloudType.AC=Altocumulus -CloudType.AS=Altostratus -CloudType.CB=Cumunolinbus -CloudType.CC=Cirrocumulus -CloudType.CI=Cirrus -CloudType.CS=Cirrostratus -CloudType.CU=Cumulus -CloudType.NS=Nimbostratus -CloudType.SC=Stratocumulus -CloudType.ST=Stratus -CloudType.TCU=Towering cumulus - -Descriptive.BC=bancs -Descriptive.BL=chasse-poussi\u00e8re haute -Descriptive.DR=chasse-poussi\u00e8re basse -Descriptive.FZ=se congelant -Descriptive.MI=mince -Descriptive.PR=partiel -Descriptive.SH=averses de -Descriptive.TS=orage -Error.prefix=Une erreur est survenue. Code erreur n° -ErrorCode.AirportNotFound=L'a\u00e9roport n'a pas \u00e9t\u00e9 trouv\u00e9 pour ce message. -ErrorCode.InvalidMessage=Le message entr\u00e9 est invalide. - -Intensity.-=Faible -Intensity.+=Fort -Intensity.VC=Au voisinage de - -Phenomenon.BR=brume -Phenomenon.DS=temp\u00eate de poussi\u00e8re -Phenomenon.DU=poussi\u00e8res g\u00e9n\u00e9ralis\u00e9es -Phenomenon.DZ=bruine -Phenomenon.FC=nuage en entonnoir -Phenomenon.FG=brouillard -Phenomenon.FU=fum\u00e9e -Phenomenon.GR=gr\u00eale -Phenomenon.GS=gr\ue009sil -Phenomenon.HZ=brume s\u00e8che -Phenomenon.IC=cristaux de glace -Phenomenon.PL=granules de glace -Phenomenon.PO=tourbillon de poussi\u00e8res sable -Phenomenon.PY=spray -Phenomenon.RA=pluie -Phenomenon.SA=sable -Phenomenon.SG=neige en grains -Phenomenon.SN=neige -Phenomenon.SQ=grains -Phenomenon.SS=temp\u00eate de sable -Phenomenon.UP=pr\u00e9cipitation inconnue -Phenomenon.VA=cendres volcaniques -Phenomenon.TS=orage -Remark.AO1=stations automatis\u00e9es sans discriminateur de pr\u00e9cipitation -Remark.AO2=stations automatis\u00e9es avec discriminateur de pr\u00e9cipitation -Remark.BASED=bas\u00e9e -Remark.Ceiling.Height=variation du plafond entre {0} et {1} pieds -Remark.Ceiling.Second.Location=plafond de {0} pieds mesur\u00e9 par un second capteur situ\u00e9 \u00e0 {1} -Remark.FCST=pr\u00e9vision -Remark.FUNNELCLOUD=nuage en entonnoir -Remark.Hail=les plus gros gr\u00ealons ont un diam\u00e8tre de {0} pouces -Remark.Hail.LesserThan=les plus gros gr\u00ealons ont un diam\u00e8tre plus petit que {0} pouces -Remark.HVY=fort -Remark.LGT=l\u00e9ger -Remark.MOD=mod\u00e9r\u00e9 -Remark.Obscuration=couche de {0} \u00e0 {1} pieds compos\u00e9e de {2} -Remark.ON=sur -Remark.NXT=prochain -Remark.PeakWind=vent de pointe de {1} noeuds en provenance de {0} degr\u00e9s \u00e0 {2}:{3} -Remark.Precipitation.Beg.End={0} {1} commencant \u00e0 {2}:{3} finissant \u00e0 {4}:{5} -Remark.PRESFR=diminution rapide de la pression -Remark.PRESRR=augmentation rapide de la pression -Remark.Sea.Level.Pressure=pression au niveau de la mer de {0} HPa -Remark.SLPNO=pression au niveau de la mer non disponible -Remark.Second.Location.Visibility=visibilit\u00e9 de {0} SM mesur\u00e9 par un capteur situ\u00e9 \u00e0 {1} -Remark.Sector.Visibility=visibilit\u00e9 de {1} SM dans la direction {0} -Remark.Snow.Increasing.Rapidly=\u00e9paisseur de neige de {0} pouces sur la derni\u00e8re heure avec une \u00e9paisseur totale au sol de {1} pouces -Remark.Snow.Pellets={0} gr\u00e9sil -Remark.Surface.Visibility=visibility de surface de {0} miles -Remark.Thunderstorm.Location=orage se situant {0} de la station -Remark.Thunderstorm.Location.Moving=orage se situant {0} de la station se d\u00e9placant vers {1} -Remark.Tornadic.Activity.Beginning={0} commencant \u00e0 {1}:{2} {3} SM {4} de la station -Remark.Tornadic.Activity.BegEnd={0} commencant \u00e0 {1}:{2} finissant \u00e0 {3}:{4} {5} SM {6} de la station -Remark.Tornadic.Activity.Ending={0} finissant \u00e0 {1}:{2} {3} SM {4} de la station -Remark.TORNADO=tornado -Remark.Tower.Visibility=visibility de la tour de contr\u00f4le de {0} miles -Remark.Variable.Prevailing.Visibility=variation de la visibilit\u00e9 dominante entre {0} et {1} SM -Remark.Variable.Sky.Condition=couche de nuages variant entre {0} et {1} -Remark.Variable.Sky.Condition.Height=couche de nuages \u00e0 {0} pieds variant entre {1} et {2} -Remark.VIRGA=virga -Remark.Virga.Direction=virga au {0} de la station -Remark.WATERSPOUT=trombe -Remark.WindShift=changement de vent \u00e0 {0}:{1} -Remark.WindShift.FROPA=changement de vent accompagn\u00e9 d'un passage de front \u00e0 {0}:{1} - -MetarFacade.InvalidIcao=Code ICAO invalide. - -Converter.D=decroissant -Converter.E=Est -Converter.N=Nord -Converter.NE=Nord Est -Converter.NSC=Aucun changement significatif -Converter.NW=Nord Ouest -Converter.S=Est -Converter.SE=Sud Est -Converter.SW=Sud Ouest -Converter.U=accroissement -Converter.VRB=Variable -Converter.W=Ouest -WeatherChangeType.FM=De -WeatherChangeType.BECMG=Becoming -WeatherChangeType.TEMPO=Temporary -WeatherChangeType.PROB=Probabilit\u00e9 - -TimeIndicator.AT=\u00e0 - -TimeIndicator.TL=jusqu'\u00e0 -ToString.airport=a\u00e9roport -ToString.altimeter=altim\u00e8tre (hPa) -ToString.amendment=amendement -ToString.clouds=nuages -ToString.day.month=jour du mois -ToString.day.hour=heure du jour -ToString.descriptive=descriptif -ToString.dew.point=point de ros\u00e9e -ToString.height.feet=altitude (pieds) -ToString.height.meter=altitude (m) -ToString.intensity=intensit\u00e9 -ToString.message=message original -ToString.name=nom -ToString.phenomenons=ph\u00e9nom\u00e8nes -ToString.probability=probabilit\u00e9 -ToString.quantity=quantit\u00e9 -ToString.remark=remarques -ToString.report.time=heure du rapport -ToString.runway.info=informations sur la piste -ToString.temperature=tempr\u00e9rature (°C) -ToString.temperature.max=temp\u00e9rature maximale (°C) -ToString.temperature.min=temp\u00e9rature minimale (°C) -ToString.trend=tendance -ToString.trends=tendances -ToString.visibility.main=visibilit\u00e9 principale -ToString.visibility.min=visibilit\u00e9 minimale -ToString.visibility.min.direction=direction de la visibilit\u00e9 minimale -ToString.visibility.max=visibilit\u00e9 maximale -ToString.vertical.visibility=visibilit\u00e9 verticale (pieds) -ToString.weather.conditions=conditions m\u00e9t\u00e9orologique -ToString.wind.direction.degrees=direction (degr\u00e9s) -ToString.wind.gusts=rafales -ToString.wind.min.variation=variation minimale du vent -ToString.wind.max.variation=variation maximale du vent -ToString.wind.speed=vitesse -ToString.wind.unit=unit\u00e9 -ToString.start.day.month=jour de d/u00e9but du mois -ToString.start.hour.day=heure de d/u00e9but du jour -ToString.start.minute=minute de d/u00e9but -ToString.end.day.month=jour de fin du mois -ToString.end.hour.day=heure de fin du jour +CloudQuantity.BKN=nuages fragment\u00e9s +CloudQuantity.FEW=peu +CloudQuantity.NSC=pas de nuages significatifs. +CloudQuantity.OVC=ciel couvert +CloudQuantity.SCT=nuages \u00e9pars +CloudQuantity.SKC=pas de nuage + +CloudType.AC=Altocumulus +CloudType.AS=Altostratus +CloudType.CB=Cumunolinbus +CloudType.CC=Cirrocumulus +CloudType.CI=Cirrus +CloudType.CS=Cirrostratus +CloudType.CU=Cumulus +CloudType.NS=Nimbostratus +CloudType.SC=Stratocumulus +CloudType.ST=Stratus +CloudType.TCU=Towering cumulus + +Descriptive.BC=bancs +Descriptive.BL=chasse-poussi\u00e8re haute +Descriptive.DR=chasse-poussi\u00e8re basse +Descriptive.FZ=se congelant +Descriptive.MI=mince +Descriptive.PR=partiel +Descriptive.SH=averses de +Descriptive.TS=orage +Error.prefix=Une erreur est survenue. Code erreur n° +ErrorCode.AirportNotFound=L'a\u00e9roport n'a pas \u00e9t\u00e9 trouv\u00e9 pour ce message. +ErrorCode.InvalidMessage=Le message entr\u00e9 est invalide. + +Intensity.-=Faible +Intensity.+=Fort +Intensity.VC=Au voisinage de + +Phenomenon.BR=brume +Phenomenon.DS=temp\u00eate de poussi\u00e8re +Phenomenon.DU=poussi\u00e8res g\u00e9n\u00e9ralis\u00e9es +Phenomenon.DZ=bruine +Phenomenon.FC=nuage en entonnoir +Phenomenon.FG=brouillard +Phenomenon.FU=fum\u00e9e +Phenomenon.GR=gr\u00eale +Phenomenon.GS=gr\ue009sil +Phenomenon.HZ=brume s\u00e8che +Phenomenon.IC=cristaux de glace +Phenomenon.PL=granules de glace +Phenomenon.PO=tourbillon de poussi\u00e8res sable +Phenomenon.PY=spray +Phenomenon.RA=pluie +Phenomenon.SA=sable +Phenomenon.SG=neige en grains +Phenomenon.SN=neige +Phenomenon.SQ=grains +Phenomenon.SS=temp\u00eate de sable +Phenomenon.UP=pr\u00e9cipitation inconnue +Phenomenon.VA=cendres volcaniques +Phenomenon.TS=orage +Remark.AO1=stations automatis\u00e9es sans discriminateur de pr\u00e9cipitation +Remark.AO2=stations automatis\u00e9es avec discriminateur de pr\u00e9cipitation +Remark.BASED=bas\u00e9e +Remark.Ceiling.Height=variation du plafond entre {0} et {1} pieds +Remark.Ceiling.Second.Location=plafond de {0} pieds mesur\u00e9 par un second capteur situ\u00e9 \u00e0 {1} +Remark.FCST=pr\u00e9vision +Remark.FUNNELCLOUD=nuage en entonnoir +Remark.Hail=les plus gros gr\u00ealons ont un diam\u00e8tre de {0} pouces +Remark.Hail.LesserThan=les plus gros gr\u00ealons ont un diam\u00e8tre plus petit que {0} pouces +Remark.HVY=fort +Remark.LGT=l\u00e9ger +Remark.MOD=mod\u00e9r\u00e9 +Remark.Obscuration=couche de {0} \u00e0 {1} pieds compos\u00e9e de {2} +Remark.ON=sur +Remark.NXT=prochain +Remark.PeakWind=vent de pointe de {1} noeuds en provenance de {0} degr\u00e9s \u00e0 {2}:{3} +Remark.Precipitation.Beg.End={0} {1} commencant \u00e0 {2}:{3} finissant \u00e0 {4}:{5} +Remark.PRESFR=diminution rapide de la pression +Remark.PRESRR=augmentation rapide de la pression +Remark.Sea.Level.Pressure=pression au niveau de la mer de {0} HPa +Remark.SLPNO=pression au niveau de la mer non disponible +Remark.Second.Location.Visibility=visibilit\u00e9 de {0} SM mesur\u00e9 par un capteur situ\u00e9 \u00e0 {1} +Remark.Sector.Visibility=visibilit\u00e9 de {1} SM dans la direction {0} +Remark.Snow.Increasing.Rapidly=\u00e9paisseur de neige de {0} pouces sur la derni\u00e8re heure avec une \u00e9paisseur totale au sol de {1} pouces +Remark.Snow.Pellets={0} gr\u00e9sil +Remark.Surface.Visibility=visibility de surface de {0} miles +Remark.Thunderstorm.Location=orage se situant {0} de la station +Remark.Thunderstorm.Location.Moving=orage se situant {0} de la station se d\u00e9placant vers {1} +Remark.Tornadic.Activity.Beginning={0} commencant \u00e0 {1}:{2} {3} SM {4} de la station +Remark.Tornadic.Activity.BegEnd={0} commencant \u00e0 {1}:{2} finissant \u00e0 {3}:{4} {5} SM {6} de la station +Remark.Tornadic.Activity.Ending={0} finissant \u00e0 {1}:{2} {3} SM {4} de la station +Remark.TORNADO=tornado +Remark.Tower.Visibility=visibility de la tour de contr\u00f4le de {0} miles +Remark.Variable.Prevailing.Visibility=variation de la visibilit\u00e9 dominante entre {0} et {1} SM +Remark.Variable.Sky.Condition=couche de nuages variant entre {0} et {1} +Remark.Variable.Sky.Condition.Height=couche de nuages \u00e0 {0} pieds variant entre {1} et {2} +Remark.VIRGA=virga +Remark.Virga.Direction=virga au {0} de la station +Remark.WATERSPOUT=trombe +Remark.WindShift=changement de vent \u00e0 {0}:{1} +Remark.WindShift.FROPA=changement de vent accompagn\u00e9 d'un passage de front \u00e0 {0}:{1} + +MetarFacade.InvalidIcao=Code ICAO invalide. + +Converter.D=decroissant +Converter.E=Est +Converter.N=Nord +Converter.NE=Nord Est +Converter.NSC=Aucun changement significatif +Converter.NW=Nord Ouest +Converter.S=Est +Converter.SE=Sud Est +Converter.SW=Sud Ouest +Converter.U=accroissement +Converter.VRB=Variable +Converter.W=Ouest +WeatherChangeType.FM=De +WeatherChangeType.BECMG=Becoming +WeatherChangeType.TEMPO=Temporary +WeatherChangeType.PROB=Probabilit\u00e9 + +TimeIndicator.AT=\u00e0 + +TimeIndicator.TL=jusqu'\u00e0 +ToString.airport=a\u00e9roport +ToString.altimeter=altim\u00e8tre (hPa) +ToString.amendment=amendement +ToString.clouds=nuages +ToString.day.month=jour du mois +ToString.day.hour=heure du jour +ToString.descriptive=descriptif +ToString.dew.point=point de ros\u00e9e +ToString.height.feet=altitude (pieds) +ToString.height.meter=altitude (m) +ToString.intensity=intensit\u00e9 +ToString.message=message original +ToString.name=nom +ToString.phenomenons=ph\u00e9nom\u00e8nes +ToString.probability=probabilit\u00e9 +ToString.quantity=quantit\u00e9 +ToString.remark=remarques +ToString.report.time=heure du rapport +ToString.runway.info=informations sur la piste +ToString.temperature=tempr\u00e9rature (°C) +ToString.temperature.max=temp\u00e9rature maximale (°C) +ToString.temperature.min=temp\u00e9rature minimale (°C) +ToString.trend=tendance +ToString.trends=tendances +ToString.visibility.main=visibilit\u00e9 principale +ToString.visibility.min=visibilit\u00e9 minimale +ToString.visibility.min.direction=direction de la visibilit\u00e9 minimale +ToString.visibility.max=visibilit\u00e9 maximale +ToString.vertical.visibility=visibilit\u00e9 verticale (pieds) +ToString.weather.conditions=conditions m\u00e9t\u00e9orologique +ToString.wind.direction.degrees=direction (degr\u00e9s) +ToString.wind.gusts=rafales +ToString.wind.min.variation=variation minimale du vent +ToString.wind.max.variation=variation maximale du vent +ToString.wind.speed=vitesse +ToString.wind.unit=unit\u00e9 +ToString.start.day.month=jour de d/u00e9but du mois +ToString.start.hour.day=heure de d/u00e9but du jour +ToString.start.minute=minute de d/u00e9but +ToString.end.day.month=jour de fin du mois +ToString.end.hour.day=heure de fin du jour diff --git a/metarParser-commons/src/test/java/io/github/mivek/internationalization/ArchitectureTest.java b/metarParser-commons/src/test/java/io/github/mivek/internationalization/ArchitectureTest.java new file mode 100644 index 00000000..ad7a27ee --- /dev/null +++ b/metarParser-commons/src/test/java/io/github/mivek/internationalization/ArchitectureTest.java @@ -0,0 +1,23 @@ +package io.github.mivek.internationalization; + +import com.tngtech.archunit.core.importer.ImportOption; +import com.tngtech.archunit.junit.AnalyzeClasses; +import com.tngtech.archunit.junit.ArchTest; +import com.tngtech.archunit.junit.ArchUnitRunner; +import com.tngtech.archunit.lang.ArchRule; +import org.junit.runner.RunWith; + +import static com.tngtech.archunit.lang.syntax.ArchRuleDefinition.classes; + +/** + * @author mivek + */ +@RunWith(ArchUnitRunner.class) +@AnalyzeClasses(packages = "io.github.mivek.internationalization", importOptions = { ImportOption.DoNotIncludeTests.class }) +public class ArchitectureTest { + + @ArchTest + public static final ArchRule dependencyRule = classes().should().onlyHaveDependentClassesThat().resideInAnyPackage("java.util..", "java.text.."); + +} + diff --git a/src/test/java/io/github/mivek/internationalization/MessagesTest.java b/metarParser-commons/src/test/java/io/github/mivek/internationalization/MessagesTest.java similarity index 83% rename from src/test/java/io/github/mivek/internationalization/MessagesTest.java rename to metarParser-commons/src/test/java/io/github/mivek/internationalization/MessagesTest.java index 969c7d3c..5da89175 100644 --- a/src/test/java/io/github/mivek/internationalization/MessagesTest.java +++ b/metarParser-commons/src/test/java/io/github/mivek/internationalization/MessagesTest.java @@ -1,21 +1,22 @@ -package io.github.mivek.internationalization; - -import static org.junit.Assert.assertEquals; - -import java.util.Locale; - -import org.junit.Test; - -public class MessagesTest { - - @Test - public void testSetLocale() { - // Given a french locale - Messages.getInstance().setLocale(Locale.FRENCH); - assertEquals("peu", Messages.getInstance().getString("CloudQuantity.FEW")); - // WHEN Changing the locale to english - Messages.getInstance().setLocale(Locale.ENGLISH); - // THEN The locale is changed and so is the message. - assertEquals("few", Messages.getInstance().getString("CloudQuantity.FEW")); - } -} +package io.github.mivek.internationalization; + +import static org.junit.Assert.assertEquals; + +import java.util.Locale; + +import org.junit.Test; + +public class MessagesTest { + + @Test + public void testSetLocale() { + // Given a french locale + Messages.getInstance().setLocale(Locale.FRENCH); + assertEquals("peu", Messages.getInstance().getString("CloudQuantity.FEW")); + // WHEN Changing the locale to english + Messages.getInstance().setLocale(Locale.ENGLISH); + // THEN The locale is changed and so is the message. + assertEquals("few", Messages.getInstance().getString("CloudQuantity.FEW")); + assertEquals("ceiling varying between 5 and 15 feet", Messages.getInstance().getString("Remark.Ceiling.Height", 5, 15)); + } +} diff --git a/metarParser-commons/src/test/java/io/github/mivek/utils/ArchitectureTest.java b/metarParser-commons/src/test/java/io/github/mivek/utils/ArchitectureTest.java new file mode 100644 index 00000000..30f5e03d --- /dev/null +++ b/metarParser-commons/src/test/java/io/github/mivek/utils/ArchitectureTest.java @@ -0,0 +1,22 @@ +package io.github.mivek.utils; + +import com.tngtech.archunit.core.importer.ImportOption; +import com.tngtech.archunit.junit.AnalyzeClasses; +import com.tngtech.archunit.junit.ArchTest; +import com.tngtech.archunit.junit.ArchUnitRunner; +import com.tngtech.archunit.lang.ArchRule; +import org.junit.runner.RunWith; + +import static com.tngtech.archunit.lang.syntax.ArchRuleDefinition.classes; + +/** + * @author mivek + */ +@RunWith(ArchUnitRunner.class) +@AnalyzeClasses(packages = "io.github.mivek.utils", importOptions = { ImportOption.DoNotIncludeTests.class }) +public class ArchitectureTest { + + @ArchTest + public static final ArchRule dependencyRule = classes().should().onlyHaveDependentClassesThat().resideInAnyPackage("io.github.mivek.internationalization", "java.time", "java.util.."); +} + diff --git a/src/test/java/io/github/mivek/utils/ConverterTest.java b/metarParser-commons/src/test/java/io/github/mivek/utils/ConverterTest.java similarity index 96% rename from src/test/java/io/github/mivek/utils/ConverterTest.java rename to metarParser-commons/src/test/java/io/github/mivek/utils/ConverterTest.java index 3a594c57..d4731f1e 100644 --- a/src/test/java/io/github/mivek/utils/ConverterTest.java +++ b/metarParser-commons/src/test/java/io/github/mivek/utils/ConverterTest.java @@ -1,56 +1,56 @@ -package io.github.mivek.utils; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; - -import java.time.LocalTime; - -import org.junit.Test; - -import io.github.mivek.internationalization.Messages; - -public class ConverterTest { - @Test - public void testBetween() { - - assertTrue(Converter.isBetween(5, 2, 8)); - assertTrue(Converter.isBetween(5, 5, 8)); - assertFalse(Converter.isBetween(5, 6, 10)); - assertFalse(Converter.isBetween(5, 0, 2)); - } - - @Test - public void testConvertVisibility() { - assertEquals(">10km", Converter.convertVisibility("9999")); - assertEquals("5000m", Converter.convertVisibility("5000")); - } - - @Test - public void testConvertTrend() { - assertEquals(Messages.getInstance().getString("Converter.U"), Converter.convertTrend("U")); - assertEquals(Messages.getInstance().getString("Converter.D"), Converter.convertTrend("D")); - assertEquals(Messages.getInstance().getString("Converter.NSC"), Converter.convertTrend("N")); - assertEquals("", Converter.convertTrend("Random string")); - } - - @Test - public void testInchesMercuryToHPascal() { - assertEquals(1013.25, Converter.inchesMercuryToHPascal(29.92), 0.1); - } - - @Test - public void testConvertTemperature() { - assertEquals(-10, Converter.convertTemperature("M10")); - assertEquals(10, Converter.convertTemperature("10")); - } - - @Test - public void testStringToTime() { - String input = "0830"; - LocalTime time = Converter.stringToTime(input); - - assertEquals(8, time.getHour()); - assertEquals(30, time.getMinute()); - } -} +package io.github.mivek.utils; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + +import java.time.LocalTime; + +import org.junit.Test; + +import io.github.mivek.internationalization.Messages; + +public class ConverterTest { + @Test + public void testBetween() { + + assertTrue(Converter.isBetween(5, 2, 8)); + assertTrue(Converter.isBetween(5, 5, 8)); + assertFalse(Converter.isBetween(5, 6, 10)); + assertFalse(Converter.isBetween(5, 0, 2)); + } + + @Test + public void testConvertVisibility() { + assertEquals(">10km", Converter.convertVisibility("9999")); + assertEquals("5000m", Converter.convertVisibility("5000")); + } + + @Test + public void testConvertTrend() { + assertEquals(Messages.getInstance().getString("Converter.U"), Converter.convertTrend("U")); + assertEquals(Messages.getInstance().getString("Converter.D"), Converter.convertTrend("D")); + assertEquals(Messages.getInstance().getString("Converter.NSC"), Converter.convertTrend("N")); + assertEquals("", Converter.convertTrend("Random string")); + } + + @Test + public void testInchesMercuryToHPascal() { + assertEquals(1013.25, Converter.inchesMercuryToHPascal(29.92), 0.1); + } + + @Test + public void testConvertTemperature() { + assertEquals(-10, Converter.convertTemperature("M10")); + assertEquals(10, Converter.convertTemperature("10")); + } + + @Test + public void testStringToTime() { + String input = "0830"; + LocalTime time = Converter.stringToTime(input); + + assertEquals(8, time.getHour()); + assertEquals(30, time.getMinute()); + } +} diff --git a/src/test/java/io/github/mivek/utils/DegreesToDirectionTest.java b/metarParser-commons/src/test/java/io/github/mivek/utils/DegreesToDirectionTest.java similarity index 92% rename from src/test/java/io/github/mivek/utils/DegreesToDirectionTest.java rename to metarParser-commons/src/test/java/io/github/mivek/utils/DegreesToDirectionTest.java index 85067693..e76921c0 100644 --- a/src/test/java/io/github/mivek/utils/DegreesToDirectionTest.java +++ b/metarParser-commons/src/test/java/io/github/mivek/utils/DegreesToDirectionTest.java @@ -1,44 +1,45 @@ -package io.github.mivek.utils; - -import static org.junit.Assert.assertEquals; - -import java.util.Arrays; -import java.util.Collection; - -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.Parameterized; -import org.junit.runners.Parameterized.Parameters; - -import io.github.mivek.internationalization.Messages; - -@RunWith(Parameterized.class) -public class DegreesToDirectionTest { - private String direction; - private String degrees; - - public DegreesToDirectionTest(final String pDirection, final String pDegrees) { - direction = pDirection; - degrees = pDegrees; - } - - @Parameters - public static Collection data() { - return Arrays.asList(new Object[][] { - { "Converter.E", "80" }, - { "Converter.NE", "30" }, - { "Converter.S", "200" }, - { "Converter.W", "280" }, - { "Converter.NW", "300"}, - { "Converter.SE", "130" }, - { "Converter.SW", "230" }, - { "Converter.N", "2" }, - { "Converter.N", "345" }, - {"Converter.VRB","anyString"} - }); - } - @Test - public void testDegreesToDirection() { - assertEquals(Messages.getInstance().getString(direction), Converter.degreesToDirection(degrees)); - } -} +package io.github.mivek.utils; + +import static org.junit.Assert.assertEquals; + +import java.util.Arrays; +import java.util.Collection; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.Parameterized; +import org.junit.runners.Parameterized.Parameters; + +import io.github.mivek.internationalization.Messages; + +@RunWith(Parameterized.class) +public class DegreesToDirectionTest { + private final String direction; + private final String degrees; + + public DegreesToDirectionTest(final String pDirection, final String pDegrees) { + direction = pDirection; + degrees = pDegrees; + } + + @Parameters + public static Collection data() { + return Arrays.asList(new Object[][] { + { "Converter.E", "80" }, + { "Converter.NE", "30" }, + { "Converter.S", "200" }, + { "Converter.W", "280" }, + { "Converter.NW", "300"}, + { "Converter.SE", "130" }, + { "Converter.SW", "230" }, + { "Converter.N", "2" }, + { "Converter.N", "345" }, + {"Converter.VRB","anyString"} + }); + } + + @Test + public void testDegreesToDirection() { + assertEquals(Messages.getInstance().getString(direction), Converter.degreesToDirection(degrees)); + } +} diff --git a/src/test/java/io/github/mivek/utils/RegexTest.java b/metarParser-commons/src/test/java/io/github/mivek/utils/RegexTest.java similarity index 65% rename from src/test/java/io/github/mivek/utils/RegexTest.java rename to metarParser-commons/src/test/java/io/github/mivek/utils/RegexTest.java index fed17406..64051951 100644 --- a/src/test/java/io/github/mivek/utils/RegexTest.java +++ b/metarParser-commons/src/test/java/io/github/mivek/utils/RegexTest.java @@ -1,49 +1,59 @@ -package io.github.mivek.utils; - -import static org.hamcrest.Matchers.arrayContainingInAnyOrder; -import static org.hamcrest.Matchers.arrayWithSize; -import static org.hamcrest.Matchers.emptyArray; -import static org.hamcrest.Matchers.is; -import static org.hamcrest.Matchers.not; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertThat; -import static org.junit.Assert.assertTrue; - -import java.util.regex.Pattern; - -import org.junit.Test; - -public class RegexTest { - - @Test - public void testPregMatchSuccess() { - Pattern regex = Pattern.compile("(a((b)(c)))"); - String input = "abc"; - - String[] res = Regex.pregMatch(regex, input); - - assertThat(res, is(not(emptyArray()))); - assertThat(res, arrayWithSize(5)); - assertThat(res, arrayContainingInAnyOrder("abc", "abc", "bc", "b", "c")); - } - - @Test - public void testPregMatchFail() { - Pattern regex = Pattern.compile("(a((b)(c)))"); - String input = ""; - - String[] res = Regex.pregMatch(regex, input); - - assertThat(res, is(emptyArray())); - } - - @Test - public void testFind() { - Pattern regex = Pattern.compile("^(R\\d{2}\\w?\\/)"); - String input1 = "R26/0550V700U"; - String input2 = "Random string"; - - assertTrue(Regex.find(regex, input1)); - assertFalse(Regex.find(regex, input2)); - } -} +package io.github.mivek.utils; + +import org.junit.Test; + +import java.util.regex.Pattern; + +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.*; +import static org.junit.Assert.*; + +public class RegexTest { + + @Test + public void testPregMatchSuccess() { + Pattern regex = Pattern.compile("(a((b)(c)))"); + String input = "abc"; + + String[] res = Regex.pregMatch(regex, input); + + assertThat(res, is(not(emptyArray()))); + assertThat(res, arrayWithSize(5)); + assertThat(res, arrayContainingInAnyOrder("abc", "abc", "bc", "b", "c")); + } + + @Test + public void testPregMatchFail() { + Pattern regex = Pattern.compile("(a((b)(c)))"); + String input = ""; + + String[] res = Regex.pregMatch(regex, input); + + assertThat(res, is(emptyArray())); + } + + @Test + public void testFind() { + Pattern regex = Pattern.compile("^(R\\d{2}\\w?\\/)"); + String input1 = "R26/0550V700U"; + String input2 = "Random string"; + + assertTrue(Regex.find(regex, input1)); + assertFalse(Regex.find(regex, input2)); + } + + @Test + public void testMatch() { + Pattern regex = Pattern.compile("(VRB|\\d{3})(\\d{2})G?(\\d{2})?(KT|MPS|KM\\/H)?"); + + assertTrue(Regex.match(regex, "12012MPS")); + } + + @Test + public void testFindString() { + Pattern regex = Pattern.compile("(TS)"); + + assertEquals("TS", Regex.findString(regex, "TSRA")); + assertNull(Regex.findString(regex, "SHRA")); + } +} diff --git a/metarParser-entities/pom.xml b/metarParser-entities/pom.xml new file mode 100644 index 00000000..66949fce --- /dev/null +++ b/metarParser-entities/pom.xml @@ -0,0 +1,37 @@ + + + + metarParser + io.github.mivek + 1.10.5 + + 4.0.0 + + metarParser-entities + Module containing the model of the application. + + + 0.68 + 0.34 + 0.58 + + + + io.github.mivek + metarParser-commons + ${project.version} + + + org.apache.commons + commons-lang3 + + + pl.pojo + pojo-tester + test + + + + diff --git a/src/main/java/io/github/mivek/enums/CloudQuantity.java b/metarParser-entities/src/main/java/io/github/mivek/enums/CloudQuantity.java similarity index 74% rename from src/main/java/io/github/mivek/enums/CloudQuantity.java rename to metarParser-entities/src/main/java/io/github/mivek/enums/CloudQuantity.java index 43203d1d..dbe3d75a 100644 --- a/src/main/java/io/github/mivek/enums/CloudQuantity.java +++ b/metarParser-entities/src/main/java/io/github/mivek/enums/CloudQuantity.java @@ -1,53 +1,56 @@ -package io.github.mivek.enums; - -import io.github.mivek.internationalization.Messages; - -/** - * Enumeration for cloud quantity. - * The first attribute is the code used in the metar. - * The second attribute is the meaning of the code. - * @author mivek - */ -public enum CloudQuantity { - /** Sky clear. */ - SKC("SKC", Messages.getInstance().getString("CloudQuantity.SKC")), //$NON-NLS-1$ - /** Few clouds. */ - FEW("FEW", Messages.getInstance().getString("CloudQuantity.FEW")), //$NON-NLS-1$ - /** Broken ceiling. */ - BKN("BKN", Messages.getInstance().getString("CloudQuantity.BKN")), //$NON-NLS-1$ - /** Scattered. */ - SCT("SCT", Messages.getInstance().getString("CloudQuantity.SCT")), //$NON-NLS-1$ - /** Overcast. */ - OVC("OVC", Messages.getInstance().getString("CloudQuantity.OVC")), //$NON-NLS-1$ - /** No significant cloud. */ - NSC("NSC", Messages.getInstance().getString("CloudQuantity.NSC")); //$NON-NLS-1$ - - /** Shortcut of the cloud quanity. */ - private String fShortcut = ""; //$NON-NLS-1$ - /** The name of the quantity. */ - private String fName = ""; //$NON-NLS-1$ - - /** - * Constructor. - * @param pShortcut a string representing the shortcut. - * @param pName The meaning of the shortcut. - */ - CloudQuantity(final String pShortcut, final String pName) { - fShortcut = pShortcut; - fName = pName; - } - - @Override - public String toString() { - return fName; - } - - /** - * Returns the shortcut. - * @return a string. - */ - public String getShortcut() { - return fShortcut; - } - -} +package io.github.mivek.enums; + +import io.github.mivek.internationalization.Messages; + +/** + * Enumeration for cloud quantity. + * The first attribute is the code used in the metar. + * The second attribute is the meaning of the code. + * + * @author mivek + */ +public enum CloudQuantity { + /** Sky clear. */ + SKC("SKC", Messages.getInstance().getString("CloudQuantity.SKC")), //$NON-NLS-1$ + /** Few clouds. */ + FEW("FEW", Messages.getInstance().getString("CloudQuantity.FEW")), //$NON-NLS-1$ + /** Broken ceiling. */ + BKN("BKN", Messages.getInstance().getString("CloudQuantity.BKN")), //$NON-NLS-1$ + /** Scattered. */ + SCT("SCT", Messages.getInstance().getString("CloudQuantity.SCT")), //$NON-NLS-1$ + /** Overcast. */ + OVC("OVC", Messages.getInstance().getString("CloudQuantity.OVC")), //$NON-NLS-1$ + /** No significant cloud. */ + NSC("NSC", Messages.getInstance().getString("CloudQuantity.NSC")); //$NON-NLS-1$ + + /** Shortcut of the cloud quanity. */ + private final String shortcut; //$NON-NLS-1$ + /** The name of the quantity. */ + private final String name; //$NON-NLS-1$ + + /** + * Constructor. + * + * @param shortcut a string representing the shortcut. + * @param name The meaning of the shortcut. + */ + CloudQuantity(final String shortcut, final String name) { + this.shortcut = shortcut; + this.name = name; + } + + @Override + public String toString() { + return name; + } + + /** + * Returns the shortcut. + * + * @return a string. + */ + public String getShortcut() { + return shortcut; + } + +} diff --git a/src/main/java/io/github/mivek/enums/CloudType.java b/metarParser-entities/src/main/java/io/github/mivek/enums/CloudType.java similarity index 79% rename from src/main/java/io/github/mivek/enums/CloudType.java rename to metarParser-entities/src/main/java/io/github/mivek/enums/CloudType.java index 48ce29ca..e1808f91 100644 --- a/src/main/java/io/github/mivek/enums/CloudType.java +++ b/metarParser-entities/src/main/java/io/github/mivek/enums/CloudType.java @@ -1,63 +1,64 @@ -package io.github.mivek.enums; - -import io.github.mivek.internationalization.Messages; - -/** - * Enumeration for cloud type. The first attribute is the code used in the - * metar. The second attribute is the meaning of the code. - * @author mivek - */ -public enum CloudType { - /** cumulonimbus. */ - CB("CB", Messages.getInstance().getString("CloudType.CB")), //$NON-NLS-1$ - /** towering cumulus, cumulus congestus. */ - TCU("TCU", Messages.getInstance().getString("CloudType.TCU")), //$NON-NLS-1$ - /** Cirrus. */ - CI("CI", Messages.getInstance().getString("CloudType.CI")), - /** Cirrocumulus. */ - CC("CC", Messages.getInstance().getString("CloudType.CC")), - /** Cirrostratus. */ - CS("CS", Messages.getInstance().getString("CloudType.CS")), - /** Altocumulus. */ - AC("AC", Messages.getInstance().getString("CloudType.AC")), - /** Stratus. */ - ST("ST", Messages.getInstance().getString("CloudType.ST")), - /** Cumulus. */ - CU("CU", Messages.getInstance().getString("CloudType.CU")), - /** Astrostratus. */ - AS("AS", Messages.getInstance().getString("CloudType.AS")), - /** Nimbostratus. */ - NS("NS", Messages.getInstance().getString("CloudType.NS")), - /** Stratocumulus. */ - SC("SC", Messages.getInstance().getString("CloudType.SC")); - - /** The shortcut of the cloud type. */ - private String fShortcut = ""; //$NON-NLS-1$ - /** The name of the cloud type. */ - private String fName = ""; //$NON-NLS-1$ - - /** - * Constructor. - * @param pShortcut - * string for shortcut. - * @param pName - * string for name. - */ - CloudType(final String pShortcut, final String pName) { - fShortcut = pShortcut; - fName = pName; - } - - @Override - public String toString() { - return fName; - } - - /** - * returns the shortcut of the type. - * @return string shortcut. - */ - public String getShortcut() { - return fShortcut; - } -} +package io.github.mivek.enums; + +import io.github.mivek.internationalization.Messages; + +/** + * Enumeration for cloud type. The first attribute is the code used in the + * metar. The second attribute is the meaning of the code. + * + * @author mivek + */ +public enum CloudType { + /** cumulonimbus. */ + CB("CB", Messages.getInstance().getString("CloudType.CB")), //$NON-NLS-1$ + /** towering cumulus, cumulus congestus. */ + TCU("TCU", Messages.getInstance().getString("CloudType.TCU")), //$NON-NLS-1$ + /** Cirrus. */ + CI("CI", Messages.getInstance().getString("CloudType.CI")), + /** Cirrocumulus. */ + CC("CC", Messages.getInstance().getString("CloudType.CC")), + /** Cirrostratus. */ + CS("CS", Messages.getInstance().getString("CloudType.CS")), + /** Altocumulus. */ + AC("AC", Messages.getInstance().getString("CloudType.AC")), + /** Stratus. */ + ST("ST", Messages.getInstance().getString("CloudType.ST")), + /** Cumulus. */ + CU("CU", Messages.getInstance().getString("CloudType.CU")), + /** Astrostratus. */ + AS("AS", Messages.getInstance().getString("CloudType.AS")), + /** Nimbostratus. */ + NS("NS", Messages.getInstance().getString("CloudType.NS")), + /** Stratocumulus. */ + SC("SC", Messages.getInstance().getString("CloudType.SC")); + + /** The shortcut of the cloud type. */ + private final String shortcut; //$NON-NLS-1$ + /** The name of the cloud type. */ + private final String name; //$NON-NLS-1$ + + /** + * Constructor. + * + * @param shortcut string for shortcut. + * @param name string for name. + */ + CloudType(final String shortcut, final String name) { + this.shortcut = shortcut; + this.name = name; + } + + @Override + public String toString() { + return name; + } + + /** + * returns the shortcut of the type. + * + * @return string shortcut. + */ + public String getShortcut() { + return shortcut; + } +} diff --git a/src/main/java/io/github/mivek/enums/Descriptive.java b/metarParser-entities/src/main/java/io/github/mivek/enums/Descriptive.java similarity index 76% rename from src/main/java/io/github/mivek/enums/Descriptive.java rename to metarParser-entities/src/main/java/io/github/mivek/enums/Descriptive.java index 87684fdf..a624980b 100644 --- a/src/main/java/io/github/mivek/enums/Descriptive.java +++ b/metarParser-entities/src/main/java/io/github/mivek/enums/Descriptive.java @@ -1,57 +1,58 @@ -package io.github.mivek.enums; - -import io.github.mivek.internationalization.Messages; - -/** - * Enumeration for descriptive. The first attribute is the code used in the - * metar. The second attribute is the meaning of the code. - * @author mivek - */ -public enum Descriptive { - /** Showers. */ - SHOWERS("SH", Messages.getInstance().getString("Descriptive.SH")), //$NON-NLS-1$ - /** Shallow. */ - SHALLOW("MI", Messages.getInstance().getString("Descriptive.MI")), //$NON-NLS-1$ - /** Patches. */ - PATCHES("BC", Messages.getInstance().getString("Descriptive.BC")), //$NON-NLS-1$ - /** Partial. */ - PARTIAL("PR", Messages.getInstance().getString("Descriptive.PR")), //$NON-NLS-1$ - /** Low drifting. */ - DRIFTING("DR", Messages.getInstance().getString("Descriptive.DR")), //$NON-NLS-1$ - /** Thunderstorm. */ - THUNDERSTORM("TS", Messages.getInstance().getString("Descriptive.TS")), //$NON-NLS-1$ - /** blowing. */ - BLOWING("BL", Messages.getInstance().getString("Descriptive.BC")), //$NON-NLS-1$ - /** Freezing. */ - FREEZING("FZ", Messages.getInstance().getString("Descriptive.FZ")); //$NON-NLS-1$ - - /** Shortcut of the descriptive. */ - private String fShortcut = ""; //$NON-NLS-1$ - /** Meaning of the descriptive. */ - private String fName = ""; //$NON-NLS-1$ - - /** - * Connstructor. - * @param pShortcut - * A string for the shorcut. - * @param pName - * a string for the meaning. - */ - Descriptive(final String pShortcut, final String pName) { - fShortcut = pShortcut; - fName = pName; - } - - @Override - public String toString() { - return fName; - } - - /** - * return shortcut. - * @return string. - */ - public String getShortcut() { - return fShortcut; - } -} +package io.github.mivek.enums; + +import io.github.mivek.internationalization.Messages; + +/** + * Enumeration for descriptive. The first attribute is the code used in the + * metar. The second attribute is the meaning of the code. + * + * @author mivek + */ +public enum Descriptive { + /** Showers. */ + SHOWERS("SH", Messages.getInstance().getString("Descriptive.SH")), //$NON-NLS-1$ + /** Shallow. */ + SHALLOW("MI", Messages.getInstance().getString("Descriptive.MI")), //$NON-NLS-1$ + /** Patches. */ + PATCHES("BC", Messages.getInstance().getString("Descriptive.BC")), //$NON-NLS-1$ + /** Partial. */ + PARTIAL("PR", Messages.getInstance().getString("Descriptive.PR")), //$NON-NLS-1$ + /** Low drifting. */ + DRIFTING("DR", Messages.getInstance().getString("Descriptive.DR")), //$NON-NLS-1$ + /** Thunderstorm. */ + THUNDERSTORM("TS", Messages.getInstance().getString("Descriptive.TS")), //$NON-NLS-1$ + /** blowing. */ + BLOWING("BL", Messages.getInstance().getString("Descriptive.BC")), //$NON-NLS-1$ + /** Freezing. */ + FREEZING("FZ", Messages.getInstance().getString("Descriptive.FZ")); //$NON-NLS-1$ + + /** Shortcut of the descriptive. */ + private final String shortcut; //$NON-NLS-1$ + /** Meaning of the descriptive. */ + private final String name; //$NON-NLS-1$ + + /** + * Connstructor. + * + * @param shortcut A string for the shorcut. + * @param name a string for the meaning. + */ + Descriptive(final String shortcut, final String name) { + this.shortcut = shortcut; + this.name = name; + } + + @Override + public String toString() { + return name; + } + + /** + * return shortcut. + * + * @return string. + */ + public String getShortcut() { + return shortcut; + } +} diff --git a/src/main/java/io/github/mivek/enums/Intensity.java b/metarParser-entities/src/main/java/io/github/mivek/enums/Intensity.java similarity index 61% rename from src/main/java/io/github/mivek/enums/Intensity.java rename to metarParser-entities/src/main/java/io/github/mivek/enums/Intensity.java index d107a046..60920ad8 100644 --- a/src/main/java/io/github/mivek/enums/Intensity.java +++ b/metarParser-entities/src/main/java/io/github/mivek/enums/Intensity.java @@ -1,65 +1,65 @@ -package io.github.mivek.enums; - -import io.github.mivek.internationalization.Messages; - -/** - * Enumeration for indicator. - * The first attribute is the code used in the metar. - * The second attribute is the meaning of the code. - * @author mivek - */ -public enum Intensity { - /** Light intensity. */ - LIGHT("-", Messages.getInstance().getString("Intensity.-")), //$NON-NLS-1$ - /** Heavy intensity. */ - HEAVY("+", Messages.getInstance().getString("Intensity.+")), //$NON-NLS-1$ - /** In vicinity. */ - IN_VICINITY("VC", Messages.getInstance().getString("Intensity.VC")); //$NON-NLS-1$ - - /** The shortcut of the intensity. */ - private String fShortcut = ""; //$NON-NLS-1$ - /** The meaning of the intensity. */ - private String fName = ""; //$NON-NLS-1$ - - /** - * Constructor. - * @param pShortcut - * A String for the shortcut. - * @param pName - * A string for the meaning. - */ - Intensity(final String pShortcut, final String pName) { - fShortcut = pShortcut; - fName = pName; - } - - @Override - public String toString() { - return fName; - } - - /** - * Returns shortcut. - * @return string. - */ - public String getShortcut() { - return fShortcut; - } - - /** - * Returns the enum with the same shortcut than the value. - * @param pValue - * String of the intensity searched. - * @return a intensity with the same shortcut. - * @throws IllegalArgumentException - * error if not found. - */ - public static Intensity getEnum(final String pValue) throws IllegalArgumentException { - for (Intensity v : values()) { - if (v.getShortcut().equalsIgnoreCase(pValue)) { - return v; - } - } - throw new IllegalArgumentException(); - } -} +package io.github.mivek.enums; + +import io.github.mivek.internationalization.Messages; + +/** + * Enumeration for indicator. + * The first attribute is the code used in the metar. + * The second attribute is the meaning of the code. + * + * @author mivek + */ +public enum Intensity { + /** Light intensity. */ + LIGHT("-", Messages.getInstance().getString("Intensity.-")), //$NON-NLS-1$ + /** Heavy intensity. */ + HEAVY("+", Messages.getInstance().getString("Intensity.+")), //$NON-NLS-1$ + /** In vicinity. */ + IN_VICINITY("VC", Messages.getInstance().getString("Intensity.VC")); //$NON-NLS-1$ + + /** The shortcut of the intensity. */ + private final String shortcut; //$NON-NLS-1$ + /** The meaning of the intensity. */ + private final String name; //$NON-NLS-1$ + + /** + * Constructor. + * + * @param shortcut A String for the shortcut. + * @param name A string for the meaning. + */ + Intensity(final String shortcut, final String name) { + this.shortcut = shortcut; + this.name = name; + } + + @Override + public String toString() { + return name; + } + + /** + * Returns shortcut. + * + * @return string. + */ + public String getShortcut() { + return shortcut; + } + + /** + * Returns the enum with the same shortcut than the value. + * + * @param value String of the intensity searched. + * @return a intensity with the same shortcut. + * @throws IllegalArgumentException error if not found. + */ + public static Intensity getEnum(final String value) { + for (Intensity v : values()) { + if (v.getShortcut().equalsIgnoreCase(value)) { + return v; + } + } + throw new IllegalArgumentException(); + } +} diff --git a/src/main/java/io/github/mivek/enums/Phenomenon.java b/metarParser-entities/src/main/java/io/github/mivek/enums/Phenomenon.java similarity index 87% rename from src/main/java/io/github/mivek/enums/Phenomenon.java rename to metarParser-entities/src/main/java/io/github/mivek/enums/Phenomenon.java index 3713393a..b6644310 100644 --- a/src/main/java/io/github/mivek/enums/Phenomenon.java +++ b/metarParser-entities/src/main/java/io/github/mivek/enums/Phenomenon.java @@ -1,86 +1,87 @@ -package io.github.mivek.enums; - -import io.github.mivek.internationalization.Messages; - -/** - * Enumeration for phenomenon. - * The first attribute is the code used in the metar. - * The second attribute is the meaning of the code. - * @author mivek - */ -public enum Phenomenon { - /** Rain. */ - RAIN("RA", Messages.getInstance().getString("Phenomenon.RA")), //$NON-NLS-1$ - /** Drizzle. */ - DRIZZLE("DZ", Messages.getInstance().getString("Phenomenon.DZ")), //$NON-NLS-1$ - /** Snow. */ - SNOW("SN", Messages.getInstance().getString("Phenomenon.SN")), //$NON-NLS-1$ - /** Snow grains. */ - SNOW_GRAINS("SG", Messages.getInstance().getString("Phenomenon.SG")), //$NON-NLS-1$ - /** Ice pellets. */ - ICE_PELLETS("PL", Messages.getInstance().getString("Phenomenon.PL")), //$NON-NLS-1$ - /** Ice crystals. */ - ICE_CRYSTALS("IC", Messages.getInstance().getString("Phenomenon.IC")), //$NON-NLS-1$ - /** Hail. */ - HAIL("GR", Messages.getInstance().getString("Phenomenon.GR")), //$NON-NLS-1$ - /** Small hail. */ - SMALL_HAIL("GS", Messages.getInstance().getString("Phenomenon.GS")), //$NON-NLS-1$ - /** Unknow precipitation. */ - UNKNOW_PRECIPITATION("UP", Messages.getInstance().getString("Phenomenon.UP")), //$NON-NLS-1$ - /** Fog. */ - FOG("FG", Messages.getInstance().getString("Phenomenon.FG")), //$NON-NLS-1$ - /** Volcanic ashes. */ - VOLCANIC_ASH("VA", Messages.getInstance().getString("Phenomenon.VA")), //$NON-NLS-1$ - /** Mist. */ - MIST("BR", Messages.getInstance().getString("Phenomenon.BR")), //$NON-NLS-1$ - /** Haze. */ - HAZE("HZ", Messages.getInstance().getString("Phenomenon.HZ")), //$NON-NLS-1$ - /** Widespread dust. */ - WIDESPREAD_DUST("DU", Messages.getInstance().getString("Phenomenon.DU")), //$NON-NLS-1$ - /** Smoke. */ - SMOKE("FU", Messages.getInstance().getString("Phenomenon.FU")), //$NON-NLS-1$ - /** Sand. */ - SAND("SA", Messages.getInstance().getString("Phenomenon.SA")), //$NON-NLS-1$ - /** Spray. */ - SPRAY("PY", Messages.getInstance().getString("Phenomenon.PY")), //$NON-NLS-1$ - /** Squall. */ - SQUALL("SQ", Messages.getInstance().getString("Phenomenon.SQ")), //$NON-NLS-1$ - /** Sand whirl. */ - SAND_WHIRLS("PO", Messages.getInstance().getString("Phenomenon.PO")), //$NON-NLS-1$ - /** Duststorm. */ - DUSTSTORM("DS", Messages.getInstance().getString("Phenomenon.DS")), //$NON-NLS-1$ - /** Sandstorm. */ - SANDSTORM("SS", Messages.getInstance().getString("Phenomenon.SS")), //$NON-NLS-1$ - /** Funnel cloud. */ - FUNNEL_CLOUD("FC", Messages.getInstance().getString("Phenomenon.FC")); //$NON-NLS-1$ - - /** Shortcut of the phenomenon. */ - private String fShortcut; - /** Name of the phenomenon. */ - private String fName; - - /** - * Constructor. - * @param pShortcut - * string for the shortcut. - * @param pName - * string for the name. - */ - Phenomenon(final String pShortcut, final String pName) { - fShortcut = pShortcut; - fName = pName; - } - - @Override - public String toString() { - return fName; - } - - /** - * Returns the shortcut. - * @return string. - */ - public String getShortcut() { - return fShortcut; - } -} +package io.github.mivek.enums; + +import io.github.mivek.internationalization.Messages; + +/** + * Enumeration for phenomenon. + * The first attribute is the code used in the metar. + * The second attribute is the meaning of the code. + * + * @author mivek + */ +public enum Phenomenon { + /** Rain. */ + RAIN("RA", Messages.getInstance().getString("Phenomenon.RA")), //$NON-NLS-1$ + /** Drizzle. */ + DRIZZLE("DZ", Messages.getInstance().getString("Phenomenon.DZ")), //$NON-NLS-1$ + /** Snow. */ + SNOW("SN", Messages.getInstance().getString("Phenomenon.SN")), //$NON-NLS-1$ + /** Snow grains. */ + SNOW_GRAINS("SG", Messages.getInstance().getString("Phenomenon.SG")), //$NON-NLS-1$ + /** Ice pellets. */ + ICE_PELLETS("PL", Messages.getInstance().getString("Phenomenon.PL")), //$NON-NLS-1$ + /** Ice crystals. */ + ICE_CRYSTALS("IC", Messages.getInstance().getString("Phenomenon.IC")), //$NON-NLS-1$ + /** Hail. */ + HAIL("GR", Messages.getInstance().getString("Phenomenon.GR")), //$NON-NLS-1$ + /** Small hail. */ + SMALL_HAIL("GS", Messages.getInstance().getString("Phenomenon.GS")), //$NON-NLS-1$ + /** Unknow precipitation. */ + UNKNOW_PRECIPITATION("UP", Messages.getInstance().getString("Phenomenon.UP")), //$NON-NLS-1$ + /** Fog. */ + FOG("FG", Messages.getInstance().getString("Phenomenon.FG")), //$NON-NLS-1$ + /** Volcanic ashes. */ + VOLCANIC_ASH("VA", Messages.getInstance().getString("Phenomenon.VA")), //$NON-NLS-1$ + /** Mist. */ + MIST("BR", Messages.getInstance().getString("Phenomenon.BR")), //$NON-NLS-1$ + /** Haze. */ + HAZE("HZ", Messages.getInstance().getString("Phenomenon.HZ")), //$NON-NLS-1$ + /** Widespread dust. */ + WIDESPREAD_DUST("DU", Messages.getInstance().getString("Phenomenon.DU")), //$NON-NLS-1$ + /** Smoke. */ + SMOKE("FU", Messages.getInstance().getString("Phenomenon.FU")), //$NON-NLS-1$ + /** Sand. */ + SAND("SA", Messages.getInstance().getString("Phenomenon.SA")), //$NON-NLS-1$ + /** Spray. */ + SPRAY("PY", Messages.getInstance().getString("Phenomenon.PY")), //$NON-NLS-1$ + /** Squall. */ + SQUALL("SQ", Messages.getInstance().getString("Phenomenon.SQ")), //$NON-NLS-1$ + /** Sand whirl. */ + SAND_WHIRLS("PO", Messages.getInstance().getString("Phenomenon.PO")), //$NON-NLS-1$ + /** Duststorm. */ + DUSTSTORM("DS", Messages.getInstance().getString("Phenomenon.DS")), //$NON-NLS-1$ + /** Sandstorm. */ + SANDSTORM("SS", Messages.getInstance().getString("Phenomenon.SS")), //$NON-NLS-1$ + /** Funnel cloud. */ + FUNNEL_CLOUD("FC", Messages.getInstance().getString("Phenomenon.FC")); //$NON-NLS-1$ + + /** Shortcut of the phenomenon. */ + private final String shortcut; + /** Name of the phenomenon. */ + private final String name; + + /** + * Constructor. + * + * @param shortcut string for the shortcut. + * @param name string for the name. + */ + Phenomenon(final String shortcut, final String name) { + this.shortcut = shortcut; + this.name = name; + } + + @Override + public String toString() { + return name; + } + + /** + * Returns the shortcut. + * + * @return string. + */ + public String getShortcut() { + return shortcut; + } +} diff --git a/src/main/java/io/github/mivek/enums/TimeIndicator.java b/metarParser-entities/src/main/java/io/github/mivek/enums/TimeIndicator.java similarity index 68% rename from src/main/java/io/github/mivek/enums/TimeIndicator.java rename to metarParser-entities/src/main/java/io/github/mivek/enums/TimeIndicator.java index 0ffa0d49..4ebe31e7 100644 --- a/src/main/java/io/github/mivek/enums/TimeIndicator.java +++ b/metarParser-entities/src/main/java/io/github/mivek/enums/TimeIndicator.java @@ -1,47 +1,49 @@ -package io.github.mivek.enums; - -import io.github.mivek.internationalization.Messages; - -/** - * Enumeration for time indicator in metar trends. - * @author mivek - */ -public enum TimeIndicator { - /** The AT value of the metar trend. */ - AT("AT", Messages.getInstance().getString("TimeIndicator.AT")), - /** The FM value of the metar trend. */ - FM("FM", Messages.getInstance().getString("WeatherChangeType.FM")), - /** The TL value of the metar trend. */ - TL("TL", Messages.getInstance().getString("TimeIndicator.TL")); - - /** - * Shortcut of the time indicator. - */ - private String fShortCut = ""; - /** - * Name of the time indicator. - */ - private String fName = ""; - - /** - * Constructor. - * @param pShortCut the shortcut of the indicator. - * @param pName the name of the indicator. - */ - TimeIndicator(final String pShortCut, final String pName) { - fShortCut = pShortCut; - fName = pName; - } - - /** - * @return the shortcut. - */ - public String getShortcut() { - return fShortCut; - } - - @Override - public String toString() { - return fName; - } -} +package io.github.mivek.enums; + +import io.github.mivek.internationalization.Messages; + +/** + * Enumeration for time indicator in metar trends. + * + * @author mivek + */ +public enum TimeIndicator { + /** The AT value of the metar trend. */ + AT("AT", Messages.getInstance().getString("TimeIndicator.AT")), + /** The FM value of the metar trend. */ + FM("FM", Messages.getInstance().getString("WeatherChangeType.FM")), + /** The TL value of the metar trend. */ + TL("TL", Messages.getInstance().getString("TimeIndicator.TL")); + + /** + * Shortcut of the time indicator. + */ + private final String shortCut; + /** + * Name of the time indicator. + */ + private final String name; + + /** + * Constructor. + * + * @param shortCut the shortcut of the indicator. + * @param name the name of the indicator. + */ + TimeIndicator(final String shortCut, final String name) { + this.shortCut = shortCut; + this.name = name; + } + + /** + * @return the shortcut. + */ + public String getShortcut() { + return shortCut; + } + + @Override + public String toString() { + return name; + } +} diff --git a/src/main/java/io/github/mivek/enums/WeatherChangeType.java b/metarParser-entities/src/main/java/io/github/mivek/enums/WeatherChangeType.java similarity index 67% rename from src/main/java/io/github/mivek/enums/WeatherChangeType.java rename to metarParser-entities/src/main/java/io/github/mivek/enums/WeatherChangeType.java index 2de40334..27ef1cae 100644 --- a/src/main/java/io/github/mivek/enums/WeatherChangeType.java +++ b/metarParser-entities/src/main/java/io/github/mivek/enums/WeatherChangeType.java @@ -1,46 +1,45 @@ -package io.github.mivek.enums; - -import io.github.mivek.internationalization.Messages; - -/** - * @author mivek - */ -public enum WeatherChangeType { - /** From enumeration. */ - FM("FM", Messages.getInstance().getString("WeatherChangeType.FM")), - /** Becoming enumeration. */ - BECMG("BECMG", Messages.getInstance().getString("WeatherChangeType.BECMG")), - /** Tempo enumeration. */ - TEMPO("TEMPO", Messages.getInstance().getString("WeatherChangeType.TEMPO")), - /** Probability change. */ - PROB("PROB", Messages.getInstance().getString("WeatherChangeType.PROB")); - /** Shortcut attribute. */ - private String fShortcut = ""; - /** Name of the enumeration. */ - private String fName = ""; - - /** - * Constructor. - * @param pShortcut - * the shortcut of the enumeration - * @param pName - * the name of the enumeration - */ - WeatherChangeType(final String pShortcut, final String pName) { - fShortcut = pShortcut; - fName = pName; - } - - /** - * @return the shortcut. - */ - public String getShortcut() { - return fShortcut; - } - - @Override - public String toString() { - return fName; - } - -} +package io.github.mivek.enums; + +import io.github.mivek.internationalization.Messages; + +/** + * @author mivek + */ +public enum WeatherChangeType { + /** From enumeration. */ + FM("FM", Messages.getInstance().getString("WeatherChangeType.FM")), + /** Becoming enumeration. */ + BECMG("BECMG", Messages.getInstance().getString("WeatherChangeType.BECMG")), + /** Tempo enumeration. */ + TEMPO("TEMPO", Messages.getInstance().getString("WeatherChangeType.TEMPO")), + /** Probability change. */ + PROB("PROB", Messages.getInstance().getString("WeatherChangeType.PROB")); + /** Shortcut attribute. */ + private final String shortcut; + /** Name of the enumeration. */ + private final String name; + + /** + * Constructor. + * + * @param shortcut the shortcut of the enumeration + * @param name the name of the enumeration + */ + WeatherChangeType(final String shortcut, final String name) { + this.shortcut = shortcut; + this.name = name; + } + + /** + * @return the shortcut. + */ + public String getShortcut() { + return shortcut; + } + + @Override + public String toString() { + return name; + } + +} diff --git a/src/main/java/io/github/mivek/enums/package-info.java b/metarParser-entities/src/main/java/io/github/mivek/enums/package-info.java similarity index 95% rename from src/main/java/io/github/mivek/enums/package-info.java rename to metarParser-entities/src/main/java/io/github/mivek/enums/package-info.java index a71cbd4a..2d60e49d 100644 --- a/src/main/java/io/github/mivek/enums/package-info.java +++ b/metarParser-entities/src/main/java/io/github/mivek/enums/package-info.java @@ -1,5 +1,6 @@ -/** - * This package contains enumerations of the application. - * @author mivek - */ -package io.github.mivek.enums; +/** + * This package contains enumerations of the application. + * + * @author mivek + */ +package io.github.mivek.enums; diff --git a/src/main/java/io/github/mivek/model/AbstractWeatherCode.java b/metarParser-entities/src/main/java/io/github/mivek/model/AbstractWeatherCode.java similarity index 78% rename from src/main/java/io/github/mivek/model/AbstractWeatherCode.java rename to metarParser-entities/src/main/java/io/github/mivek/model/AbstractWeatherCode.java index 519e2cfa..57dcb33b 100644 --- a/src/main/java/io/github/mivek/model/AbstractWeatherCode.java +++ b/metarParser-entities/src/main/java/io/github/mivek/model/AbstractWeatherCode.java @@ -1,109 +1,108 @@ -package io.github.mivek.model; - -import io.github.mivek.internationalization.Messages; -import org.apache.commons.lang3.builder.ToStringBuilder; - -import java.time.LocalTime; - -/** - * @author mivek - * Parent class of {@link Metar} and {@link TAF}. - */ -public abstract class AbstractWeatherCode extends AbstractWeatherContainer { - - /** Integer for the day of the metar. */ - private Integer day; - /** Time of the metar. */ - private LocalTime time; - /** Airport of the metar. */ - private Airport airport; - /** Original message of the metar. */ - private String message; - /** The identifier of the station. */ - private String station; - - - /** - * @return the day - */ - public Integer getDay() { - return day; - } - - /** - * @param pDay the day to set - */ - public void setDay(final Integer pDay) { - day = pDay; - } - - /** - * @return the time - */ - public LocalTime getTime() { - return time; - } - - /** - * @param pTime the time to set - */ - public void setTime(final LocalTime pTime) { - time = pTime; - } - - /** - * @return the airport - */ - public Airport getAirport() { - return airport; - } - - /** - * @param pAirport the airport to set - */ - public void setAirport(final Airport pAirport) { - airport = pAirport; - } - - /** - * @return the message - */ - public String getMessage() { - return message; - } - - /** - * @param pMessage the message to set - */ - public void setMessage(final String pMessage) { - message = pMessage; - } - - /** - * @return The station. the icao. - */ - public String getStation() { - return station; - } - - /** - * @param station The identifier of the station. - */ - public void setStation(final String station) { - this.station = station; - } - - /** - * @return a description of the object. - */ - @Override - public String toString() { - return new ToStringBuilder(this). - append(Messages.getInstance().getString("ToString.day.month"), day). - append(Messages.getInstance().getString("ToString.report.time"), time). - append(Messages.getInstance().getString("ToString.airport"), airport). - appendSuper(super.toString()). - append(Messages.getInstance().getString("ToString.message"), message). - toString(); - } -} +package io.github.mivek.model; + +import io.github.mivek.internationalization.Messages; +import org.apache.commons.lang3.builder.ToStringBuilder; + +import java.time.LocalTime; + +/** + * @author mivek + * Parent class of {@link Metar} and {@link TAF}. + */ +public abstract class AbstractWeatherCode extends AbstractWeatherContainer { + + /** Integer for the day of the metar. */ + private Integer day; + /** Time of the metar. */ + private LocalTime time; + /** Airport of the metar. */ + private Airport airport; + /** Original message of the metar. */ + private String message; + /** The identifier of the station. */ + private String station; + + /** + * @return the day + */ + public Integer getDay() { + return day; + } + + /** + * @param day the day to set + */ + public void setDay(final Integer day) { + this.day = day; + } + + /** + * @return the time + */ + public LocalTime getTime() { + return time; + } + + /** + * @param time the time to set + */ + public void setTime(final LocalTime time) { + this.time = time; + } + + /** + * @return the airport + */ + public Airport getAirport() { + return airport; + } + + /** + * @param airport the airport to set + */ + public void setAirport(final Airport airport) { + this.airport = airport; + } + + /** + * @return the message + */ + public String getMessage() { + return message; + } + + /** + * @param message the message to set + */ + public void setMessage(final String message) { + this.message = message; + } + + /** + * @return The station. the icao. + */ + public String getStation() { + return station; + } + + /** + * @param station The identifier of the station. + */ + public void setStation(final String station) { + this.station = station; + } + + /** + * @return a description of the object. + */ + @Override + public String toString() { + return new ToStringBuilder(this). + append(Messages.getInstance().getString("ToString.day.month"), day). + append(Messages.getInstance().getString("ToString.report.time"), time). + append(Messages.getInstance().getString("ToString.airport"), airport). + appendSuper(super.toString()). + append(Messages.getInstance().getString("ToString.message"), message). + toString(); + } +} diff --git a/src/main/java/io/github/mivek/model/AbstractWeatherContainer.java b/metarParser-entities/src/main/java/io/github/mivek/model/AbstractWeatherContainer.java similarity index 69% rename from src/main/java/io/github/mivek/model/AbstractWeatherContainer.java rename to metarParser-entities/src/main/java/io/github/mivek/model/AbstractWeatherContainer.java index b8e325cd..a7729c14 100644 --- a/src/main/java/io/github/mivek/model/AbstractWeatherContainer.java +++ b/metarParser-entities/src/main/java/io/github/mivek/model/AbstractWeatherContainer.java @@ -1,185 +1,187 @@ -package io.github.mivek.model; - -import io.github.mivek.internationalization.Messages; -import org.apache.commons.lang3.builder.ToStringBuilder; - -import java.util.ArrayList; -import java.util.List; - -/** - * @author mivek - */ -public abstract class AbstractWeatherContainer { - /** The wind. */ - private Wind wind; - /** The visibility. */ - private Visibility visibility; - /** The list of clouds. */ - private List clouds; - /** The list of weatherConditions. */ - private List weatherConditions; - /** the vertical Visibility in feet. */ - private Integer verticalVisibility; - /** The wind shear. */ - private WindShear windShear; - /** Indicates whether the event contains CAVOK (ceiling and visibility ok). */ - private boolean cavok; - /**Contains the remarks.*/ - private String remark; - - /** - * Constructor to initialize the lists. - */ - public AbstractWeatherContainer() { - clouds = new ArrayList<>(); - weatherConditions = new ArrayList<>(); - } - - /** - * @return the wind - */ - public final Wind getWind() { - return wind; - } - - /** - * @param pWind the wind element to set. - */ - public final void setWind(final Wind pWind) { - wind = pWind; - } - - /** - * @return the visibility - */ - public final Visibility getVisibility() { - return visibility; - } - - /** - * @param pVisibility the visibility to set - */ - public final void setVisibility(final Visibility pVisibility) { - visibility = pVisibility; - } - - /** - * @return the clouds - */ - public final List getClouds() { - return clouds; - } - - /** - * @return the weatherConditions - */ - public final List getWeatherConditions() { - return weatherConditions; - } - - /** - * Adds a cloud to the list. - * @param pCloud the cloud to add. - * @return true if the cloud has been added in the list, false otherwise. - */ - public boolean addCloud(final Cloud pCloud) { - if (pCloud == null) { - return false; - } - clouds.add(pCloud); - return true; - } - - /** - * Adds a weather condition to the list. - * @param pWeatherCondition the weather condition to add. - * @return true if the weather condition has been added to the list, false - * otherwise. - */ - public boolean addWeatherCondition(final WeatherCondition pWeatherCondition) { - if (pWeatherCondition == null) { - return false; - } - weatherConditions.add(pWeatherCondition); - return true; - } - - /** - * @return the verticalVisibility in feet. - */ - public Integer getVerticalVisibility() { - return verticalVisibility; - } - - /** - * @param pVerticalVisibility the verticalVisibility to set - */ - public void setVerticalVisibility(final Integer pVerticalVisibility) { - verticalVisibility = pVerticalVisibility; - } - - /** - * @return the windShear - */ - public WindShear getWindShear() { - return windShear; - } - - /** - * @param pWindShear the windShear to set - */ - public void setWindShear(final WindShear pWindShear) { - windShear = pWindShear; - } - - /** - * @return the cavok - */ - public boolean isCavok() { - return cavok; - } - - /** - * @param pCavok the cavok to set - */ - public void setCavok(final boolean pCavok) { - cavok = pCavok; - } - - /** - * @return the remark - */ - public String getRemark() { - return remark; - } - - /** - * @param pRemark the remark to set - */ - public void setRemark(final String pRemark) { - remark = pRemark; - } - - /** - * @return string describing the object. - */ - @Override - public String toString() { - ToStringBuilder builder = new ToStringBuilder(this); - if (wind != null) { - builder.appendToString(wind.toString()); - } - if (visibility != null) { - builder.appendToString(visibility.toString()); - } - builder.append(Messages.getInstance().getString("ToString.vertical.visibility"), verticalVisibility). - append(Messages.getInstance().getString("ToString.clouds"), clouds.toString()). - append(Messages.getInstance().getString("ToString.weather.conditions"), weatherConditions.toString()); - if (windShear != null) { - builder.appendToString(windShear.toString()); - } - builder.append(Messages.getInstance().getString("ToString.cavok"), cavok). - append(Messages.getInstance().getString("ToString.remark"), remark); - return builder.toString(); - } -} +package io.github.mivek.model; + +import io.github.mivek.internationalization.Messages; +import org.apache.commons.lang3.builder.ToStringBuilder; + +import java.util.ArrayList; +import java.util.List; + +/** + * @author mivek + */ +public abstract class AbstractWeatherContainer { + /** The wind. */ + private Wind wind; + /** The visibility. */ + private Visibility visibility; + /** The list of clouds. */ + private final List clouds; + /** The list of weatherConditions. */ + private final List weatherConditions; + /** the vertical Visibility in feet. */ + private Integer verticalVisibility; + /** The wind shear. */ + private WindShear windShear; + /** Indicates whether the event contains CAVOK (ceiling and visibility ok). */ + private boolean cavok; + /** Contains the remarks. */ + private String remark; + + /** + * Constructor to initialize the lists. + */ + public AbstractWeatherContainer() { + clouds = new ArrayList<>(); + weatherConditions = new ArrayList<>(); + } + + /** + * @return the wind + */ + public final Wind getWind() { + return wind; + } + + /** + * @param wind the wind element to set. + */ + public final void setWind(final Wind wind) { + this.wind = wind; + } + + /** + * @return the visibility + */ + public final Visibility getVisibility() { + return visibility; + } + + /** + * @param visibility the visibility to set + */ + public final void setVisibility(final Visibility visibility) { + this.visibility = visibility; + } + + /** + * @return the clouds + */ + public final List getClouds() { + return clouds; + } + + /** + * @return the weatherConditions + */ + public final List getWeatherConditions() { + return weatherConditions; + } + + /** + * Adds a cloud to the list. + * + * @param cloud the cloud to add. + * @return true if the cloud has been added in the list, false otherwise. + */ + public boolean addCloud(final Cloud cloud) { + if (cloud == null) { + return false; + } + clouds.add(cloud); + return true; + } + + /** + * Adds a weather condition to the list. + * + * @param weatherCondition the weather condition to add. + * @return true if the weather condition has been added to the list, false + * otherwise. + */ + public boolean addWeatherCondition(final WeatherCondition weatherCondition) { + if (weatherCondition == null) { + return false; + } + weatherConditions.add(weatherCondition); + return true; + } + + /** + * @return the verticalVisibility in feet. + */ + public Integer getVerticalVisibility() { + return verticalVisibility; + } + + /** + * @param verticalVisibility the verticalVisibility to set + */ + public void setVerticalVisibility(final Integer verticalVisibility) { + this.verticalVisibility = verticalVisibility; + } + + /** + * @return the windShear + */ + public WindShear getWindShear() { + return windShear; + } + + /** + * @param windShear the windShear to set + */ + public void setWindShear(final WindShear windShear) { + this.windShear = windShear; + } + + /** + * @return the cavok + */ + public boolean isCavok() { + return cavok; + } + + /** + * @param cavok the cavok to set + */ + public void setCavok(final boolean cavok) { + this.cavok = cavok; + } + + /** + * @return the remark + */ + public String getRemark() { + return remark; + } + + /** + * @param remark the remark to set + */ + public void setRemark(final String remark) { + this.remark = remark; + } + + /** + * @return string describing the object. + */ + @Override + public String toString() { + ToStringBuilder builder = new ToStringBuilder(this); + if (wind != null) { + builder.appendToString(wind.toString()); + } + if (visibility != null) { + builder.appendToString(visibility.toString()); + } + builder.append(Messages.getInstance().getString("ToString.vertical.visibility"), verticalVisibility). + append(Messages.getInstance().getString("ToString.clouds"), clouds.toString()). + append(Messages.getInstance().getString("ToString.weather.conditions"), weatherConditions.toString()); + if (windShear != null) { + builder.appendToString(windShear.toString()); + } + builder.append(Messages.getInstance().getString("ToString.cavok"), cavok). + append(Messages.getInstance().getString("ToString.remark"), remark); + return builder.toString(); + } +} diff --git a/src/main/java/io/github/mivek/model/Airport.java b/metarParser-entities/src/main/java/io/github/mivek/model/Airport.java similarity index 64% rename from src/main/java/io/github/mivek/model/Airport.java rename to metarParser-entities/src/main/java/io/github/mivek/model/Airport.java index 7ac77b9f..d48442e4 100644 --- a/src/main/java/io/github/mivek/model/Airport.java +++ b/metarParser-entities/src/main/java/io/github/mivek/model/Airport.java @@ -1,229 +1,249 @@ -package io.github.mivek.model; - -/** - * Represents an airport. - * @author mivek - */ -public class Airport { - /** Name of the airport. */ - private String name; - /** Name of the city. */ - private String city; - /** Country of the airport. */ - private Country country; - /** Iata code of the airport. */ - private String iata; - /** Icao code of the airport. */ - private String icao; - /** Latitude of the airport. */ - private double latitude; - /** Longitude of the airport. */ - private double longitude; - /** Altitude of the airport. */ - private int altitude; - /** Timezone of the airport. */ - private String timezone; - /** DST of the airport. */ - private String dst; - /** tzdatabase of the aiport. */ - private String tzDatabase; - - /** - * Getter of name. - * @return string name. - */ - public String getName() { - return name; - } - - /** - * Setter of name. - * @param pName name of the airport. - */ - public void setName(final String pName) { - name = pName; - } - - /** - * Getter of city. - * @return string of city. - */ - public String getCity() { - return city; - } - - /** - * Setter of the city. - * @param pCity string of the name of the city. - */ - public void setCity(final String pCity) { - city = pCity; - } - - /** - * Getter of country. - * @return a country object. - */ - public Country getCountry() { - return country; - } - - /** - * Setter of country. - * @param pCountry The country to set. - */ - public void setCountry(final Country pCountry) { - country = pCountry; - } - - /** - * Getter of iata. - * @return string of iata. - */ - public String getIata() { - return iata; - } - - /** - * Setter of iata code. - * @param pIata string of iata. - */ - public void setIata(final String pIata) { - iata = pIata; - } - - /** - * Getter of Icao code. - * @return string icao code. - */ - public String getIcao() { - return icao; - } - - /** - * Setter of icao. - * @param pIcao string of icao. - */ - public void setIcao(final String pIcao) { - icao = pIcao; - } - - /** - * Getter of latitude. - * @return latitude. - */ - public double getLatitude() { - return latitude; - } - - /** - * Setter of latitude. - * - * @param pLatitude Latitude to set. - */ - public void setLatitude(final double pLatitude) { - latitude = pLatitude; - } - - /** - * Getter of longitude. - * @return longitude. - */ - public double getLongitude() { - return longitude; - } - - /** - * Setter of longitude. - * - * @param pLongitude to set. - */ - public void setLongitude(final double pLongitude) { - longitude = pLongitude; - } - - /** - * Getter of altitude. - * @return altitude. - */ - public int getAltitude() { - return altitude; - } - - /** - * Setter of altitude. - * - * @param pAltitude the altitude to set. - */ - public void setAltitude(final int pAltitude) { - altitude = pAltitude; - } - - /** - * Getter of timezone. - * @return string of timezone. - */ - public String getTimezone() { - return timezone; - } - - /** - * Setter of timezone. - * @param pTimezone timezone string to set. - */ - public void setTimezone(final String pTimezone) { - timezone = pTimezone; - } - - /** - * Getter of DST. - * @return string of dst. - */ - public String getDst() { - return dst; - } - - /** - * Setter of DST. - * @param pDst the dst to set. - */ - public void setDst(final String pDst) { - dst = pDst; - } - - /** - * Getter of tzDatabase. - * @return string of tzDatabase. - */ - public String getTzDatabase() { - return tzDatabase; - } - - /** - * Setter of tzDatabase. - * @param pTzDatabase The tzDatabase to set. - */ - public void setTzDatabase(final String pTzDatabase) { - tzDatabase = pTzDatabase; - } - - @Override - public final boolean equals(final Object pObj) { - if (pObj instanceof Airport) { - return icao.equals(((Airport) pObj).getIcao()); - } - return false; - } - - @Override - public final int hashCode() { - int result; - result = 31 * icao.hashCode(); - return result; - } - - @Override - public final String toString() { - return name + " (" + icao + ")"; - } -} +package io.github.mivek.model; + +/** + * Represents an airport. + * + * @author mivek + */ +public class Airport { + /** Name of the airport. */ + private String name; + /** Name of the city. */ + private String city; + /** Country of the airport. */ + private Country country; + /** Iata code of the airport. */ + private String iata; + /** Icao code of the airport. */ + private String icao; + /** Latitude of the airport. */ + private double latitude; + /** Longitude of the airport. */ + private double longitude; + /** Altitude of the airport. */ + private int altitude; + /** Timezone of the airport. */ + private String timezone; + /** DST of the airport. */ + private String dst; + /** tzdatabase of the aiport. */ + private String tzDatabase; + + /** + * Getter of name. + * + * @return string name. + */ + public String getName() { + return name; + } + + /** + * Setter of name. + * + * @param name name of the airport. + */ + public void setName(final String name) { + this.name = name; + } + + /** + * Getter of city. + * + * @return string of city. + */ + public String getCity() { + return city; + } + + /** + * Setter of the city. + * + * @param city string of the name of the city. + */ + public void setCity(final String city) { + this.city = city; + } + + /** + * Getter of country. + * + * @return a country object. + */ + public Country getCountry() { + return country; + } + + /** + * Setter of country. + * + * @param country The country to set. + */ + public void setCountry(final Country country) { + this.country = country; + } + + /** + * Getter of iata. + * + * @return string of iata. + */ + public String getIata() { + return iata; + } + + /** + * Setter of iata code. + * + * @param iata string of iata. + */ + public void setIata(final String iata) { + this.iata = iata; + } + + /** + * Getter of Icao code. + * + * @return string icao code. + */ + public String getIcao() { + return icao; + } + + /** + * Setter of icao. + * + * @param icao string of icao. + */ + public void setIcao(final String icao) { + this.icao = icao; + } + + /** + * Getter of latitude. + * + * @return latitude. + */ + public double getLatitude() { + return latitude; + } + + /** + * Setter of latitude. + * + * @param latitude Latitude to set. + */ + public void setLatitude(final double latitude) { + this.latitude = latitude; + } + + /** + * Getter of longitude. + * + * @return longitude. + */ + public double getLongitude() { + return longitude; + } + + /** + * Setter of longitude. + * + * @param longitude to set. + */ + public void setLongitude(final double longitude) { + this.longitude = longitude; + } + + /** + * Getter of altitude. + * + * @return altitude. + */ + public int getAltitude() { + return altitude; + } + + /** + * Setter of altitude. + * + * @param altitude the altitude to set. + */ + public void setAltitude(final int altitude) { + this.altitude = altitude; + } + + /** + * Getter of timezone. + * + * @return string of timezone. + */ + public String getTimezone() { + return timezone; + } + + /** + * Setter of timezone. + * + * @param timezone timezone string to set. + */ + public void setTimezone(final String timezone) { + this.timezone = timezone; + } + + /** + * Getter of DST. + * + * @return string of dst. + */ + public String getDst() { + return dst; + } + + /** + * Setter of DST. + * + * @param dst the dst to set. + */ + public void setDst(final String dst) { + this.dst = dst; + } + + /** + * Getter of tzDatabase. + * + * @return string of tzDatabase. + */ + public String getTzDatabase() { + return tzDatabase; + } + + /** + * Setter of tzDatabase. + * + * @param tzDatabase The tzDatabase to set. + */ + public void setTzDatabase(final String tzDatabase) { + this.tzDatabase = tzDatabase; + } + + @Override + public final boolean equals(final Object obj) { + if (obj instanceof Airport) { + return icao.equals(((Airport) obj).getIcao()); + } + return false; + } + + @Override + public final int hashCode() { + int result; + result = 31 * icao.hashCode(); + return result; + } + + @Override + public final String toString() { + return name + " (" + icao + ")"; + } +} diff --git a/src/main/java/io/github/mivek/model/Cloud.java b/metarParser-entities/src/main/java/io/github/mivek/model/Cloud.java similarity index 59% rename from src/main/java/io/github/mivek/model/Cloud.java rename to metarParser-entities/src/main/java/io/github/mivek/model/Cloud.java index 01ffedd6..afe70e48 100644 --- a/src/main/java/io/github/mivek/model/Cloud.java +++ b/metarParser-entities/src/main/java/io/github/mivek/model/Cloud.java @@ -1,98 +1,84 @@ -package io.github.mivek.model; - -import io.github.mivek.enums.CloudQuantity; -import io.github.mivek.enums.CloudType; -import io.github.mivek.internationalization.Messages; -import org.apache.commons.lang3.builder.ToStringBuilder; - -/** - * Class representing a cloud element. Clouds are composed of : a quantity a - * type (optional) an height (optional) - * @author mivek - */ -public class Cloud { - /** The height of the cloud (unit: feet). */ - private int height; - /** The quantity of the cloud. */ - private CloudQuantity quantity; - /** The type of the cloud. */ - private CloudType type; - - /** - * Getter of the altitude (unit: meters, approximation). - * @return int of altitude. - * @deprecated Use {@link #getHeight()} - */ - @Deprecated - public int getAltitude() { - return height * 30 / 100; - } - - /** - * Setter of the altitude (unit: meters). - * - * @param pAltitude The altitude to set. - * @deprecated Use {@link #setHeight(int)} - */ - @Deprecated public void setAltitude(final int pAltitude) { - height = pAltitude * 100 / 30; - } - - /** - * Getter of the height (unit: feet). - * @return int of height. - */ - public int getHeight() { - return height; - } - - /** - * Setter of the height (unit: feet). - * @param pHeight The height to set. - */ - public void setHeight(final int pHeight) { - height = pHeight; - } - - /** - * Getter of the quantity. - * @return a CloudQuantity. - */ - public CloudQuantity getQuantity() { - return quantity; - } - - /** - * Setter of CloudQuantity. - * @param pQuantity The CloudQuantity to set. - */ - public void setQuantity(final CloudQuantity pQuantity) { - quantity = pQuantity; - } - - /** - * Getter of type. - * @return a CloudType. - */ - public CloudType getType() { - return type; - } - - /** - * Setter of cloud type. - * @param pType The CloudType to set. - */ - public void setType(final CloudType pType) { - type = pType; - } - - @Override - public final String toString() { - return new ToStringBuilder(this). - append(Messages.getInstance().getString("ToString.quantity"), quantity). - append(Messages.getInstance().getString("ToString.type"), type). - append(Messages.getInstance().getString("ToString.height.feet"), height). - append(Messages.getInstance().getString("ToString.height.meter"), getAltitude()). - toString(); - } -} +package io.github.mivek.model; + +import io.github.mivek.enums.CloudQuantity; +import io.github.mivek.enums.CloudType; +import io.github.mivek.internationalization.Messages; +import org.apache.commons.lang3.builder.ToStringBuilder; + +/** + * Class representing a cloud element. Clouds are composed of : a quantity a + * type (optional) an height (optional) + * + * @author mivek + */ +public class Cloud { + /** The height of the cloud (unit: feet). */ + private int height; + /** The quantity of the cloud. */ + private CloudQuantity quantity; + /** The type of the cloud. */ + private CloudType type; + + /** + * Getter of the height (unit: feet). + * + * @return int of height. + */ + public int getHeight() { + return height; + } + + /** + * Setter of the height (unit: feet). + * + * @param height The height to set. + */ + public void setHeight(final int height) { + this.height = height; + } + + /** + * Getter of the quantity. + * + * @return a CloudQuantity. + */ + public CloudQuantity getQuantity() { + return quantity; + } + + /** + * Setter of CloudQuantity. + * + * @param quantity The CloudQuantity to set. + */ + public void setQuantity(final CloudQuantity quantity) { + this.quantity = quantity; + } + + /** + * Getter of type. + * + * @return a CloudType. + */ + public CloudType getType() { + return type; + } + + /** + * Setter of cloud type. + * + * @param type The CloudType to set. + */ + public void setType(final CloudType type) { + this.type = type; + } + + @Override + public final String toString() { + return new ToStringBuilder(this). + append(Messages.getInstance().getString("ToString.quantity"), quantity). + append(Messages.getInstance().getString("ToString.type"), type). + append(Messages.getInstance().getString("ToString.height.feet"), height). + toString(); + } +} diff --git a/src/main/java/io/github/mivek/model/Country.java b/metarParser-entities/src/main/java/io/github/mivek/model/Country.java similarity index 75% rename from src/main/java/io/github/mivek/model/Country.java rename to metarParser-entities/src/main/java/io/github/mivek/model/Country.java index 7b2a9220..c5891bcb 100644 --- a/src/main/java/io/github/mivek/model/Country.java +++ b/metarParser-entities/src/main/java/io/github/mivek/model/Country.java @@ -1,33 +1,36 @@ -package io.github.mivek.model; - -/** - * Country class. - * @author mivek - */ -public class Country { - /** - * Name of the country. - */ - private String name; - - /** - * Getter of name. - * @return the name. - */ - public String getName() { - return name; - } - - /** - * Setter of name. - * @param pName the name to set. - */ - public void setName(final String pName) { - name = pName; - } - - @Override - public final String toString() { - return name; - } -} +package io.github.mivek.model; + +/** + * Country class. + * + * @author mivek + */ +public class Country { + /** + * Name of the country. + */ + private String name; + + /** + * Getter of name. + * + * @return the name. + */ + public String getName() { + return name; + } + + /** + * Setter of name. + * + * @param name the name to set. + */ + public void setName(final String name) { + this.name = name; + } + + @Override + public final String toString() { + return name; + } +} diff --git a/src/main/java/io/github/mivek/model/Metar.java b/metarParser-entities/src/main/java/io/github/mivek/model/Metar.java similarity index 68% rename from src/main/java/io/github/mivek/model/Metar.java rename to metarParser-entities/src/main/java/io/github/mivek/model/Metar.java index 8d507a91..214269a9 100644 --- a/src/main/java/io/github/mivek/model/Metar.java +++ b/metarParser-entities/src/main/java/io/github/mivek/model/Metar.java @@ -1,152 +1,156 @@ -package io.github.mivek.model; - -import io.github.mivek.internationalization.Messages; -import io.github.mivek.model.trend.AbstractMetarTrend; -import org.apache.commons.lang3.Validate; -import org.apache.commons.lang3.builder.ToStringBuilder; - -import java.util.ArrayList; -import java.util.List; - -/** - * Metar class. - * @author mivek - */ -public class Metar extends AbstractWeatherCode { - /** Temperature. */ - private Integer temperature; - /** Dew point. */ - private Integer dewPoint; - /** Altimeter in HPa. */ - private Integer altimeter; - /** Nosig value. */ - private boolean nosig; - /** Auto Value. */ - private boolean auto; - /** List of runways information. */ - private List runways; - /** List of trends. */ - private List trends; - - /** - * Constructor. - */ - public Metar() { - super(); - runways = new ArrayList<>(); - trends = new ArrayList<>(); - } - - /** - * @return the temperature - */ - public Integer getTemperature() { - return temperature; - } - - /** - * @param pTemperature the temperature to set - */ - public void setTemperature(final Integer pTemperature) { - temperature = pTemperature; - } - - /** - * @return the dewPoint - */ - public Integer getDewPoint() { - return dewPoint; - } - - /** - * @param pDewPoint the dewPoint to set - */ - public void setDewPoint(final Integer pDewPoint) { - dewPoint = pDewPoint; - } - - /** - * @return the altimeter in HPa. - */ - public Integer getAltimeter() { - return altimeter; - } - - /** - * @param pAltimeter the altimeter to set - */ - public void setAltimeter(final Integer pAltimeter) { - altimeter = pAltimeter; - } - - /** - * @return the runways - */ - public List getRunways() { - return runways; - } - - /** - * Adds a runway to the list. - * @param pRunwayInformation the runway to add. - */ - public void addRunwayInfo(final RunwayInfo pRunwayInformation) { - runways.add(pRunwayInformation); - } - - /** - * @return the nosig - */ - public boolean isNosig() { - return nosig; - } - - /** - * @param pNosig the nosig to set - */ - public void setNosig(final boolean pNosig) { - nosig = pNosig; - } - - /** - * @return the auto - */ - public boolean isAuto() { - return auto; - } - - /** - * @param pAuto the auto to set - */ - public void setAuto(final boolean pAuto) { - auto = pAuto; - } - - /** - * Adds a trend to the list. - * @param pTrend the trend to add. - */ - public void addTrend(final AbstractMetarTrend pTrend) { - trends.add(Validate.notNull(pTrend)); - } - - /** - * @return the list of trends. - */ - public List getTrends() { - return trends; - } - - @Override public final String toString() { - return new ToStringBuilder(this). - appendSuper(super.toString()). - append(Messages.getInstance().getString("ToString.temperature"), temperature). - append(Messages.getInstance().getString("ToString.dew.point"), dewPoint). - append(Messages.getInstance().getString("ToString.altimeter"), altimeter). - append(Messages.getInstance().getString("ToString.nosig"), nosig). - append(Messages.getInstance().getString("ToString.auto"), auto). - append(Messages.getInstance().getString("ToString.runway.info"), runways.toString()). - append(Messages.getInstance().getString("ToString.trends"), trends.toString()). - toString(); - } -} +package io.github.mivek.model; + +import io.github.mivek.internationalization.Messages; +import io.github.mivek.model.trend.AbstractMetarTrend; +import org.apache.commons.lang3.Validate; +import org.apache.commons.lang3.builder.ToStringBuilder; + +import java.util.ArrayList; +import java.util.List; + +/** + * Metar class. + * + * @author mivek + */ +public class Metar extends AbstractWeatherCode { + /** Temperature. */ + private Integer temperature; + /** Dew point. */ + private Integer dewPoint; + /** Altimeter in HPa. */ + private Integer altimeter; + /** Nosig value. */ + private boolean nosig; + /** Auto Value. */ + private boolean auto; + /** List of runways information. */ + private final List runways; + /** List of trends. */ + private final List trends; + + /** + * Constructor. + */ + public Metar() { + super(); + runways = new ArrayList<>(); + trends = new ArrayList<>(); + } + + /** + * @return the temperature + */ + public Integer getTemperature() { + return temperature; + } + + /** + * @param temperature the temperature to set + */ + public void setTemperature(final Integer temperature) { + this.temperature = temperature; + } + + /** + * @return the dewPoint + */ + public Integer getDewPoint() { + return dewPoint; + } + + /** + * @param dewPoint the dewPoint to set + */ + public void setDewPoint(final Integer dewPoint) { + this.dewPoint = dewPoint; + } + + /** + * @return the altimeter in HPa. + */ + public Integer getAltimeter() { + return altimeter; + } + + /** + * @param altimeter the altimeter to set + */ + public void setAltimeter(final Integer altimeter) { + this.altimeter = altimeter; + } + + /** + * @return the runways + */ + public List getRunways() { + return runways; + } + + /** + * Adds a runway to the list. + * + * @param runwayInformation the runway to add. + */ + public void addRunwayInfo(final RunwayInfo runwayInformation) { + runways.add(runwayInformation); + } + + /** + * @return the nosig + */ + public boolean isNosig() { + return nosig; + } + + /** + * @param nosig the nosig to set + */ + public void setNosig(final boolean nosig) { + this.nosig = nosig; + } + + /** + * @return the auto + */ + public boolean isAuto() { + return auto; + } + + /** + * @param auto the auto to set + */ + public void setAuto(final boolean auto) { + this.auto = auto; + } + + /** + * Adds a trend to the list. + * + * @param trend the trend to add. + */ + public void addTrend(final AbstractMetarTrend trend) { + trends.add(Validate.notNull(trend)); + } + + /** + * @return the list of trends. + */ + public List getTrends() { + return trends; + } + + @Override + public final String toString() { + return new ToStringBuilder(this). + appendSuper(super.toString()). + append(Messages.getInstance().getString("ToString.temperature"), temperature). + append(Messages.getInstance().getString("ToString.dew.point"), dewPoint). + append(Messages.getInstance().getString("ToString.altimeter"), altimeter). + append(Messages.getInstance().getString("ToString.nosig"), nosig). + append(Messages.getInstance().getString("ToString.auto"), auto). + append(Messages.getInstance().getString("ToString.runway.info"), runways.toString()). + append(Messages.getInstance().getString("ToString.trends"), trends.toString()). + toString(); + } +} diff --git a/src/main/java/io/github/mivek/model/RunwayInfo.java b/metarParser-entities/src/main/java/io/github/mivek/model/RunwayInfo.java similarity index 75% rename from src/main/java/io/github/mivek/model/RunwayInfo.java rename to metarParser-entities/src/main/java/io/github/mivek/model/RunwayInfo.java index e583655c..f48782a1 100644 --- a/src/main/java/io/github/mivek/model/RunwayInfo.java +++ b/metarParser-entities/src/main/java/io/github/mivek/model/RunwayInfo.java @@ -1,94 +1,103 @@ -package io.github.mivek.model; - -import io.github.mivek.internationalization.Messages; -import org.apache.commons.lang3.builder.ToStringBuilder; - -/** - * Runway class. - * @author mivek - */ -public class RunwayInfo { - /** The name of the runway. */ - private String name; - /** The minimal visibility on the runway. */ - private int minRange; - /** The maximal visibility on the runway. */ - private int maxRange; - /** The tread. */ - private String trend; - - /** - * Getter of name. - * @return the name. - */ - public String getName() { - return name; - } - - /** - * Setter of name. - * @param pName the name to set. - */ - public void setName(final String pName) { - name = pName; - } - - /** - * Getter of minimal range. - * @return the minRange. - */ - public int getMinRange() { - return minRange; - } - - /** - * The setter of minRange. - * @param pMinRange the minRange to set. - */ - public void setMinRange(final int pMinRange) { - minRange = pMinRange; - } - - /** - * Getter of maxRange. - * @return maxRange. - */ - public int getMaxRange() { - return maxRange; - } - - /** - * Setter of maxRange. - * @param pMaxRange the maxrange to set. - */ - public void setMaxRange(final int pMaxRange) { - maxRange = pMaxRange; - } - - /** - * Getter of the trend. - * @return the trend. - */ - public String getTrend() { - return trend; - } - - /** - * Setter of the trend. - * @param pTrend Trend to set. - */ - public void setTrend(final String pTrend) { - trend = pTrend; - } - - @Override - public final String toString() { - return new ToStringBuilder(this). - append(Messages.getInstance().getString("ToString.name"), name). - append(Messages.getInstance().getString("ToString.visibility.min"), minRange). - append(Messages.getInstance().getString("ToString.visibility.max"), maxRange). - append(Messages.getInstance().getString("ToString.trend"), trend). - toString(); - - } -} +package io.github.mivek.model; + +import io.github.mivek.internationalization.Messages; +import org.apache.commons.lang3.builder.ToStringBuilder; + +/** + * Runway class. + * + * @author mivek + */ +public class RunwayInfo { + /** The name of the runway. */ + private String name; + /** The minimal visibility on the runway. */ + private int minRange; + /** The maximal visibility on the runway. */ + private int maxRange; + /** The tread. */ + private String trend; + + /** + * Getter of name. + * + * @return the name. + */ + public String getName() { + return name; + } + + /** + * Setter of name. + * + * @param name the name to set. + */ + public void setName(final String name) { + this.name = name; + } + + /** + * Getter of minimal range. + * + * @return the minRange. + */ + public int getMinRange() { + return minRange; + } + + /** + * The setter of minRange. + * + * @param minRange the minRange to set. + */ + public void setMinRange(final int minRange) { + this.minRange = minRange; + } + + /** + * Getter of maxRange. + * + * @return maxRange. + */ + public int getMaxRange() { + return maxRange; + } + + /** + * Setter of maxRange. + * + * @param maxRange the maxrange to set. + */ + public void setMaxRange(final int maxRange) { + this.maxRange = maxRange; + } + + /** + * Getter of the trend. + * + * @return the trend. + */ + public String getTrend() { + return trend; + } + + /** + * Setter of the trend. + * + * @param trend Trend to set. + */ + public void setTrend(final String trend) { + this.trend = trend; + } + + @Override + public final String toString() { + return new ToStringBuilder(this). + append(Messages.getInstance().getString("ToString.name"), name). + append(Messages.getInstance().getString("ToString.visibility.min"), minRange). + append(Messages.getInstance().getString("ToString.visibility.max"), maxRange). + append(Messages.getInstance().getString("ToString.trend"), trend). + toString(); + + } +} diff --git a/src/main/java/io/github/mivek/model/TAF.java b/metarParser-entities/src/main/java/io/github/mivek/model/TAF.java similarity index 58% rename from src/main/java/io/github/mivek/model/TAF.java rename to metarParser-entities/src/main/java/io/github/mivek/model/TAF.java index 0175d6df..1f2390ce 100644 --- a/src/main/java/io/github/mivek/model/TAF.java +++ b/metarParser-entities/src/main/java/io/github/mivek/model/TAF.java @@ -1,171 +1,174 @@ -package io.github.mivek.model; - -import io.github.mivek.internationalization.Messages; -import io.github.mivek.model.trend.BECMGTafTrend; -import io.github.mivek.model.trend.FMTafTrend; -import io.github.mivek.model.trend.PROBTafTrend; -import io.github.mivek.model.trend.TEMPOTafTrend; -import io.github.mivek.model.trend.validity.Validity; -import org.apache.commons.lang3.builder.ToStringBuilder; - -import java.util.ArrayList; -import java.util.List; - -/** - * Class representing a TAF. - * @author mivek - */ -public class TAF extends AbstractWeatherCode { - /** The valididty of the TAF. */ - private Validity validity; - /** The maximum temperature. */ - private TemperatureDated maxTemperature; - /** The minimum temperature. */ - private TemperatureDated minTemperature; - /** List of BECMG changes. */ - private List bECMGs; - /** List of From changes. */ - private List fMs; - /** List of Tempos changes. */ - private List tempos; - /** List of probability changes. */ - private List probs; - /**Indicate if the taf event is ameded.*/ - private boolean amendment; - - /** - * Constructor. - */ - public TAF() { - super(); - bECMGs = new ArrayList<>(); - fMs = new ArrayList<>(); - tempos = new ArrayList<>(); - probs = new ArrayList<>(); - } - - /** - * @return the validity - */ - public Validity getValidity() { - return validity; - } - - /** - * @param pValidity the validity to set - */ - public void setValidity(final Validity pValidity) { - validity = pValidity; - } - - /** - * @return the maxTemperature - */ - public TemperatureDated getMaxTemperature() { - return maxTemperature; - } - - /** - * @param pMaxTemperature the maxTemperature to set - */ - public void setMaxTemperature(final TemperatureDated pMaxTemperature) { - maxTemperature = pMaxTemperature; - } - - /** - * @return the minTemperature - */ - public TemperatureDated getMinTemperature() { - return minTemperature; - } - - /** - * @param pMinTemperature the minTemperature to set - */ - public void setMinTemperature(final TemperatureDated pMinTemperature) { - minTemperature = pMinTemperature; - } - - /** - * @return the bECMGs - */ - public List getBECMGs() { - return bECMGs; - } - - /** - * @return the fMs - */ - public List getFMs() { - return fMs; - } - - /** - * @return the probs - */ - public List getProbs() { - return probs; - } - - /** - * Adds a tempo change to the list. - * @param pChange the change to add. - */ - public void addTempo(final TEMPOTafTrend pChange) { - tempos.add(pChange); - } - - /** - * Adds a PROB Change to the list. - * @param pChange the change to add. - */ - public void addProb(final PROBTafTrend pChange) { - probs.add(pChange); - } - - /** - * Adds a BECMG to the list. - * @param pChange the change to add. - */ - public void addBECMG(final BECMGTafTrend pChange) { - bECMGs.add(pChange); - } - - /** - * Adds a FM change to the list. - * @param pChange the change to add. - */ - public void addFM(final FMTafTrend pChange) { - fMs.add(pChange); - } - - /** - * @return the tempos - */ - public List getTempos() { - return tempos; - } - - /** - * @return the amendment - */ - public boolean isAmendment() { - return amendment; - } - - /** - * @param pAmendment the amendment to set - */ - public void setAmendment(final boolean pAmendment) { - amendment = pAmendment; - } - - @Override public final String toString() { - return new ToStringBuilder(this).appendSuper(super.toString()).appendToString(validity.toString()) - .append(Messages.getInstance().getString("ToString.temperature.max"), maxTemperature) - .append(Messages.getInstance().getString("ToString.temperature.min"), minTemperature) - .append(Messages.getInstance().getString("ToString.amendment"), amendment) - .appendToString(bECMGs.toString()).appendToString(fMs.toString()).appendToString(tempos.toString()) - .appendToString(probs.toString()).toString(); - } -} +package io.github.mivek.model; + +import io.github.mivek.internationalization.Messages; +import io.github.mivek.model.trend.BECMGTafTrend; +import io.github.mivek.model.trend.FMTafTrend; +import io.github.mivek.model.trend.PROBTafTrend; +import io.github.mivek.model.trend.TEMPOTafTrend; +import io.github.mivek.model.trend.validity.Validity; +import org.apache.commons.lang3.builder.ToStringBuilder; + +import java.util.ArrayList; +import java.util.List; + +/** + * Class representing a TAF. + * + * @author mivek + */ +public class TAF extends AbstractWeatherCode { + /** The valididty of the TAF. */ + private Validity validity; + /** The maximum temperature. */ + private TemperatureDated maxTemperature; + /** The minimum temperature. */ + private TemperatureDated minTemperature; + /** List of BECMG changes. */ + private final List bECMGs; + /** List of From changes. */ + private final List fMs; + /** List of Tempos changes. */ + private final List tempos; + /** List of probability changes. */ + private final List probs; + /** Indicate if the taf event is ameded. */ + private boolean amendment; + + /** + * Constructor. + */ + public TAF() { + super(); + bECMGs = new ArrayList<>(); + fMs = new ArrayList<>(); + tempos = new ArrayList<>(); + probs = new ArrayList<>(); + } + + /** + * @return the validity + */ + public Validity getValidity() { + return validity; + } + + /** + * @param validity the validity to set + */ + public void setValidity(final Validity validity) { + this.validity = validity; + } + + /** + * @return the maxTemperature + */ + public TemperatureDated getMaxTemperature() { + return maxTemperature; + } + + /** + * @param maxTemperature the maxTemperature to set + */ + public void setMaxTemperature(final TemperatureDated maxTemperature) { + this.maxTemperature = maxTemperature; + } + + /** + * @return the minTemperature + */ + public TemperatureDated getMinTemperature() { + return minTemperature; + } + + /** + * @param minTemperature the minTemperature to set + */ + public void setMinTemperature(final TemperatureDated minTemperature) { + this.minTemperature = minTemperature; + } + + /** + * @return the bECMGs + */ + public List getBECMGs() { + return bECMGs; + } + + /** + * @return the fMs + */ + public List getFMs() { + return fMs; + } + + /** + * @return the probs + */ + public List getProbs() { + return probs; + } + + /** + * Adds a tempo change to the list. + * + * @param change the change to add. + */ + public void addTempo(final TEMPOTafTrend change) { + tempos.add(change); + } + + /** + * Adds a PROB Change to the list. + * + * @param change the change to add. + */ + public void addProb(final PROBTafTrend change) { + probs.add(change); + } + + /** + * Adds a BECMG to the list. + * + * @param change the change to add. + */ + public void addBECMG(final BECMGTafTrend change) { + bECMGs.add(change); + } + + /** + * Adds a FM change to the list. + * + * @param change the change to add. + */ + public void addFM(final FMTafTrend change) { + fMs.add(change); + } + + /** + * @return the tempos + */ + public List getTempos() { + return tempos; + } + + /** + * @return the amendment + */ + public boolean isAmendment() { + return amendment; + } + + /** + * @param amendment the amendment to set + */ + public void setAmendment(final boolean amendment) { + this.amendment = amendment; + } + + @Override + public final String toString() { + return new ToStringBuilder(this).appendSuper(super.toString()).appendToString(validity.toString()).append(Messages.getInstance().getString("ToString.temperature.max"), maxTemperature) + .append(Messages.getInstance().getString("ToString.temperature.min"), minTemperature).append(Messages.getInstance().getString("ToString.amendment"), amendment) + .appendToString(bECMGs.toString()).appendToString(fMs.toString()).appendToString(tempos.toString()).appendToString(probs.toString()).toString(); + } +} diff --git a/src/main/java/io/github/mivek/model/TemperatureDated.java b/metarParser-entities/src/main/java/io/github/mivek/model/TemperatureDated.java similarity index 73% rename from src/main/java/io/github/mivek/model/TemperatureDated.java rename to metarParser-entities/src/main/java/io/github/mivek/model/TemperatureDated.java index aca4dae8..3fab2f4e 100644 --- a/src/main/java/io/github/mivek/model/TemperatureDated.java +++ b/metarParser-entities/src/main/java/io/github/mivek/model/TemperatureDated.java @@ -1,68 +1,69 @@ -package io.github.mivek.model; - -import io.github.mivek.internationalization.Messages; -import org.apache.commons.lang3.builder.ToStringBuilder; - -/** - * Class representing a temperature with its date. - * @author mivek - */ -public class TemperatureDated { - /** The temperature. */ - private Integer temperature; - /** The day. */ - private Integer day; - /** The hour. */ - private Integer hour; - - /** - * @return the temperature - */ - public Integer getTemperature() { - return temperature; - } - - /** - * @param pTemperature the temperature to set - */ - public void setTemperature(final Integer pTemperature) { - temperature = pTemperature; - } - - /** - * @return the day - */ - public Integer getDay() { - return day; - } - - /** - * @param pDay the day to set - */ - public void setDay(final Integer pDay) { - day = pDay; - } - - /** - * @return the hour - */ - public Integer getHour() { - return hour; - } - - /** - * @param pHour the hour to set - */ - public void setHour(final Integer pHour) { - hour = pHour; - } - - @Override - public final String toString() { - return new ToStringBuilder(this). - append(Messages.getInstance().getString("ToString.temperature"), temperature). - append(Messages.getInstance().getString("ToString.day.month"), day). - append(Messages.getInstance().getString("ToString.day.hour"), hour). - toString(); - } -} +package io.github.mivek.model; + +import io.github.mivek.internationalization.Messages; +import org.apache.commons.lang3.builder.ToStringBuilder; + +/** + * Class representing a temperature with its date. + * + * @author mivek + */ +public class TemperatureDated { + /** The temperature. */ + private Integer temperature; + /** The day. */ + private Integer day; + /** The hour. */ + private Integer hour; + + /** + * @return the temperature + */ + public Integer getTemperature() { + return temperature; + } + + /** + * @param temperature the temperature to set + */ + public void setTemperature(final Integer temperature) { + this.temperature = temperature; + } + + /** + * @return the day + */ + public Integer getDay() { + return day; + } + + /** + * @param day the day to set + */ + public void setDay(final Integer day) { + this.day = day; + } + + /** + * @return the hour + */ + public Integer getHour() { + return hour; + } + + /** + * @param hour the hour to set + */ + public void setHour(final Integer hour) { + this.hour = hour; + } + + @Override + public final String toString() { + return new ToStringBuilder(this). + append(Messages.getInstance().getString("ToString.temperature"), temperature). + append(Messages.getInstance().getString("ToString.day.month"), day). + append(Messages.getInstance().getString("ToString.day.hour"), hour). + toString(); + } +} diff --git a/src/main/java/io/github/mivek/model/Visibility.java b/metarParser-entities/src/main/java/io/github/mivek/model/Visibility.java similarity index 73% rename from src/main/java/io/github/mivek/model/Visibility.java rename to metarParser-entities/src/main/java/io/github/mivek/model/Visibility.java index 7de1a82e..d891d45d 100644 --- a/src/main/java/io/github/mivek/model/Visibility.java +++ b/metarParser-entities/src/main/java/io/github/mivek/model/Visibility.java @@ -1,73 +1,80 @@ -package io.github.mivek.model; - -import io.github.mivek.internationalization.Messages; -import org.apache.commons.lang3.builder.ToStringBuilder; - -/** - * Visisbility class. - * @author mivek - */ -public class Visibility { - /** mainVisibility of the metar. */ - private String mainVisibility; - /** minimal visibility of the metar. */ - private int minVisibility; - /** Direction of the minimal visibility. */ - private String minDirection; - - /** - * Getter of the mainVisibility. - * @return the mainvisibility. - */ - public String getMainVisibility() { - return mainVisibility; - } - - /** - * Setter of the main visibility. - * @param pMainVisibility the main visibility to set. - */ - public void setMainVisibility(final String pMainVisibility) { - mainVisibility = pMainVisibility; - } - - /** - * Getter of the minimal visibility. - * @return the minimal visibility. - */ - public int getMinVisibility() { - return minVisibility; - } - - /** - * Setter of the minimal visibility. - * @param pMinVisibility the minimal visibility to set. - */ - public void setMinVisibility(final int pMinVisibility) { - minVisibility = pMinVisibility; - } - - /** - * Getter of direction. - * @return the direction. - */ - public String getMinDirection() { - return minDirection; - } - - /** - * Setter of the minimal direction. - * @param pMinDirection the minimal direction to set. - */ - public void setMinDirection(final String pMinDirection) { - minDirection = pMinDirection; - } - - @Override - public final String toString() { - return new ToStringBuilder(this). - append(Messages.getInstance().getString("ToString.visibility.main"), mainVisibility). - append(Messages.getInstance().getString("ToString.visibility.min"), minVisibility). - append(Messages.getInstance().getString("ToString.visibility.min.direction"), minDirection).toString(); - } -} +package io.github.mivek.model; + +import io.github.mivek.internationalization.Messages; +import org.apache.commons.lang3.builder.ToStringBuilder; + +/** + * Visisbility class. + * + * @author mivek + */ +public class Visibility { + /** mainVisibility of the metar. */ + private String mainVisibility; + /** minimal visibility of the metar. */ + private int minVisibility; + /** Direction of the minimal visibility. */ + private String minDirection; + + /** + * Getter of the mainVisibility. + * + * @return the mainvisibility. + */ + public String getMainVisibility() { + return mainVisibility; + } + + /** + * Setter of the main visibility. + * + * @param mainVisibility the main visibility to set. + */ + public void setMainVisibility(final String mainVisibility) { + this.mainVisibility = mainVisibility; + } + + /** + * Getter of the minimal visibility. + * + * @return the minimal visibility. + */ + public int getMinVisibility() { + return minVisibility; + } + + /** + * Setter of the minimal visibility. + * + * @param minVisibility the minimal visibility to set. + */ + public void setMinVisibility(final int minVisibility) { + this.minVisibility = minVisibility; + } + + /** + * Getter of direction. + * + * @return the direction. + */ + public String getMinDirection() { + return minDirection; + } + + /** + * Setter of the minimal direction. + * + * @param minDirection the minimal direction to set. + */ + public void setMinDirection(final String minDirection) { + this.minDirection = minDirection; + } + + @Override + public final String toString() { + return new ToStringBuilder(this). + append(Messages.getInstance().getString("ToString.visibility.main"), mainVisibility). + append(Messages.getInstance().getString("ToString.visibility.min"), minVisibility). + append(Messages.getInstance().getString("ToString.visibility.min.direction"), minDirection).toString(); + } +} diff --git a/src/main/java/io/github/mivek/model/WeatherCondition.java b/metarParser-entities/src/main/java/io/github/mivek/model/WeatherCondition.java similarity index 71% rename from src/main/java/io/github/mivek/model/WeatherCondition.java rename to metarParser-entities/src/main/java/io/github/mivek/model/WeatherCondition.java index 2e2c8e62..1b266945 100644 --- a/src/main/java/io/github/mivek/model/WeatherCondition.java +++ b/metarParser-entities/src/main/java/io/github/mivek/model/WeatherCondition.java @@ -1,109 +1,103 @@ -package io.github.mivek.model; - -import io.github.mivek.enums.Descriptive; -import io.github.mivek.enums.Intensity; -import io.github.mivek.enums.Phenomenon; -import io.github.mivek.internationalization.Messages; -import org.apache.commons.lang3.builder.ToStringBuilder; - -import java.util.ArrayList; -import java.util.List; - -/** - * Weather condition class. - * - * @author mivek - */ -public class WeatherCondition { - /** - * Intensity of the condition (optional). - */ - private Intensity intensity; - /** - * Descriptive of the condition (optional). - */ - private Descriptive descriptive; - /** - * List of phenomenons of the condition. - */ - private List phenomenons; - - /** - * Constructor. - */ - public WeatherCondition() { - phenomenons = new ArrayList<>(); - } - - /** - * Getter of intensity. - * - * @return the Intensity of the condition. - */ - public Intensity getIntensity() { - return intensity; - } - - /** - * Setter of intensity. - * - * @param pIntensity The intensity to set. - */ - public void setIntensity(final Intensity pIntensity) { - intensity = pIntensity; - } - - /** - * Getter of the descriptive. - * - * @return the descriptive. - */ - public Descriptive getDescriptive() { - return descriptive; - } - - /** - * Setter of the descriptive. - * - * @param pDescriptive the descriptive to set. - */ - public void setDescriptive(final Descriptive pDescriptive) { - descriptive = pDescriptive; - } - - /** - * Getter of the phenomenons list. - * - * @return a list of phenomenons. - */ - public List getPhenomenons() { - return phenomenons; - } - - /** - * Adds a phenomenon to the list. - * - * @param pPhenomenon The Phenomenon to add. - */ - public void addPhenomenon(final Phenomenon pPhenomenon) { - phenomenons.add(pPhenomenon); - } - - /** - * Checks if the weather condition is valid. - * - * @return true if there is at least phenomenon. - */ - public boolean isValid() { - return !phenomenons.isEmpty() || Descriptive.THUNDERSTORM == descriptive; - } - - @Override - public final String toString() { - return new ToStringBuilder(this). - append(Messages.getInstance().getString("ToString.intensity"), intensity). - append(Messages.getInstance().getString("ToString.descriptive"), descriptive). - append(Messages.getInstance().getString("ToString.phenomenons"), phenomenons.toString()). - toString(); - } -} +package io.github.mivek.model; + +import io.github.mivek.enums.Descriptive; +import io.github.mivek.enums.Intensity; +import io.github.mivek.enums.Phenomenon; +import io.github.mivek.internationalization.Messages; +import org.apache.commons.lang3.builder.ToStringBuilder; + +import java.util.ArrayList; +import java.util.List; + +/** + * Weather condition class. + * + * @author mivek + */ +public class WeatherCondition { + /** Intensity of the condition (optional). */ + private Intensity intensity; + /** Descriptive of the condition (optional). */ + private Descriptive descriptive; + /** List of phenomenons of the condition. */ + private final List phenomenons; + + /** + * Constructor. + */ + public WeatherCondition() { + phenomenons = new ArrayList<>(); + } + + /** + * Getter of intensity. + * + * @return the Intensity of the condition. + */ + public Intensity getIntensity() { + return intensity; + } + + /** + * Setter of intensity. + * + * @param intensity The intensity to set. + */ + public void setIntensity(final Intensity intensity) { + this.intensity = intensity; + } + + /** + * Getter of the descriptive. + * + * @return the descriptive. + */ + public Descriptive getDescriptive() { + return descriptive; + } + + /** + * Setter of the descriptive. + * + * @param descriptive the descriptive to set. + */ + public void setDescriptive(final Descriptive descriptive) { + this.descriptive = descriptive; + } + + /** + * Getter of the phenomenons list. + * + * @return a list of phenomenons. + */ + public List getPhenomenons() { + return phenomenons; + } + + /** + * Adds a phenomenon to the list. + * + * @param phenomenon The Phenomenon to add. + */ + public void addPhenomenon(final Phenomenon phenomenon) { + phenomenons.add(phenomenon); + } + + /** + * Checks if the weather condition is valid. + * + * @return true if there is at least phenomenon. + */ + public boolean isValid() { + return !phenomenons.isEmpty() || Descriptive.THUNDERSTORM == descriptive; + } + + @Override + public final String toString() { + return new ToStringBuilder(this). + append(Messages.getInstance().getString("ToString.intensity"), intensity). + append(Messages.getInstance().getString("ToString.descriptive"), descriptive). + append(Messages.getInstance().getString("ToString.phenomenons"), phenomenons.toString()). + toString(); + } +} diff --git a/src/main/java/io/github/mivek/model/Wind.java b/metarParser-entities/src/main/java/io/github/mivek/model/Wind.java similarity index 63% rename from src/main/java/io/github/mivek/model/Wind.java rename to metarParser-entities/src/main/java/io/github/mivek/model/Wind.java index 53f1a955..a6aee007 100644 --- a/src/main/java/io/github/mivek/model/Wind.java +++ b/metarParser-entities/src/main/java/io/github/mivek/model/Wind.java @@ -1,152 +1,158 @@ -package io.github.mivek.model; - -import io.github.mivek.internationalization.Messages; -import org.apache.commons.lang3.builder.ToStringBuilder; - -/** - * Wind class. - * TODO Change unit to enumeration class. - * @author mivek - */ -public class Wind { - /** Speed of the wind. */ - private int speed; - /** Direction of the wind. */ - private String direction; - /** Direction of the wind. */ - private Integer directionDegrees; - /** The speed of the gust. */ - private int gust; - /** The minimal variation of the wind. */ - private int extreme1; - /** The maximum variation of the wind. */ - private int extreme2; - /** The unit of the speed. */ - private String unit; - - /** - * Getter of the speed. - * @return the speed. - */ - public int getSpeed() { - return speed; - } - - /** - * Setter of the speed. - * @param pSpeed the speed to set. - */ - public void setSpeed(final int pSpeed) { - speed = pSpeed; - } - - /** - * Getter of the direction. - * @return The Direction of the wind. - */ - public String getDirection() { - return direction; - } - - /** - * Setter of the direction of the wind. - * @param pDirection the direction to set. - */ - public void setDirection(final String pDirection) { - direction = pDirection; - } - - /** - * Getter of the gust. - * @return the gust. - */ - public int getGust() { - return gust; - } - - /** - * Setter of the gust. - * @param pGust the gust to set. - */ - public void setGust(final int pGust) { - gust = pGust; - } - - /** - * Getter of the minimal variation of the wind. - * @return the minimal variation of the wind. - */ - public int getExtreme1() { - return extreme1; - } - - /** - * Setter of extreme1. - * @param pExtreme1 the minimal wind variation to set. - */ - public void setExtreme1(final int pExtreme1) { - extreme1 = pExtreme1; - } - - /** - * Getter of the maximal wind variation. - * @return the wind variation. - */ - public int getExtreme2() { - return extreme2; - } - - /** - * Setter. - * @param pExtreme2 the wind variation to set. - */ - public void setExtreme2(final int pExtreme2) { - extreme2 = pExtreme2; - } - - /** - * Getter of the unit. - * @return the unit. - */ - public String getUnit() { - return unit; - } - - /** - * Setter. - * @param pUnit The unit to set. - */ - public void setUnit(final String pUnit) { - unit = pUnit; - } - - /** - * @return the directionDegrees. - */ - public Integer getDirectionDegrees() { - return directionDegrees; - } - - /** - * @param pDirectionDegrees the directionDegrees to set. - */ - public void setDirectionDegrees(final Integer pDirectionDegrees) { - directionDegrees = pDirectionDegrees; - } - - /** - * @return a description of the wind component. - */ - @Override - public String toString() { - return new ToStringBuilder(this). - append(Messages.getInstance().getString("ToString.wind.speed"), speed). - append(Messages.getInstance().getString("ToString.wind.unit"), unit). - append(Messages.getInstance().getString("ToString.wind.direction"), direction). - append(Messages.getInstance().getString("ToString.wind.direction.degrees"), directionDegrees). - append(Messages.getInstance().getString("ToString.wind.gusts"), gust). - append(Messages.getInstance().getString("ToString.wind.min.variation"), extreme1). - append(Messages.getInstance().getString("ToString.wind.max.variation"), extreme2). - toString(); - } -} +package io.github.mivek.model; + +import io.github.mivek.internationalization.Messages; +import org.apache.commons.lang3.builder.ToStringBuilder; + +/** + * Wind class. + * + * @author mivek + */ +public class Wind { + /** Speed of the wind. */ + private int speed; + /** Direction of the wind. */ + private String direction; + /** Direction of the wind. */ + private Integer directionDegrees; + /** The speed of the gust. */ + private int gust; + /** The minimal variation of the wind. */ + private int minVariation; + /** The maximum variation of the wind. */ + private int maxVariation; + /** The unit of the speed. */ + private String unit; + + /** + * Getter of the speed. + * + * @return the speed. + */ + public int getSpeed() { + return speed; + } + + /** + * Setter of the speed. + * + * @param speed the speed to set. + */ + public void setSpeed(final int speed) { + this.speed = speed; + } + + /** + * Getter of the direction. + * + * @return The Direction of the wind. + */ + public String getDirection() { + return direction; + } + + /** + * Setter of the direction of the wind. + * + * @param direction the direction to set. + */ + public void setDirection(final String direction) { + this.direction = direction; + } + + /** + * Getter of the gust. + * + * @return the gust. + */ + public int getGust() { + return gust; + } + + /** + * Setter of the gust. + * + * @param gust the gust to set. + */ + public void setGust(final int gust) { + this.gust = gust; + } + + /** + * Getter of the minimal variation of the wind. + * + * @return the minimal variation of the wind. + */ + public int getMinVariation() { + return minVariation; + } + + /** + * @param minVariation the minimal wind variation to set. + */ + public void setMinVariation(final int minVariation) { + this.minVariation = minVariation; + } + + /** + * @return the wind max variation. + */ + public int getMaxVariation() { + return maxVariation; + } + + /** + * @param maxVariation the wind max variation to set. + */ + public void setMaxVariation(final int maxVariation) { + this.maxVariation = maxVariation; + } + + /** + * Getter of the unit. + * + * @return the unit. + */ + public String getUnit() { + return unit; + } + + /** + * Setter. + * + * @param unit The unit to set. + */ + public void setUnit(final String unit) { + this.unit = unit; + } + + /** + * @return the directionDegrees. + */ + public Integer getDirectionDegrees() { + return directionDegrees; + } + + /** + * @param directionDegrees the directionDegrees to set. + */ + public void setDirectionDegrees(final Integer directionDegrees) { + this.directionDegrees = directionDegrees; + } + + /** + * @return a description of the wind component. + */ + @Override + public String toString() { + return new ToStringBuilder(this). + append(Messages.getInstance().getString("ToString.wind.speed"), speed). + append(Messages.getInstance().getString("ToString.wind.unit"), unit). + append(Messages.getInstance().getString("ToString.wind.direction"), direction). + append(Messages.getInstance().getString("ToString.wind.direction.degrees"), directionDegrees). + append(Messages.getInstance().getString("ToString.wind.gusts"), gust). + append(Messages.getInstance().getString("ToString.wind.min.variation"), minVariation). + append(Messages.getInstance().getString("ToString.wind.max.variation"), maxVariation). + toString(); + } +} diff --git a/src/main/java/io/github/mivek/model/WindShear.java b/metarParser-entities/src/main/java/io/github/mivek/model/WindShear.java similarity index 82% rename from src/main/java/io/github/mivek/model/WindShear.java rename to metarParser-entities/src/main/java/io/github/mivek/model/WindShear.java index a67984d3..733e9983 100644 --- a/src/main/java/io/github/mivek/model/WindShear.java +++ b/metarParser-entities/src/main/java/io/github/mivek/model/WindShear.java @@ -1,35 +1,36 @@ -package io.github.mivek.model; - -import io.github.mivek.internationalization.Messages; -import org.apache.commons.lang3.builder.ToStringBuilder; - -/** - * Class representing the wind shear. - * @author mivek - */ -public class WindShear extends Wind { - /** The height of the wind shear in feet. */ - private int height; - - /** - * @return the height - */ - public int getHeight() { - return height; - } - - /** - * @param pHeight the height to set - */ - public void setHeight(final int pHeight) { - height = pHeight; - } - - @Override - public final String toString() { - return new ToStringBuilder(this). - appendSuper(super.toString()). - append(Messages.getInstance().getString("ToString.height.feet"), height). - toString(); - } -} +package io.github.mivek.model; + +import io.github.mivek.internationalization.Messages; +import org.apache.commons.lang3.builder.ToStringBuilder; + +/** + * Class representing the wind shear. + * + * @author mivek + */ +public class WindShear extends Wind { + /** The height of the wind shear in feet. */ + private int height; + + /** + * @return the height + */ + public int getHeight() { + return height; + } + + /** + * @param height the height to set + */ + public void setHeight(final int height) { + this.height = height; + } + + @Override + public final String toString() { + return new ToStringBuilder(this). + appendSuper(super.toString()). + append(Messages.getInstance().getString("ToString.height.feet"), height). + toString(); + } +} diff --git a/src/main/java/io/github/mivek/model/package-info.java b/metarParser-entities/src/main/java/io/github/mivek/model/package-info.java similarity index 95% rename from src/main/java/io/github/mivek/model/package-info.java rename to metarParser-entities/src/main/java/io/github/mivek/model/package-info.java index 67edd26a..f432e84a 100644 --- a/src/main/java/io/github/mivek/model/package-info.java +++ b/metarParser-entities/src/main/java/io/github/mivek/model/package-info.java @@ -1,5 +1,6 @@ -/** - * This package contains model classes of the project. - * @author mivek. - */ -package io.github.mivek.model; +/** + * This package contains model classes of the project. + * + * @author mivek. + */ +package io.github.mivek.model; diff --git a/src/main/java/io/github/mivek/model/trend/AbstractMetarTrend.java b/metarParser-entities/src/main/java/io/github/mivek/model/trend/AbstractMetarTrend.java similarity index 69% rename from src/main/java/io/github/mivek/model/trend/AbstractMetarTrend.java rename to metarParser-entities/src/main/java/io/github/mivek/model/trend/AbstractMetarTrend.java index d10e50e7..0bf326cb 100644 --- a/src/main/java/io/github/mivek/model/trend/AbstractMetarTrend.java +++ b/metarParser-entities/src/main/java/io/github/mivek/model/trend/AbstractMetarTrend.java @@ -1,51 +1,55 @@ -package io.github.mivek.model.trend; - -import io.github.mivek.enums.WeatherChangeType; -import io.github.mivek.model.trend.validity.AbstractMetarTrendTime; -import org.apache.commons.lang3.builder.ToStringBuilder; - -import java.util.ArrayList; -import java.util.List; - -/** - * Abstract class for metar's trend. - * @author mivek - */ -public abstract class AbstractMetarTrend extends AbstractTrend { - /** - * List containing the times properties of the trend. - */ - private List times; - - /** - * Constructor. - * @param pType the WeatherChangeType to set. - */ - protected AbstractMetarTrend(final WeatherChangeType pType) { - super(pType); - times = new ArrayList<>(); - } - - /** - * @return the times - */ - public List getTimes() { - return times; - } - - /** - * Adds a AbstractMetarTrendTime to the list. - * @param pTime the element to add. - */ - public void addTime(final AbstractMetarTrendTime pTime) { - times.add(pTime); - } - - /** - * @return a description of the object. - */ - @Override public String toString() { - return new ToStringBuilder(this).appendSuper(super.toString()).append(times.toString()).toString(); - } - -} +package io.github.mivek.model.trend; + +import io.github.mivek.enums.WeatherChangeType; +import io.github.mivek.model.trend.validity.AbstractMetarTrendTime; +import org.apache.commons.lang3.builder.ToStringBuilder; + +import java.util.ArrayList; +import java.util.List; + +/** + * Abstract class for metar's trend. + * + * @author mivek + */ +public abstract class AbstractMetarTrend extends AbstractTrend { + /** + * List containing the times properties of the trend. + */ + private final List times; + + /** + * Constructor. + * + * @param type the WeatherChangeType to set. + */ + protected AbstractMetarTrend(final WeatherChangeType type) { + super(type); + times = new ArrayList<>(); + } + + /** + * @return the times + */ + public List getTimes() { + return times; + } + + /** + * Adds a AbstractMetarTrendTime to the list. + * + * @param time the element to add. + */ + public void addTime(final AbstractMetarTrendTime time) { + times.add(time); + } + + /** + * @return a description of the object. + */ + @Override + public String toString() { + return new ToStringBuilder(this).appendSuper(super.toString()).append(times.toString()).toString(); + } + +} diff --git a/src/main/java/io/github/mivek/model/trend/AbstractTafProbTrend.java b/metarParser-entities/src/main/java/io/github/mivek/model/trend/AbstractTafProbTrend.java similarity index 80% rename from src/main/java/io/github/mivek/model/trend/AbstractTafProbTrend.java rename to metarParser-entities/src/main/java/io/github/mivek/model/trend/AbstractTafProbTrend.java index df786f4e..f9b67f9c 100644 --- a/src/main/java/io/github/mivek/model/trend/AbstractTafProbTrend.java +++ b/metarParser-entities/src/main/java/io/github/mivek/model/trend/AbstractTafProbTrend.java @@ -19,13 +19,12 @@ public abstract class AbstractTafProbTrend extends A /** * Constructor with parameter. * - * @param pType the type to set. + * @param type the type to set. */ - protected AbstractTafProbTrend(final WeatherChangeType pType) { - super(pType); + protected AbstractTafProbTrend(final WeatherChangeType type) { + super(type); } - /** * @return the probability */ @@ -34,10 +33,10 @@ public Integer getProbability() { } /** - * @param pProbability the probability to set + * @param probability the probability to set */ - public void setProbability(final Integer pProbability) { - probability = pProbability; + public void setProbability(final Integer probability) { + this.probability = probability; } /** @@ -50,4 +49,4 @@ public String toString() { append(Messages.getInstance().getString("ToString.probability"), probability). toString(); } -} \ No newline at end of file +} diff --git a/src/main/java/io/github/mivek/model/trend/AbstractTafTrend.java b/metarParser-entities/src/main/java/io/github/mivek/model/trend/AbstractTafTrend.java similarity index 73% rename from src/main/java/io/github/mivek/model/trend/AbstractTafTrend.java rename to metarParser-entities/src/main/java/io/github/mivek/model/trend/AbstractTafTrend.java index c246fb50..904af244 100644 --- a/src/main/java/io/github/mivek/model/trend/AbstractTafTrend.java +++ b/metarParser-entities/src/main/java/io/github/mivek/model/trend/AbstractTafTrend.java @@ -1,48 +1,50 @@ -package io.github.mivek.model.trend; - -import io.github.mivek.enums.WeatherChangeType; -import io.github.mivek.model.trend.validity.AbstractValidity; -import org.apache.commons.lang3.builder.ToStringBuilder; - -/** - * Class representing a weather change. - * @param a concrete subclass of {@link AbstractValidity} - * @author mivek - */ -public abstract class AbstractTafTrend extends AbstractTrend { - /** The validity of the change. */ - private T validity; - - /** - * Constructor with parameter. - * @param pType the type to set. - */ - protected AbstractTafTrend(final WeatherChangeType pType) { - super(pType); - } - - /** - * @return the validity - */ - public T getValidity() { - return validity; - } - - /** - * @param pValidity the validity to set - */ - public void setValidity(final T pValidity) { - validity = pValidity; - } - - - /** - * @return A description of the object. - */ - @Override public String toString() { - return new ToStringBuilder(this). - appendSuper(super.toString()). - appendToString(validity.toString()). - toString(); - } -} +package io.github.mivek.model.trend; + +import io.github.mivek.enums.WeatherChangeType; +import io.github.mivek.model.trend.validity.AbstractValidity; +import org.apache.commons.lang3.builder.ToStringBuilder; + +/** + * Class representing a weather change. + * + * @param a concrete subclass of {@link AbstractValidity} + * @author mivek + */ +public abstract class AbstractTafTrend extends AbstractTrend { + /** The validity of the change. */ + private T validity; + + /** + * Constructor with parameter. + * + * @param type the type to set. + */ + protected AbstractTafTrend(final WeatherChangeType type) { + super(type); + } + + /** + * @return the validity + */ + public T getValidity() { + return validity; + } + + /** + * @param validity the validity to set + */ + public void setValidity(final T validity) { + this.validity = validity; + } + + /** + * @return A description of the object. + */ + @Override + public String toString() { + return new ToStringBuilder(this). + appendSuper(super.toString()). + appendToString(validity.toString()). + toString(); + } +} diff --git a/src/main/java/io/github/mivek/model/trend/AbstractTrend.java b/metarParser-entities/src/main/java/io/github/mivek/model/trend/AbstractTrend.java similarity index 74% rename from src/main/java/io/github/mivek/model/trend/AbstractTrend.java rename to metarParser-entities/src/main/java/io/github/mivek/model/trend/AbstractTrend.java index 3958bdb0..afdc5107 100644 --- a/src/main/java/io/github/mivek/model/trend/AbstractTrend.java +++ b/metarParser-entities/src/main/java/io/github/mivek/model/trend/AbstractTrend.java @@ -1,36 +1,39 @@ -package io.github.mivek.model.trend; - -import io.github.mivek.enums.WeatherChangeType; -import io.github.mivek.model.AbstractWeatherContainer; -import org.apache.commons.lang3.builder.ToStringBuilder; - -/** - * Abstract class for trends. - * @author mivek - */ -public abstract class AbstractTrend extends AbstractWeatherContainer { - /** Type of trend. */ - private WeatherChangeType type; - - /** - * Constructor. - * @param pType the type of the trend. - */ - protected AbstractTrend(final WeatherChangeType pType) { - type = pType; - } - - /** - * @return the type - */ - public final WeatherChangeType getType() { - return type; - } - - /** - * @return a description of the object - */ - @Override public String toString() { - return new ToStringBuilder(this).appendToString(type.toString()).appendSuper(super.toString()).toString(); - } -} +package io.github.mivek.model.trend; + +import io.github.mivek.enums.WeatherChangeType; +import io.github.mivek.model.AbstractWeatherContainer; +import org.apache.commons.lang3.builder.ToStringBuilder; + +/** + * Abstract class for trends. + * + * @author mivek + */ +public abstract class AbstractTrend extends AbstractWeatherContainer { + /** Type of trend. */ + private final WeatherChangeType type; + + /** + * Constructor. + * + * @param type the type of the trend. + */ + protected AbstractTrend(final WeatherChangeType type) { + this.type = type; + } + + /** + * @return the type + */ + public final WeatherChangeType getType() { + return type; + } + + /** + * @return a description of the object + */ + @Override + public String toString() { + return new ToStringBuilder(this).appendToString(type.toString()).appendSuper(super.toString()).toString(); + } +} diff --git a/src/main/java/io/github/mivek/model/trend/BECMGMetarTrend.java b/metarParser-entities/src/main/java/io/github/mivek/model/trend/BECMGMetarTrend.java similarity index 94% rename from src/main/java/io/github/mivek/model/trend/BECMGMetarTrend.java rename to metarParser-entities/src/main/java/io/github/mivek/model/trend/BECMGMetarTrend.java index 352bfa93..53041372 100644 --- a/src/main/java/io/github/mivek/model/trend/BECMGMetarTrend.java +++ b/metarParser-entities/src/main/java/io/github/mivek/model/trend/BECMGMetarTrend.java @@ -1,18 +1,19 @@ -package io.github.mivek.model.trend; - -import io.github.mivek.enums.WeatherChangeType; - -/** - * BECMG class for metar. - * @author mivek - */ -public final class BECMGMetarTrend extends AbstractMetarTrend { - - /** - * Constructor. - */ - public BECMGMetarTrend() { - super(WeatherChangeType.BECMG); - } - -} +package io.github.mivek.model.trend; + +import io.github.mivek.enums.WeatherChangeType; + +/** + * BECMG class for metar. + * + * @author mivek + */ +public final class BECMGMetarTrend extends AbstractMetarTrend { + + /** + * Constructor. + */ + public BECMGMetarTrend() { + super(WeatherChangeType.BECMG); + } + +} diff --git a/src/main/java/io/github/mivek/model/trend/BECMGTafTrend.java b/metarParser-entities/src/main/java/io/github/mivek/model/trend/BECMGTafTrend.java similarity index 95% rename from src/main/java/io/github/mivek/model/trend/BECMGTafTrend.java rename to metarParser-entities/src/main/java/io/github/mivek/model/trend/BECMGTafTrend.java index 2cc41b37..b4b07cef 100644 --- a/src/main/java/io/github/mivek/model/trend/BECMGTafTrend.java +++ b/metarParser-entities/src/main/java/io/github/mivek/model/trend/BECMGTafTrend.java @@ -1,19 +1,20 @@ -package io.github.mivek.model.trend; - -import io.github.mivek.enums.WeatherChangeType; -import io.github.mivek.model.trend.validity.Validity; - -/** - * Class representing a BECMG change of a TAF. - * @author mivek - */ -public class BECMGTafTrend extends AbstractTafTrend { - - /** - * Constructor. - */ - public BECMGTafTrend() { - super(WeatherChangeType.BECMG); - } - -} +package io.github.mivek.model.trend; + +import io.github.mivek.enums.WeatherChangeType; +import io.github.mivek.model.trend.validity.Validity; + +/** + * Class representing a BECMG change of a TAF. + * + * @author mivek + */ +public class BECMGTafTrend extends AbstractTafTrend { + + /** + * Constructor. + */ + public BECMGTafTrend() { + super(WeatherChangeType.BECMG); + } + +} diff --git a/src/main/java/io/github/mivek/model/trend/FMTafTrend.java b/metarParser-entities/src/main/java/io/github/mivek/model/trend/FMTafTrend.java similarity index 95% rename from src/main/java/io/github/mivek/model/trend/FMTafTrend.java rename to metarParser-entities/src/main/java/io/github/mivek/model/trend/FMTafTrend.java index d5db8209..96fcf34a 100644 --- a/src/main/java/io/github/mivek/model/trend/FMTafTrend.java +++ b/metarParser-entities/src/main/java/io/github/mivek/model/trend/FMTafTrend.java @@ -1,19 +1,20 @@ -package io.github.mivek.model.trend; - -import io.github.mivek.enums.WeatherChangeType; -import io.github.mivek.model.trend.validity.BeginningValidity; - -/** - * Class representing From Changes. - * @author mivek - */ -public class FMTafTrend extends AbstractTafTrend { - - /** - * Constructor. - */ - public FMTafTrend() { - super(WeatherChangeType.FM); - } - -} +package io.github.mivek.model.trend; + +import io.github.mivek.enums.WeatherChangeType; +import io.github.mivek.model.trend.validity.BeginningValidity; + +/** + * Class representing From Changes. + * + * @author mivek + */ +public class FMTafTrend extends AbstractTafTrend { + + /** + * Constructor. + */ + public FMTafTrend() { + super(WeatherChangeType.FM); + } + +} diff --git a/src/main/java/io/github/mivek/model/trend/PROBTafTrend.java b/metarParser-entities/src/main/java/io/github/mivek/model/trend/PROBTafTrend.java similarity index 95% rename from src/main/java/io/github/mivek/model/trend/PROBTafTrend.java rename to metarParser-entities/src/main/java/io/github/mivek/model/trend/PROBTafTrend.java index 943f66fe..db81834b 100644 --- a/src/main/java/io/github/mivek/model/trend/PROBTafTrend.java +++ b/metarParser-entities/src/main/java/io/github/mivek/model/trend/PROBTafTrend.java @@ -1,18 +1,18 @@ -package io.github.mivek.model.trend; - -import io.github.mivek.enums.WeatherChangeType; -import io.github.mivek.model.trend.validity.Validity; - -/** - * @author mivek - */ -public class PROBTafTrend extends AbstractTafProbTrend { - - /** - * Constructor. - */ - public PROBTafTrend() { - super(WeatherChangeType.PROB); - } - -} +package io.github.mivek.model.trend; + +import io.github.mivek.enums.WeatherChangeType; +import io.github.mivek.model.trend.validity.Validity; + +/** + * @author mivek + */ +public class PROBTafTrend extends AbstractTafProbTrend { + + /** + * Constructor. + */ + public PROBTafTrend() { + super(WeatherChangeType.PROB); + } + +} diff --git a/src/main/java/io/github/mivek/model/trend/TEMPOMetarTrend.java b/metarParser-entities/src/main/java/io/github/mivek/model/trend/TEMPOMetarTrend.java similarity index 94% rename from src/main/java/io/github/mivek/model/trend/TEMPOMetarTrend.java rename to metarParser-entities/src/main/java/io/github/mivek/model/trend/TEMPOMetarTrend.java index b44bef81..870a7f1d 100644 --- a/src/main/java/io/github/mivek/model/trend/TEMPOMetarTrend.java +++ b/metarParser-entities/src/main/java/io/github/mivek/model/trend/TEMPOMetarTrend.java @@ -1,18 +1,19 @@ -package io.github.mivek.model.trend; - -import io.github.mivek.enums.WeatherChangeType; - -/** - * TEMPO class for metar trend. - * @author mivek - */ -public final class TEMPOMetarTrend extends AbstractMetarTrend { - - /** - * Constructor. - */ - public TEMPOMetarTrend() { - super(WeatherChangeType.TEMPO); - } - -} +package io.github.mivek.model.trend; + +import io.github.mivek.enums.WeatherChangeType; + +/** + * TEMPO class for metar trend. + * + * @author mivek + */ +public final class TEMPOMetarTrend extends AbstractMetarTrend { + + /** + * Constructor. + */ + public TEMPOMetarTrend() { + super(WeatherChangeType.TEMPO); + } + +} diff --git a/src/main/java/io/github/mivek/model/trend/TEMPOTafTrend.java b/metarParser-entities/src/main/java/io/github/mivek/model/trend/TEMPOTafTrend.java similarity index 95% rename from src/main/java/io/github/mivek/model/trend/TEMPOTafTrend.java rename to metarParser-entities/src/main/java/io/github/mivek/model/trend/TEMPOTafTrend.java index 891146e8..5d10051c 100644 --- a/src/main/java/io/github/mivek/model/trend/TEMPOTafTrend.java +++ b/metarParser-entities/src/main/java/io/github/mivek/model/trend/TEMPOTafTrend.java @@ -1,18 +1,19 @@ -package io.github.mivek.model.trend; - -import io.github.mivek.enums.WeatherChangeType; -import io.github.mivek.model.trend.validity.Validity; - -/** - * Class representing a Tempo change in a taf message. - * @author mivek - */ -public final class TEMPOTafTrend extends AbstractTafProbTrend { - /** - * Default constructor. - */ - public TEMPOTafTrend() { - super(WeatherChangeType.TEMPO); - } - -} +package io.github.mivek.model.trend; + +import io.github.mivek.enums.WeatherChangeType; +import io.github.mivek.model.trend.validity.Validity; + +/** + * Class representing a Tempo change in a taf message. + * + * @author mivek + */ +public final class TEMPOTafTrend extends AbstractTafProbTrend { + /** + * Default constructor. + */ + public TEMPOTafTrend() { + super(WeatherChangeType.TEMPO); + } + +} diff --git a/src/main/java/io/github/mivek/model/trend/package-info.java b/metarParser-entities/src/main/java/io/github/mivek/model/trend/package-info.java similarity index 96% rename from src/main/java/io/github/mivek/model/trend/package-info.java rename to metarParser-entities/src/main/java/io/github/mivek/model/trend/package-info.java index db3befee..db3db383 100644 --- a/src/main/java/io/github/mivek/model/trend/package-info.java +++ b/metarParser-entities/src/main/java/io/github/mivek/model/trend/package-info.java @@ -1,5 +1,6 @@ -/** - * This package contains classes related to metar and taf trends. - * @author mivek - */ -package io.github.mivek.model.trend; +/** + * This package contains classes related to metar and taf trends. + * + * @author mivek + */ +package io.github.mivek.model.trend; diff --git a/src/main/java/io/github/mivek/model/trend/validity/ATTime.java b/metarParser-entities/src/main/java/io/github/mivek/model/trend/validity/ATTime.java similarity index 94% rename from src/main/java/io/github/mivek/model/trend/validity/ATTime.java rename to metarParser-entities/src/main/java/io/github/mivek/model/trend/validity/ATTime.java index 52569095..82599bc4 100644 --- a/src/main/java/io/github/mivek/model/trend/validity/ATTime.java +++ b/metarParser-entities/src/main/java/io/github/mivek/model/trend/validity/ATTime.java @@ -1,18 +1,19 @@ -package io.github.mivek.model.trend.validity; - -import io.github.mivek.enums.TimeIndicator; - -/** - * This class represents the AT part of the trend in a metar. - * @author mivek - */ -public class ATTime extends AbstractMetarTrendTime { - - /** - * Constructor. - */ - public ATTime() { - super(TimeIndicator.AT); - } - -} +package io.github.mivek.model.trend.validity; + +import io.github.mivek.enums.TimeIndicator; + +/** + * This class represents the AT part of the trend in a metar. + * + * @author mivek + */ +public class ATTime extends AbstractMetarTrendTime { + + /** + * Constructor. + */ + public ATTime() { + super(TimeIndicator.AT); + } + +} diff --git a/src/main/java/io/github/mivek/model/trend/validity/AbstractMetarTrendTime.java b/metarParser-entities/src/main/java/io/github/mivek/model/trend/validity/AbstractMetarTrendTime.java similarity index 69% rename from src/main/java/io/github/mivek/model/trend/validity/AbstractMetarTrendTime.java rename to metarParser-entities/src/main/java/io/github/mivek/model/trend/validity/AbstractMetarTrendTime.java index 02e7e8c8..a657c451 100644 --- a/src/main/java/io/github/mivek/model/trend/validity/AbstractMetarTrendTime.java +++ b/metarParser-entities/src/main/java/io/github/mivek/model/trend/validity/AbstractMetarTrendTime.java @@ -1,55 +1,57 @@ -package io.github.mivek.model.trend.validity; - -import io.github.mivek.enums.TimeIndicator; -import org.apache.commons.lang3.Validate; - -import java.time.LocalTime; - -/** - * Abstract class for the time trend in a metar. - * @author mivek - */ -public abstract class AbstractMetarTrendTime { - /** - * Type of trend AT, FM or TL. - */ - private TimeIndicator type; - /** - * Time of the change. - */ - private LocalTime time; - - /** - * Constructor. - * @param pType the type of trend. - */ - protected AbstractMetarTrendTime(final TimeIndicator pType) { - this.type = pType; - } - - /** - * @return the time - */ - public LocalTime getTime() { - return time; - } - - /** - * @param pTime the time to set - */ - public void setTime(final LocalTime pTime) { - time = Validate.notNull(pTime); - } - - /** - * @return the type - */ - public TimeIndicator getType() { - return type; - } - - @Override - public final String toString() { - return type + " " + time; - } -} +package io.github.mivek.model.trend.validity; + +import io.github.mivek.enums.TimeIndicator; +import org.apache.commons.lang3.Validate; + +import java.time.LocalTime; + +/** + * Abstract class for the time trend in a metar. + * + * @author mivek + */ +public abstract class AbstractMetarTrendTime { + /** + * Type of trend AT, FM or TL. + */ + private final TimeIndicator type; + /** + * Time of the change. + */ + private LocalTime time; + + /** + * Constructor. + * + * @param type the type of trend. + */ + protected AbstractMetarTrendTime(final TimeIndicator type) { + this.type = type; + } + + /** + * @return the time + */ + public LocalTime getTime() { + return time; + } + + /** + * @param time the time to set + */ + public void setTime(final LocalTime time) { + this.time = Validate.notNull(time); + } + + /** + * @return the type + */ + public TimeIndicator getType() { + return type; + } + + @Override + public final String toString() { + return type + " " + time; + } +} diff --git a/src/main/java/io/github/mivek/model/trend/validity/AbstractValidity.java b/metarParser-entities/src/main/java/io/github/mivek/model/trend/validity/AbstractValidity.java similarity index 78% rename from src/main/java/io/github/mivek/model/trend/validity/AbstractValidity.java rename to metarParser-entities/src/main/java/io/github/mivek/model/trend/validity/AbstractValidity.java index ab20dee7..391b0b98 100644 --- a/src/main/java/io/github/mivek/model/trend/validity/AbstractValidity.java +++ b/metarParser-entities/src/main/java/io/github/mivek/model/trend/validity/AbstractValidity.java @@ -1,51 +1,52 @@ -package io.github.mivek.model.trend.validity; - -import io.github.mivek.internationalization.Messages; -import org.apache.commons.lang3.builder.ToStringBuilder; - -/** - * Abstract class for the validity of a TAF. - * @author mivek - */ -public abstract class AbstractValidity implements IValidity { - /** - * Beginning day of the taf's validity. - */ - private Integer startDay; - /** - * Beginning hour of the taf's validity. - */ - private Integer startHour; - - - @Override - public final Integer getStartDay() { - return startDay; - } - - @Override - public final void setStartDay(final Integer pStartDay) { - startDay = pStartDay; - } - - @Override - public final Integer getStartHour() { - return startHour; - } - - @Override - public final void setStartHour(final Integer pStartHour) { - startHour = pStartHour; - } - - /** - * @return a string describing the object. - */ - @Override public String toString() { - return new ToStringBuilder(this). - append(Messages.getInstance().getString("ToString.start.day.month"), startDay). - append(Messages.getInstance().getString("ToString.start.hour.day"), startHour). - toString(); - } - -} +package io.github.mivek.model.trend.validity; + +import io.github.mivek.internationalization.Messages; +import org.apache.commons.lang3.builder.ToStringBuilder; + +/** + * Abstract class for the validity of a TAF. + * + * @author mivek + */ +public abstract class AbstractValidity implements IValidity { + /** + * Beginning day of the taf's validity. + */ + private Integer startDay; + /** + * Beginning hour of the taf's validity. + */ + private Integer startHour; + + @Override + public final Integer getStartDay() { + return startDay; + } + + @Override + public final void setStartDay(final Integer startDay) { + this.startDay = startDay; + } + + @Override + public final Integer getStartHour() { + return startHour; + } + + @Override + public final void setStartHour(final Integer startHour) { + this.startHour = startHour; + } + + /** + * @return a string describing the object. + */ + @Override + public String toString() { + return new ToStringBuilder(this). + append(Messages.getInstance().getString("ToString.start.day.month"), startDay). + append(Messages.getInstance().getString("ToString.start.hour.day"), startHour). + toString(); + } + +} diff --git a/src/main/java/io/github/mivek/model/trend/validity/BeginningValidity.java b/metarParser-entities/src/main/java/io/github/mivek/model/trend/validity/BeginningValidity.java similarity index 80% rename from src/main/java/io/github/mivek/model/trend/validity/BeginningValidity.java rename to metarParser-entities/src/main/java/io/github/mivek/model/trend/validity/BeginningValidity.java index 0595388c..30a6fbd4 100644 --- a/src/main/java/io/github/mivek/model/trend/validity/BeginningValidity.java +++ b/metarParser-entities/src/main/java/io/github/mivek/model/trend/validity/BeginningValidity.java @@ -1,35 +1,36 @@ -package io.github.mivek.model.trend.validity; - -import io.github.mivek.internationalization.Messages; -import org.apache.commons.lang3.builder.ToStringBuilder; - -/** - * Class representing a validity with start day, start hour and start minutes. - * @author mivek - */ -public class BeginningValidity extends AbstractValidity { - /** the minutes. */ - private Integer startMinutes; - - /** - * @return the startMinutes - */ - public Integer getStartMinutes() { - return startMinutes; - } - - /** - * @param pStartMinutes the startMinutes to set - */ - public void setStartMinutes(final Integer pStartMinutes) { - startMinutes = pStartMinutes; - } - - @Override - public final String toString() { - return new ToStringBuilder(this). - appendSuper(super.toString()). - append(Messages.getInstance().getString("ToString.start.minute"), startMinutes). - toString(); - } -} +package io.github.mivek.model.trend.validity; + +import io.github.mivek.internationalization.Messages; +import org.apache.commons.lang3.builder.ToStringBuilder; + +/** + * Class representing a validity with start day, start hour and start minutes. + * + * @author mivek + */ +public class BeginningValidity extends AbstractValidity { + /** the minutes. */ + private Integer startMinutes; + + /** + * @return the startMinutes + */ + public Integer getStartMinutes() { + return startMinutes; + } + + /** + * @param startMinutes the startMinutes to set + */ + public void setStartMinutes(final Integer startMinutes) { + this.startMinutes = startMinutes; + } + + @Override + public final String toString() { + return new ToStringBuilder(this). + appendSuper(super.toString()). + append(Messages.getInstance().getString("ToString.start.minute"), startMinutes). + toString(); + } +} diff --git a/src/main/java/io/github/mivek/model/trend/validity/FMTime.java b/metarParser-entities/src/main/java/io/github/mivek/model/trend/validity/FMTime.java similarity index 94% rename from src/main/java/io/github/mivek/model/trend/validity/FMTime.java rename to metarParser-entities/src/main/java/io/github/mivek/model/trend/validity/FMTime.java index 71085365..d1c14862 100644 --- a/src/main/java/io/github/mivek/model/trend/validity/FMTime.java +++ b/metarParser-entities/src/main/java/io/github/mivek/model/trend/validity/FMTime.java @@ -1,18 +1,19 @@ -package io.github.mivek.model.trend.validity; - -import io.github.mivek.enums.TimeIndicator; - -/** - * This class represents the FM part of a trend in a metar. - * @author mivek - */ -public class FMTime extends AbstractMetarTrendTime { - - /** - * Constructor. - */ - public FMTime() { - super(TimeIndicator.FM); - } - -} +package io.github.mivek.model.trend.validity; + +import io.github.mivek.enums.TimeIndicator; + +/** + * This class represents the FM part of a trend in a metar. + * + * @author mivek + */ +public class FMTime extends AbstractMetarTrendTime { + + /** + * Constructor. + */ + public FMTime() { + super(TimeIndicator.FM); + } + +} diff --git a/src/main/java/io/github/mivek/model/trend/validity/IValidity.java b/metarParser-entities/src/main/java/io/github/mivek/model/trend/validity/IValidity.java similarity index 61% rename from src/main/java/io/github/mivek/model/trend/validity/IValidity.java rename to metarParser-entities/src/main/java/io/github/mivek/model/trend/validity/IValidity.java index ef1f9ce6..2062732a 100644 --- a/src/main/java/io/github/mivek/model/trend/validity/IValidity.java +++ b/metarParser-entities/src/main/java/io/github/mivek/model/trend/validity/IValidity.java @@ -1,29 +1,30 @@ -package io.github.mivek.model.trend.validity; - -/** - * Interface for validity objects. - * @author mivek - */ -public interface IValidity { - - /** - * @return the startDay - */ - - Integer getStartDay(); - - /** - * @param pStartDay the startDay to set - */ - void setStartDay(Integer pStartDay); - - /** - * @return the startHour - */ - Integer getStartHour(); - - /** - * @param pStartHour the startHour to set - */ - void setStartHour(Integer pStartHour); -} +package io.github.mivek.model.trend.validity; + +/** + * Interface for validity objects. + * + * @author mivek + */ +public interface IValidity { + + /** + * @return the startDay + */ + + Integer getStartDay(); + + /** + * @param startDay the startDay to set + */ + void setStartDay(Integer startDay); + + /** + * @return the startHour + */ + Integer getStartHour(); + + /** + * @param startHour the startHour to set + */ + void setStartHour(Integer startHour); +} diff --git a/src/main/java/io/github/mivek/model/trend/validity/TLTime.java b/metarParser-entities/src/main/java/io/github/mivek/model/trend/validity/TLTime.java similarity index 95% rename from src/main/java/io/github/mivek/model/trend/validity/TLTime.java rename to metarParser-entities/src/main/java/io/github/mivek/model/trend/validity/TLTime.java index ed2e85b5..637a6ec0 100644 --- a/src/main/java/io/github/mivek/model/trend/validity/TLTime.java +++ b/metarParser-entities/src/main/java/io/github/mivek/model/trend/validity/TLTime.java @@ -1,18 +1,19 @@ -package io.github.mivek.model.trend.validity; - -import io.github.mivek.enums.TimeIndicator; - -/** - * This class represents the TL part of the trend part of a metar. - * @author mivek - */ -public final class TLTime extends AbstractMetarTrendTime { - - /** - * Constructor. - */ - public TLTime() { - super(TimeIndicator.TL); - } - -} +package io.github.mivek.model.trend.validity; + +import io.github.mivek.enums.TimeIndicator; + +/** + * This class represents the TL part of the trend part of a metar. + * + * @author mivek + */ +public final class TLTime extends AbstractMetarTrendTime { + + /** + * Constructor. + */ + public TLTime() { + super(TimeIndicator.TL); + } + +} diff --git a/src/main/java/io/github/mivek/model/trend/validity/Validity.java b/metarParser-entities/src/main/java/io/github/mivek/model/trend/validity/Validity.java similarity index 78% rename from src/main/java/io/github/mivek/model/trend/validity/Validity.java rename to metarParser-entities/src/main/java/io/github/mivek/model/trend/validity/Validity.java index 99507074..567059c7 100644 --- a/src/main/java/io/github/mivek/model/trend/validity/Validity.java +++ b/metarParser-entities/src/main/java/io/github/mivek/model/trend/validity/Validity.java @@ -1,57 +1,58 @@ -package io.github.mivek.model.trend.validity; - -import io.github.mivek.internationalization.Messages; -import org.apache.commons.lang3.builder.ToStringBuilder; - -/** - * Class representing the validity of a TAF message. - * @author mivek - */ -public final class Validity extends AbstractValidity { - - /** - * Ending day of the taf's validity. - */ - private Integer endDay; - /** - * Ending hour of the taf's validity. - */ - private Integer endHour; - - /** - * @return the endDay - */ - public Integer getEndDay() { - return endDay; - } - - /** - * @param pEndDay the endDay to set - */ - public void setEndDay(final Integer pEndDay) { - endDay = pEndDay; - } - - /** - * @return the endHour - */ - public Integer getEndHour() { - return endHour; - } - - /** - * @param pEndHour the endHour to set - */ - public void setEndHour(final Integer pEndHour) { - endHour = pEndHour; - } - - @Override - public String toString() { - return new ToStringBuilder(this). - appendSuper(super.toString()). - append(Messages.getInstance().getString("ToString.end.day.month"), endDay). - append(Messages.getInstance().getString("ToString.end.hour.day"), endHour). - toString(); - } -} +package io.github.mivek.model.trend.validity; + +import io.github.mivek.internationalization.Messages; +import org.apache.commons.lang3.builder.ToStringBuilder; + +/** + * Class representing the validity of a TAF message. + * + * @author mivek + */ +public final class Validity extends AbstractValidity { + + /** + * Ending day of the taf's validity. + */ + private Integer endDay; + /** + * Ending hour of the taf's validity. + */ + private Integer endHour; + + /** + * @return the endDay + */ + public Integer getEndDay() { + return endDay; + } + + /** + * @param endDay the endDay to set + */ + public void setEndDay(final Integer endDay) { + this.endDay = endDay; + } + + /** + * @return the endHour + */ + public Integer getEndHour() { + return endHour; + } + + /** + * @param endHour the endHour to set + */ + public void setEndHour(final Integer endHour) { + this.endHour = endHour; + } + + @Override + public String toString() { + return new ToStringBuilder(this). + appendSuper(super.toString()). + append(Messages.getInstance().getString("ToString.end.day.month"), endDay). + append(Messages.getInstance().getString("ToString.end.hour.day"), endHour). + toString(); + } +} diff --git a/src/main/java/io/github/mivek/model/trend/validity/package-info.java b/metarParser-entities/src/main/java/io/github/mivek/model/trend/validity/package-info.java similarity index 95% rename from src/main/java/io/github/mivek/model/trend/validity/package-info.java rename to metarParser-entities/src/main/java/io/github/mivek/model/trend/validity/package-info.java index 0939e70b..52e6efaa 100644 --- a/src/main/java/io/github/mivek/model/trend/validity/package-info.java +++ b/metarParser-entities/src/main/java/io/github/mivek/model/trend/validity/package-info.java @@ -1,5 +1,6 @@ -/** - * This package contains validity classes. - * @author mivek - */ -package io.github.mivek.model.trend.validity; +/** + * This package contains validity classes. + * + * @author mivek + */ +package io.github.mivek.model.trend.validity; diff --git a/src/test/java/io/github/mivek/enums/IntensityTest.java b/metarParser-entities/src/test/java/io/github/mivek/enums/IntensityTest.java similarity index 95% rename from src/test/java/io/github/mivek/enums/IntensityTest.java rename to metarParser-entities/src/test/java/io/github/mivek/enums/IntensityTest.java index f6366a1b..a660e933 100644 --- a/src/test/java/io/github/mivek/enums/IntensityTest.java +++ b/metarParser-entities/src/test/java/io/github/mivek/enums/IntensityTest.java @@ -1,11 +1,11 @@ -package io.github.mivek.enums; - -import org.junit.Test; - -public class IntensityTest { - - @Test(expected = IllegalArgumentException.class) - public void testGetEnum() { - Intensity.getEnum("QWERTY"); - } -} +package io.github.mivek.enums; + +import org.junit.Test; + +public class IntensityTest { + + @Test(expected = IllegalArgumentException.class) + public void testGetEnum() { + Intensity.getEnum("QWERTY"); + } +} diff --git a/metarParser-entities/src/test/java/io/github/mivek/model/AbstractWeatherContainerTest.java b/metarParser-entities/src/test/java/io/github/mivek/model/AbstractWeatherContainerTest.java new file mode 100644 index 00000000..952f2056 --- /dev/null +++ b/metarParser-entities/src/test/java/io/github/mivek/model/AbstractWeatherContainerTest.java @@ -0,0 +1,39 @@ +package io.github.mivek.model; + +import org.junit.Test; + +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.empty; +import static org.junit.Assert.assertNull; + +/** + * Test class for {@link AbstractWeatherContainer}. + * + * @author mivek + */ +public class AbstractWeatherContainerTest { + + @Test + public void testAddWeatherConditionWithNull() { + Metar m = new Metar(); + m.addWeatherCondition(null); + assertThat(m.getWeatherConditions(), empty()); + } + + @Test + public void testAddCloudWithNull() { + Metar m = new Metar(); + m.addCloud(null); + assertThat(m.getClouds(), empty()); + } + + @Test + public void testGetVerticalVisibility() { + //GIVEN a metar object with a null vertical visibility + Metar m = new Metar(); + //WHEN retrieving the vertical visibility + Integer result = m.getVerticalVisibility(); + //THEN the result is null, not a null pointer expection + assertNull(result); + } +} diff --git a/src/test/java/io/github/mivek/model/AirportTest.java b/metarParser-entities/src/test/java/io/github/mivek/model/AirportTest.java similarity index 82% rename from src/test/java/io/github/mivek/model/AirportTest.java rename to metarParser-entities/src/test/java/io/github/mivek/model/AirportTest.java index 29ddf445..77c0a2ab 100644 --- a/src/test/java/io/github/mivek/model/AirportTest.java +++ b/metarParser-entities/src/test/java/io/github/mivek/model/AirportTest.java @@ -1,70 +1,71 @@ -package io.github.mivek.model; - -import org.junit.Before; -import org.junit.Test; -import pl.pojo.tester.api.assertion.Method; - -import static org.junit.Assert.*; -import static pl.pojo.tester.api.assertion.Assertions.assertPojoMethodsFor; - -public class AirportTest { - private Airport sut; - - @Before - public void init() { - sut = new Airport(); - } - - @Test - public void testEqual() { - sut.setIcao("111"); - - Airport other1 = new Airport(); - other1.setIcao("111"); - - Airport other2 = new Airport(); - other2.setIcao("498"); - - assertTrue(sut.equals(sut)); - assertTrue(sut.equals(other1)); - assertFalse(sut.equals(other2)); - assertFalse(sut.equals(null)); - assertFalse(sut.equals(new Object())); - } - - @Test - public void test() { - String city = "London"; - String timezone = "Europe/London"; - String icao = "EGLL"; - String iata = "LHR"; - String name = "London Heathrow Airport"; - int altitude = 51; - double latitude = 51.4706; - double longitude = -0.461941; - sut = new Airport(); - sut.setCity(city); - sut.setTimezone(timezone); - sut.setIcao(icao); - sut.setIata(iata); - sut.setName(name); - sut.setAltitude(altitude); - sut.setLatitude(latitude); - sut.setLongitude(longitude); - assertEquals(city, sut.getCity()); - assertEquals(timezone, sut.getTimezone()); - assertEquals(icao, sut.getIcao()); - assertEquals(iata, sut.getIata()); - assertEquals(name, sut.getName()); - assertEquals(latitude, sut.getLatitude(), 0); - assertEquals(longitude, sut.getLongitude(),0); - assertEquals(altitude, sut.getAltitude()); - } - - @Test public void testPojo() { - // given - final Class classUnderTest = Airport.class; - // then - assertPojoMethodsFor(classUnderTest).testing(Method.GETTER, Method.SETTER).areWellImplemented(); - } -} +package io.github.mivek.model; + +import org.junit.Before; +import org.junit.Test; +import pl.pojo.tester.api.assertion.Method; + +import static org.junit.Assert.*; +import static pl.pojo.tester.api.assertion.Assertions.assertPojoMethodsFor; + +public class AirportTest { + private Airport sut; + + @Before + public void init() { + sut = new Airport(); + } + + @Test + public void testEqual() { + sut.setIcao("111"); + + Airport other1 = new Airport(); + other1.setIcao("111"); + + Airport other2 = new Airport(); + other2.setIcao("498"); + + assertEquals(sut, sut); + assertEquals(sut, other1); + assertNotEquals(sut, other2); + assertNotEquals(null, sut); + assertNotEquals(sut, new Object()); + } + + @Test + public void test() { + String city = "London"; + String timezone = "Europe/London"; + String icao = "EGLL"; + String iata = "LHR"; + String name = "London Heathrow Airport"; + int altitude = 51; + double latitude = 51.4706; + double longitude = -0.461941; + sut = new Airport(); + sut.setCity(city); + sut.setTimezone(timezone); + sut.setIcao(icao); + sut.setIata(iata); + sut.setName(name); + sut.setAltitude(altitude); + sut.setLatitude(latitude); + sut.setLongitude(longitude); + assertEquals(city, sut.getCity()); + assertEquals(timezone, sut.getTimezone()); + assertEquals(icao, sut.getIcao()); + assertEquals(iata, sut.getIata()); + assertEquals(name, sut.getName()); + assertEquals(latitude, sut.getLatitude(), 0); + assertEquals(longitude, sut.getLongitude(), 0); + assertEquals(altitude, sut.getAltitude()); + } + + @Test + public void testPojo() { + // given + final Class classUnderTest = Airport.class; + // then + assertPojoMethodsFor(classUnderTest).testing(Method.GETTER, Method.SETTER).areWellImplemented(); + } +} diff --git a/metarParser-entities/src/test/java/io/github/mivek/model/CloudTest.java b/metarParser-entities/src/test/java/io/github/mivek/model/CloudTest.java new file mode 100644 index 00000000..551f0cc5 --- /dev/null +++ b/metarParser-entities/src/test/java/io/github/mivek/model/CloudTest.java @@ -0,0 +1,41 @@ +package io.github.mivek.model; + +import io.github.mivek.enums.CloudQuantity; +import io.github.mivek.enums.CloudType; +import io.github.mivek.internationalization.Messages; +import org.hamcrest.Matchers; +import org.junit.Test; +import pl.pojo.tester.api.assertion.Method; + +import static org.hamcrest.MatcherAssert.assertThat; +import static org.junit.Assert.assertEquals; +import static pl.pojo.tester.api.assertion.Assertions.assertPojoMethodsFor; + +public class CloudTest { + + @Test + public void testSetHeightGetHeight() { + Cloud c = new Cloud(); + c.setHeight(300); + assertEquals(300, c.getHeight()); + } + + @Test + public void testToString() { + Cloud c = new Cloud(); + c.setQuantity(CloudQuantity.BKN); + c.setHeight(300); + c.setType(CloudType.CB); + assertThat(c.toString(), Matchers.containsString(Messages.getInstance().getString("ToString.type") + "=" + CloudType.CB.toString())); + assertThat(c.toString(), Matchers.containsString(Messages.getInstance().getString("ToString.quantity") + "=" + CloudQuantity.BKN.toString())); + assertThat(c.toString(), Matchers.containsString(Messages.getInstance().getString("ToString.height.feet") + "=300")); + } + + @Test + public void testPojo() { + // given + final Class classUnderTest = Cloud.class; + // then + assertPojoMethodsFor(classUnderTest).testing(Method.GETTER, Method.SETTER).areWellImplemented(); + } +} diff --git a/src/test/java/io/github/mivek/model/MetarTest.java b/metarParser-entities/src/test/java/io/github/mivek/model/MetarTest.java similarity index 92% rename from src/test/java/io/github/mivek/model/MetarTest.java rename to metarParser-entities/src/test/java/io/github/mivek/model/MetarTest.java index d65a9489..8b821797 100644 --- a/src/test/java/io/github/mivek/model/MetarTest.java +++ b/metarParser-entities/src/test/java/io/github/mivek/model/MetarTest.java @@ -8,7 +8,8 @@ public class MetarTest { - @Test public void testPojo() { + @Test + public void testPojo() { // given final Class classUnderTest = Metar.class; // then diff --git a/src/test/java/io/github/mivek/model/RunwayInfoTest.java b/metarParser-entities/src/test/java/io/github/mivek/model/RunwayInfoTest.java similarity index 89% rename from src/test/java/io/github/mivek/model/RunwayInfoTest.java rename to metarParser-entities/src/test/java/io/github/mivek/model/RunwayInfoTest.java index 5a7ee90d..5fb09a94 100644 --- a/src/test/java/io/github/mivek/model/RunwayInfoTest.java +++ b/metarParser-entities/src/test/java/io/github/mivek/model/RunwayInfoTest.java @@ -5,12 +5,13 @@ import org.junit.Test; import pl.pojo.tester.api.assertion.Method; -import static org.junit.Assert.assertThat; +import static org.hamcrest.MatcherAssert.assertThat; import static pl.pojo.tester.api.assertion.Assertions.assertPojoMethodsFor; public class RunwayInfoTest { - @Test public void testToString() { + @Test + public void testToString() { RunwayInfo ri = new RunwayInfo(); ri.setMinRange(300); ri.setName("14R"); @@ -25,7 +26,8 @@ public class RunwayInfoTest { assertThat(des, Matchers.containsString(Messages.getInstance().getString("ToString.trend") + "=rising")); } - @Test public void testPojo() { + @Test + public void testPojo() { // given final Class classUnderTest = RunwayInfo.class; // then diff --git a/src/test/java/io/github/mivek/model/TAFTest.java b/metarParser-entities/src/test/java/io/github/mivek/model/TAFTest.java similarity index 91% rename from src/test/java/io/github/mivek/model/TAFTest.java rename to metarParser-entities/src/test/java/io/github/mivek/model/TAFTest.java index f978ee45..948ec637 100644 --- a/src/test/java/io/github/mivek/model/TAFTest.java +++ b/metarParser-entities/src/test/java/io/github/mivek/model/TAFTest.java @@ -6,7 +6,8 @@ import static pl.pojo.tester.api.assertion.Assertions.assertPojoMethodsFor; public class TAFTest { - @Test public void testPojo() { + @Test + public void testPojo() { // given final Class classUnderTest = Cloud.class; // then diff --git a/src/test/java/io/github/mivek/model/TemperatureDatedTest.java b/metarParser-entities/src/test/java/io/github/mivek/model/TemperatureDatedTest.java similarity index 92% rename from src/test/java/io/github/mivek/model/TemperatureDatedTest.java rename to metarParser-entities/src/test/java/io/github/mivek/model/TemperatureDatedTest.java index b25a2f77..a6130f57 100644 --- a/src/test/java/io/github/mivek/model/TemperatureDatedTest.java +++ b/metarParser-entities/src/test/java/io/github/mivek/model/TemperatureDatedTest.java @@ -4,8 +4,8 @@ import org.junit.Test; import pl.pojo.tester.api.assertion.Method; +import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.containsString; -import static org.junit.Assert.assertThat; import static pl.pojo.tester.api.assertion.Assertions.assertPojoMethodsFor; public class TemperatureDatedTest { @@ -23,7 +23,8 @@ public void testToString() { assertThat(des, containsString(Messages.getInstance().getString("ToString.temperature") + "=20")); } - @Test public void testPojo() { + @Test + public void testPojo() { // given final Class classUnderTest = TemperatureDated.class; // then diff --git a/src/test/java/io/github/mivek/model/VisibilityTest.java b/metarParser-entities/src/test/java/io/github/mivek/model/VisibilityTest.java similarity index 89% rename from src/test/java/io/github/mivek/model/VisibilityTest.java rename to metarParser-entities/src/test/java/io/github/mivek/model/VisibilityTest.java index 344db290..c125cfda 100644 --- a/src/test/java/io/github/mivek/model/VisibilityTest.java +++ b/metarParser-entities/src/test/java/io/github/mivek/model/VisibilityTest.java @@ -5,13 +5,13 @@ import org.junit.Test; import pl.pojo.tester.api.assertion.Method; -import static org.junit.Assert.assertThat; +import static org.hamcrest.MatcherAssert.assertThat; import static pl.pojo.tester.api.assertion.Assertions.assertPojoMethodsFor; public class VisibilityTest { @Test - public void testToString(){ + public void testToString() { Visibility sut = new Visibility(); sut.setMainVisibility(">10km"); sut.setMinDirection("SE"); @@ -24,7 +24,8 @@ public void testToString(){ assertThat(des, Matchers.containsString(Messages.getInstance().getString("ToString.visibility.min") + "=200")); } - @Test public void testPojo() { + @Test + public void testPojo() { // given final Class classUnderTest = Visibility.class; // then diff --git a/src/test/java/io/github/mivek/model/WeatherConditionTest.java b/metarParser-entities/src/test/java/io/github/mivek/model/WeatherConditionTest.java similarity index 91% rename from src/test/java/io/github/mivek/model/WeatherConditionTest.java rename to metarParser-entities/src/test/java/io/github/mivek/model/WeatherConditionTest.java index 7dcc4790..7d0303d9 100644 --- a/src/test/java/io/github/mivek/model/WeatherConditionTest.java +++ b/metarParser-entities/src/test/java/io/github/mivek/model/WeatherConditionTest.java @@ -9,13 +9,13 @@ import pl.pojo.tester.api.FieldPredicate; import pl.pojo.tester.api.assertion.Method; -import static org.junit.Assert.assertThat; +import static org.hamcrest.MatcherAssert.assertThat; import static pl.pojo.tester.api.assertion.Assertions.assertPojoMethodsFor; public class WeatherConditionTest { @Test - public void testToString(){ + public void testToString() { WeatherCondition sut = new WeatherCondition(); sut.setIntensity(Intensity.LIGHT); sut.setDescriptive(Descriptive.SHOWERS); @@ -28,7 +28,8 @@ public void testToString(){ assertThat(desc, Matchers.containsString(Phenomenon.RAIN.toString())); } - @Test public void testPojo() { + @Test + public void testPojo() { // given final Class classUnderTest = WeatherCondition.class; // then diff --git a/src/test/java/io/github/mivek/model/WindShearTest.java b/metarParser-entities/src/test/java/io/github/mivek/model/WindShearTest.java similarity index 83% rename from src/test/java/io/github/mivek/model/WindShearTest.java rename to metarParser-entities/src/test/java/io/github/mivek/model/WindShearTest.java index 8dd58dde..76a09284 100644 --- a/src/test/java/io/github/mivek/model/WindShearTest.java +++ b/metarParser-entities/src/test/java/io/github/mivek/model/WindShearTest.java @@ -5,19 +5,21 @@ import org.junit.Test; import pl.pojo.tester.api.assertion.Method; -import static org.junit.Assert.assertThat; +import static org.hamcrest.MatcherAssert.assertThat; import static pl.pojo.tester.api.assertion.Assertions.assertPojoMethodsFor; public class WindShearTest { - @Test public void testToString() { + @Test + public void testToString() { WindShear sut = new WindShear(); sut.setHeight(500); assertThat(sut.toString(), Matchers.containsString(Messages.getInstance().getString("ToString.height.feet") + "=500")); } - @Test public void testPojo() { + @Test + public void testPojo() { // given final Class classUnderTest = WindShear.class; // then diff --git a/src/test/java/io/github/mivek/model/WindTest.java b/metarParser-entities/src/test/java/io/github/mivek/model/WindTest.java similarity index 92% rename from src/test/java/io/github/mivek/model/WindTest.java rename to metarParser-entities/src/test/java/io/github/mivek/model/WindTest.java index 21ba0e2c..acc9fa3a 100644 --- a/src/test/java/io/github/mivek/model/WindTest.java +++ b/metarParser-entities/src/test/java/io/github/mivek/model/WindTest.java @@ -4,14 +4,14 @@ import org.junit.Test; import pl.pojo.tester.api.assertion.Method; +import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.containsString; -import static org.junit.Assert.assertThat; import static pl.pojo.tester.api.assertion.Assertions.assertPojoMethodsFor; public class WindTest { @Test - public void testToString(){ + public void testToString() { Wind sut = new Wind(); sut.setDirection(Messages.getInstance().getString("Converter.NE")); @@ -19,7 +19,6 @@ public void testToString(){ sut.setSpeed(25); sut.setUnit("KM/H"); - String desc = sut.toString(); assertThat(desc, containsString(Messages.getInstance().getString("ToString.wind.speed") + "=25")); @@ -31,7 +30,8 @@ public void testToString(){ assertThat(desc, containsString(Messages.getInstance().getString("ToString.wind.unit") + "=KM/H")); } - @Test public void testPojo() { + @Test + public void testPojo() { // given final Class classUnderTest = Wind.class; // then diff --git a/src/test/java/io/github/mivek/model/trend/validity/ATTimeTest.java b/metarParser-entities/src/test/java/io/github/mivek/model/trend/validity/ATTimeTest.java similarity index 100% rename from src/test/java/io/github/mivek/model/trend/validity/ATTimeTest.java rename to metarParser-entities/src/test/java/io/github/mivek/model/trend/validity/ATTimeTest.java diff --git a/src/test/java/io/github/mivek/model/trend/validity/BeginningValidityTest.java b/metarParser-entities/src/test/java/io/github/mivek/model/trend/validity/BeginningValidityTest.java similarity index 93% rename from src/test/java/io/github/mivek/model/trend/validity/BeginningValidityTest.java rename to metarParser-entities/src/test/java/io/github/mivek/model/trend/validity/BeginningValidityTest.java index 419845d0..0e64e2f2 100644 --- a/src/test/java/io/github/mivek/model/trend/validity/BeginningValidityTest.java +++ b/metarParser-entities/src/test/java/io/github/mivek/model/trend/validity/BeginningValidityTest.java @@ -3,8 +3,8 @@ import io.github.mivek.internationalization.Messages; import org.junit.Test; +import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.containsString; -import static org.junit.Assert.assertThat; public class BeginningValidityTest { diff --git a/src/test/java/io/github/mivek/model/trend/validity/FMTimeTest.java b/metarParser-entities/src/test/java/io/github/mivek/model/trend/validity/FMTimeTest.java similarity index 100% rename from src/test/java/io/github/mivek/model/trend/validity/FMTimeTest.java rename to metarParser-entities/src/test/java/io/github/mivek/model/trend/validity/FMTimeTest.java diff --git a/src/test/java/io/github/mivek/model/trend/validity/TLTimeTest.java b/metarParser-entities/src/test/java/io/github/mivek/model/trend/validity/TLTimeTest.java similarity index 68% rename from src/test/java/io/github/mivek/model/trend/validity/TLTimeTest.java rename to metarParser-entities/src/test/java/io/github/mivek/model/trend/validity/TLTimeTest.java index 7b5d4a15..eafde2cb 100644 --- a/src/test/java/io/github/mivek/model/trend/validity/TLTimeTest.java +++ b/metarParser-entities/src/test/java/io/github/mivek/model/trend/validity/TLTimeTest.java @@ -9,12 +9,12 @@ public class TLTimeTest { @Test - public void testToString(){ + public void testToString() { TLTime sut = new TLTime(); - sut.setTime(LocalTime.of(12,15)); + sut.setTime(LocalTime.of(12, 15)); String desc = sut.toString(); - assertEquals(TimeIndicator.TL.toString()+" 12:15", desc); + assertEquals(TimeIndicator.TL.toString() + " 12:15", desc); } } diff --git a/src/test/java/io/github/mivek/model/trend/validity/ValidityTest.java b/metarParser-entities/src/test/java/io/github/mivek/model/trend/validity/ValidityTest.java similarity index 94% rename from src/test/java/io/github/mivek/model/trend/validity/ValidityTest.java rename to metarParser-entities/src/test/java/io/github/mivek/model/trend/validity/ValidityTest.java index 7ed1de2b..71ccb095 100644 --- a/src/test/java/io/github/mivek/model/trend/validity/ValidityTest.java +++ b/metarParser-entities/src/test/java/io/github/mivek/model/trend/validity/ValidityTest.java @@ -3,8 +3,8 @@ import io.github.mivek.internationalization.Messages; import org.junit.Test; +import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.containsString; -import static org.junit.Assert.assertThat; public class ValidityTest { @Test diff --git a/metarParser-parsers/README.md b/metarParser-parsers/README.md new file mode 100644 index 00000000..2ce1e0e5 --- /dev/null +++ b/metarParser-parsers/README.md @@ -0,0 +1,3 @@ +# MetarParser-parsers + +This module contains the parsers for METAR and TAF messages. diff --git a/metarParser-parsers/pom.xml b/metarParser-parsers/pom.xml new file mode 100644 index 00000000..573df6d5 --- /dev/null +++ b/metarParser-parsers/pom.xml @@ -0,0 +1,28 @@ + + + + metarParser + io.github.mivek + 1.10.5 + + 4.0.0 + + metarParser-parsers + Module containing the parsers. + + + 0.98 + 0.95 + 0.97 + + + + + io.github.mivek + metarParser-spi + ${project.version} + + + diff --git a/metarParser-parsers/src/main/java/io/github/mivek/command/AirportSupplier.java b/metarParser-parsers/src/main/java/io/github/mivek/command/AirportSupplier.java new file mode 100644 index 00000000..22c9eb14 --- /dev/null +++ b/metarParser-parsers/src/main/java/io/github/mivek/command/AirportSupplier.java @@ -0,0 +1,34 @@ +package io.github.mivek.command; + +import io.github.mivek.model.Airport; +import io.github.mivek.provider.airport.AirportProvider; +import io.github.mivek.provider.airport.impl.DefaultAirportProvider; + +import java.util.ServiceLoader; + +/** + * @author mivek + */ +public final class AirportSupplier implements Supplier { + /** The service loader for the airport provider. */ + private final ServiceLoader airportLoader; + + /** + * Constructor. + */ + public AirportSupplier() { + airportLoader = ServiceLoader.load(AirportProvider.class); + } + + @Override + public Airport get(final String string) { + AirportProvider provider; + if (airportLoader.iterator().hasNext()) { + provider = airportLoader.iterator().next(); + } else { + provider = new DefaultAirportProvider(); + } + return provider.getAirports().get(string); + } +} + diff --git a/src/main/java/io/github/mivek/command/Supplier.java b/metarParser-parsers/src/main/java/io/github/mivek/command/Supplier.java similarity index 58% rename from src/main/java/io/github/mivek/command/Supplier.java rename to metarParser-parsers/src/main/java/io/github/mivek/command/Supplier.java index 1c020143..818dfd09 100644 --- a/src/main/java/io/github/mivek/command/Supplier.java +++ b/metarParser-parsers/src/main/java/io/github/mivek/command/Supplier.java @@ -4,12 +4,13 @@ * @param type of command to return. * @author mivek */ -@FunctionalInterface public interface Supplier { +@FunctionalInterface +public interface Supplier { /** - * @param pString the string to parse. + * @param string the string to parse. * @return the command able to parse the string. */ - T get(String pString); + T get(String string); } diff --git a/metarParser-parsers/src/main/java/io/github/mivek/command/common/BaseWindCommand.java b/metarParser-parsers/src/main/java/io/github/mivek/command/common/BaseWindCommand.java new file mode 100644 index 00000000..aba32153 --- /dev/null +++ b/metarParser-parsers/src/main/java/io/github/mivek/command/common/BaseWindCommand.java @@ -0,0 +1,37 @@ +package io.github.mivek.command.common; + +import io.github.mivek.internationalization.Messages; +import io.github.mivek.model.Wind; +import io.github.mivek.utils.Converter; + +/** + * @author mivek + */ +public interface BaseWindCommand extends Command { + + /** + * Sets the elements of the wind. + * + * @param wind the wind element. + * @param directionStr the direction of the wind in degrees. + * @param speed the speed of the wind + * @param gust the speed of the gust if any + * @param unit the unit. + */ + default void setWindElements(final Wind wind, final String directionStr, final String speed, final String gust, final String unit) { + String direction = Converter.degreesToDirection(directionStr); + wind.setDirection(direction); + if (!direction.equals(Messages.getInstance().getString("Converter.VRB"))) { + wind.setDirectionDegrees(Integer.parseInt(directionStr)); + } + wind.setSpeed(Integer.parseInt(speed)); + if (gust != null) { + wind.setGust(Integer.parseInt(gust)); + } + if (unit == null) { + wind.setUnit("KT"); + } else { + wind.setUnit(unit); + } + } +} diff --git a/src/main/java/io/github/mivek/command/common/CloudCommand.java b/metarParser-parsers/src/main/java/io/github/mivek/command/common/CloudCommand.java similarity index 69% rename from src/main/java/io/github/mivek/command/common/CloudCommand.java rename to metarParser-parsers/src/main/java/io/github/mivek/command/common/CloudCommand.java index fd33796e..896318c1 100644 --- a/src/main/java/io/github/mivek/command/common/CloudCommand.java +++ b/metarParser-parsers/src/main/java/io/github/mivek/command/common/CloudCommand.java @@ -15,20 +15,27 @@ public final class CloudCommand implements Command { /** Pattern to recognize clouds. */ private static final Pattern CLOUD_REGEX = Pattern.compile("^([A-Z]{3})(\\d{3})?([A-Z]{2,3})?$"); - @Override public boolean execute(final AbstractWeatherContainer pContainer, final String pPart) { - Cloud c = parseCloud(pPart); - return pContainer.addCloud(c); + /** + * constructor. + */ + CloudCommand() { + } + + @Override + public boolean execute(final AbstractWeatherContainer container, final String part) { + Cloud c = parseCloud(part); + return container.addCloud(c); } /** * This method parses the cloud part of the metar. * - * @param pCloudString string with cloud elements. + * @param cloudString string with cloud elements. * @return a decoded cloud with its quantity, its altitude and its type. */ - protected Cloud parseCloud(final String pCloudString) { + protected Cloud parseCloud(final String cloudString) { Cloud cloud = new Cloud(); - String[] cloudPart = Regex.pregMatch(CLOUD_REGEX, pCloudString); + String[] cloudPart = Regex.pregMatch(CLOUD_REGEX, cloudString); try { CloudQuantity cq = CloudQuantity.valueOf(cloudPart[1]); cloud.setQuantity(cq); @@ -45,8 +52,9 @@ protected Cloud parseCloud(final String pCloudString) { } } - @Override public boolean canParse(final String pInput) { - return Regex.find(CLOUD_REGEX, pInput); + @Override + public boolean canParse(final String input) { + return Regex.find(CLOUD_REGEX, input); } } diff --git a/src/main/java/io/github/mivek/command/common/Command.java b/metarParser-parsers/src/main/java/io/github/mivek/command/common/Command.java similarity index 60% rename from src/main/java/io/github/mivek/command/common/Command.java rename to metarParser-parsers/src/main/java/io/github/mivek/command/common/Command.java index 95d24152..12d0bd6f 100644 --- a/src/main/java/io/github/mivek/command/common/Command.java +++ b/metarParser-parsers/src/main/java/io/github/mivek/command/common/Command.java @@ -8,13 +8,13 @@ public interface Command { /** - * Handles the pPart and updates the pContainer. + * Handles the pqrt and updates the container. * - * @param pContainer the container to update. - * @param pPart the string to parse. + * @param container the container to update. + * @param part the string to parse. * @return true if the part has been properly handled false otherwise */ - boolean execute(AbstractWeatherContainer pContainer, String pPart); + boolean execute(AbstractWeatherContainer container, String part); /** * @return the default return value of a command. @@ -24,8 +24,8 @@ default boolean getReturnValue() { } /** - * @param pInput the input string to test. + * @param input the input string to test. * @return true if the input can be handled by the command. */ - boolean canParse(String pInput); + boolean canParse(String input); } diff --git a/src/main/java/io/github/mivek/command/common/CommonCommandSupplier.java b/metarParser-parsers/src/main/java/io/github/mivek/command/common/CommonCommandSupplier.java similarity index 92% rename from src/main/java/io/github/mivek/command/common/CommonCommandSupplier.java rename to metarParser-parsers/src/main/java/io/github/mivek/command/common/CommonCommandSupplier.java index 1a229ce3..a9ab8b91 100644 --- a/src/main/java/io/github/mivek/command/common/CommonCommandSupplier.java +++ b/metarParser-parsers/src/main/java/io/github/mivek/command/common/CommonCommandSupplier.java @@ -19,9 +19,10 @@ public CommonCommandSupplier() { commands = buildCommands(); } - @Override public Command get(final String pString) { + @Override + public Command get(final String string) { for (Command command : commands) { - if (command.canParse(pString)) { + if (command.canParse(string)) { return command; } } diff --git a/src/main/java/io/github/mivek/command/common/MainVisibilityCommand.java b/metarParser-parsers/src/main/java/io/github/mivek/command/common/MainVisibilityCommand.java similarity index 54% rename from src/main/java/io/github/mivek/command/common/MainVisibilityCommand.java rename to metarParser-parsers/src/main/java/io/github/mivek/command/common/MainVisibilityCommand.java index 78ff5c81..6f31e1da 100644 --- a/src/main/java/io/github/mivek/command/common/MainVisibilityCommand.java +++ b/metarParser-parsers/src/main/java/io/github/mivek/command/common/MainVisibilityCommand.java @@ -14,16 +14,24 @@ public final class MainVisibilityCommand implements Command { /** Pattern for the main visibility. */ private static final Pattern MAIN_VISIBILITY_REGEX = Pattern.compile("^(\\d{4})(|NDV)$"); - @Override public boolean execute(final AbstractWeatherContainer pContainer, final String pPart) { - String[] matches = Regex.pregMatch(MAIN_VISIBILITY_REGEX, pPart); - if (pContainer.getVisibility() == null) { - pContainer.setVisibility(new Visibility()); + /** + * constructor. + */ + MainVisibilityCommand() { + } + + @Override + public boolean execute(final AbstractWeatherContainer container, final String part) { + String[] matches = Regex.pregMatch(MAIN_VISIBILITY_REGEX, part); + if (container.getVisibility() == null) { + container.setVisibility(new Visibility()); } - pContainer.getVisibility().setMainVisibility(Converter.convertVisibility(matches[1])); + container.getVisibility().setMainVisibility(Converter.convertVisibility(matches[1])); return getReturnValue(); } - @Override public boolean canParse(final String pInput) { - return Regex.find(MAIN_VISIBILITY_REGEX, pInput); + @Override + public boolean canParse(final String input) { + return Regex.find(MAIN_VISIBILITY_REGEX, input); } } diff --git a/src/main/java/io/github/mivek/command/common/MainVisibilityNauticalMilesCommand.java b/metarParser-parsers/src/main/java/io/github/mivek/command/common/MainVisibilityNauticalMilesCommand.java similarity index 54% rename from src/main/java/io/github/mivek/command/common/MainVisibilityNauticalMilesCommand.java rename to metarParser-parsers/src/main/java/io/github/mivek/command/common/MainVisibilityNauticalMilesCommand.java index 7d423c01..707d19bf 100644 --- a/src/main/java/io/github/mivek/command/common/MainVisibilityNauticalMilesCommand.java +++ b/metarParser-parsers/src/main/java/io/github/mivek/command/common/MainVisibilityNauticalMilesCommand.java @@ -13,17 +13,24 @@ public final class MainVisibilityNauticalMilesCommand implements Command { /** Pattern for the main visibility in SM. */ private static final Pattern MAIN_VISIBILITY_SM_REGEX = Pattern.compile("^(\\d)*(\\s)?((\\d\\/\\d)?SM)$"); + /** + * constructor. + */ + MainVisibilityNauticalMilesCommand() { + } - @Override public boolean execute(final AbstractWeatherContainer pContainer, final String pPart) { - String[] matches = Regex.pregMatch(MAIN_VISIBILITY_SM_REGEX, pPart); - if (pContainer.getVisibility() == null) { - pContainer.setVisibility(new Visibility()); + @Override + public boolean execute(final AbstractWeatherContainer container, final String part) { + String[] matches = Regex.pregMatch(MAIN_VISIBILITY_SM_REGEX, part); + if (container.getVisibility() == null) { + container.setVisibility(new Visibility()); } - pContainer.getVisibility().setMainVisibility(matches[0]); + container.getVisibility().setMainVisibility(matches[0]); return getReturnValue(); } - @Override public boolean canParse(final String pInput) { - return Regex.find(MAIN_VISIBILITY_SM_REGEX, pInput); + @Override + public boolean canParse(final String input) { + return Regex.find(MAIN_VISIBILITY_SM_REGEX, input); } } diff --git a/src/main/java/io/github/mivek/command/common/MinimalVisibilityCommand.java b/metarParser-parsers/src/main/java/io/github/mivek/command/common/MinimalVisibilityCommand.java similarity index 50% rename from src/main/java/io/github/mivek/command/common/MinimalVisibilityCommand.java rename to metarParser-parsers/src/main/java/io/github/mivek/command/common/MinimalVisibilityCommand.java index 30654f49..42b08df5 100644 --- a/src/main/java/io/github/mivek/command/common/MinimalVisibilityCommand.java +++ b/metarParser-parsers/src/main/java/io/github/mivek/command/common/MinimalVisibilityCommand.java @@ -12,14 +12,22 @@ public final class MinimalVisibilityCommand implements Command { /** Pattern for the minimum visibility. */ public static final Pattern MIN_VISIBILITY_REGEX = Pattern.compile("^(\\d{4}[a-z])$"); - @Override public boolean execute(final AbstractWeatherContainer pContainer, final String pPart) { - String[] matches = Regex.pregMatch(MIN_VISIBILITY_REGEX, pPart); - pContainer.getVisibility().setMinVisibility(Integer.parseInt(matches[1].substring(0, 4))); - pContainer.getVisibility().setMinDirection(matches[1].substring(4)); + /** + * Protected constructor. + */ + MinimalVisibilityCommand() { + } + + @Override + public boolean execute(final AbstractWeatherContainer container, final String part) { + String[] matches = Regex.pregMatch(MIN_VISIBILITY_REGEX, part); + container.getVisibility().setMinVisibility(Integer.parseInt(matches[1].substring(0, 4))); + container.getVisibility().setMinDirection(matches[1].substring(4)); return getReturnValue(); } - @Override public boolean canParse(final String pInput) { - return Regex.find(MIN_VISIBILITY_REGEX, pInput); + @Override + public boolean canParse(final String input) { + return Regex.find(MIN_VISIBILITY_REGEX, input); } } diff --git a/src/main/java/io/github/mivek/command/common/VerticalVisibilityCommand.java b/metarParser-parsers/src/main/java/io/github/mivek/command/common/VerticalVisibilityCommand.java similarity index 56% rename from src/main/java/io/github/mivek/command/common/VerticalVisibilityCommand.java rename to metarParser-parsers/src/main/java/io/github/mivek/command/common/VerticalVisibilityCommand.java index a6c8653a..ccc6ccbf 100644 --- a/src/main/java/io/github/mivek/command/common/VerticalVisibilityCommand.java +++ b/metarParser-parsers/src/main/java/io/github/mivek/command/common/VerticalVisibilityCommand.java @@ -12,13 +12,21 @@ public final class VerticalVisibilityCommand implements Command { /** Pattern for the vertical visibility. */ private static final Pattern VERTICAL_VISIBILITY = Pattern.compile("^VV(\\d{3})$"); - @Override public boolean execute(final AbstractWeatherContainer pContainer, final String pPart) { - String[] matches = Regex.pregMatch(VERTICAL_VISIBILITY, pPart); - pContainer.setVerticalVisibility(100 * Integer.parseInt(matches[1])); + /** + * Protected constructor. + */ + VerticalVisibilityCommand() { + } + + @Override + public boolean execute(final AbstractWeatherContainer container, final String part) { + String[] matches = Regex.pregMatch(VERTICAL_VISIBILITY, part); + container.setVerticalVisibility(100 * Integer.parseInt(matches[1])); return getReturnValue(); } - @Override public boolean canParse(final String pInput) { - return Regex.find(VERTICAL_VISIBILITY, pInput); + @Override + public boolean canParse(final String input) { + return Regex.find(VERTICAL_VISIBILITY, input); } } diff --git a/src/main/java/io/github/mivek/command/common/WindCommand.java b/metarParser-parsers/src/main/java/io/github/mivek/command/common/WindCommand.java similarity index 59% rename from src/main/java/io/github/mivek/command/common/WindCommand.java rename to metarParser-parsers/src/main/java/io/github/mivek/command/common/WindCommand.java index e9e5d7ef..33b1f86f 100644 --- a/src/main/java/io/github/mivek/command/common/WindCommand.java +++ b/metarParser-parsers/src/main/java/io/github/mivek/command/common/WindCommand.java @@ -12,27 +12,36 @@ public final class WindCommand implements BaseWindCommand { /** Pattern regex for wind. */ private static final Pattern WIND_REGEX = Pattern.compile("(VRB|\\d{3})(\\d{2})G?(\\d{2})?(KT|MPS|KM\\/H)?"); + + /** + * Package private constructor. + */ + WindCommand() { + } + /** * This method parses the wind part of the metar code. It parses the generic * part. * - * @param pStringWind a string with wind elements. + * @param stringWind a string with wind elements. * @return a Wind element with the informations. */ - protected Wind parseWind(final String pStringWind) { + protected Wind parseWind(final String stringWind) { Wind wind = new Wind(); - String[] windPart = Regex.pregMatch(WIND_REGEX, pStringWind); + String[] windPart = Regex.pregMatch(WIND_REGEX, stringWind); setWindElements(wind, windPart[1], windPart[2], windPart[3], windPart[4]); return wind; } - @Override public boolean execute(final AbstractWeatherContainer pContainer, final String pPart) { - Wind wind = parseWind(pPart); - pContainer.setWind(wind); + @Override + public boolean execute(final AbstractWeatherContainer container, final String part) { + Wind wind = parseWind(part); + container.setWind(wind); return getReturnValue(); } - @Override public boolean canParse(final String pInput) { - return Regex.find(WIND_REGEX, pInput); + @Override + public boolean canParse(final String input) { + return Regex.find(WIND_REGEX, input); } } diff --git a/metarParser-parsers/src/main/java/io/github/mivek/command/common/WindExtremeCommand.java b/metarParser-parsers/src/main/java/io/github/mivek/command/common/WindExtremeCommand.java new file mode 100644 index 00000000..e350bc4c --- /dev/null +++ b/metarParser-parsers/src/main/java/io/github/mivek/command/common/WindExtremeCommand.java @@ -0,0 +1,44 @@ +package io.github.mivek.command.common; + +import io.github.mivek.model.AbstractWeatherContainer; +import io.github.mivek.model.Wind; +import io.github.mivek.utils.Regex; + +import java.util.regex.Pattern; + +/** + * @author mivek + */ +public final class WindExtremeCommand implements Command { + /** Pattern regex for extreme winds. */ + private static final Pattern WIND_EXTREME_REGEX = Pattern.compile("^(\\d{3})V(\\d{3})"); + + /** + * Protected constructor. + */ + WindExtremeCommand() { + } + + @Override + public boolean execute(final AbstractWeatherContainer container, final String part) { + parseWindVariation(container.getWind(), part); + return getReturnValue(); + } + + /** + * Parses the wind. + * + * @param wind the wind to update + * @param windVariation String with wind variation information + */ + protected void parseWindVariation(final Wind wind, final String windVariation) { + String[] matches = Regex.pregMatch(WIND_EXTREME_REGEX, windVariation); + wind.setMinVariation(Integer.parseInt(matches[1])); + wind.setMaxVariation(Integer.parseInt(matches[2])); + } + + @Override + public boolean canParse(final String input) { + return Regex.find(WIND_EXTREME_REGEX, input); + } +} diff --git a/src/main/java/io/github/mivek/command/common/WindShearCommand.java b/metarParser-parsers/src/main/java/io/github/mivek/command/common/WindShearCommand.java similarity index 57% rename from src/main/java/io/github/mivek/command/common/WindShearCommand.java rename to metarParser-parsers/src/main/java/io/github/mivek/command/common/WindShearCommand.java index 975a0498..dcaae774 100644 --- a/src/main/java/io/github/mivek/command/common/WindShearCommand.java +++ b/metarParser-parsers/src/main/java/io/github/mivek/command/common/WindShearCommand.java @@ -13,27 +13,35 @@ public final class WindShearCommand implements BaseWindCommand { /** Pattern regex for windshear. */ private static final Pattern WIND_SHEAR_REGEX = Pattern.compile("WS(\\d{3})\\/(\\w{3})(\\d{2})G?(\\d{2})?(KT|MPS|KM\\/H)"); - @Override public boolean execute(final AbstractWeatherContainer pContainer, final String pPart) { - WindShear windShear = parseWindShear(pPart); - pContainer.setWindShear(windShear); + /** + * Package private constructor. + */ + WindShearCommand() { + } + + @Override + public boolean execute(final AbstractWeatherContainer container, final String part) { + WindShear windShear = parseWindShear(part); + container.setWindShear(windShear); return getReturnValue(); } /** * Parses the wind shear part. * - * @param pStringWindShear the string to parse + * @param stringWindShear the string to parse * @return a wind shear object. */ - protected WindShear parseWindShear(final String pStringWindShear) { + protected WindShear parseWindShear(final String stringWindShear) { WindShear wind = new WindShear(); - String[] windPart = Regex.pregMatch(WIND_SHEAR_REGEX, pStringWindShear); + String[] windPart = Regex.pregMatch(WIND_SHEAR_REGEX, stringWindShear); wind.setHeight(100 * Integer.parseInt(windPart[1])); setWindElements(wind, windPart[2], windPart[3], windPart[4], windPart[5]); return wind; } - @Override public boolean canParse(final String pInput) { - return Regex.find(WIND_SHEAR_REGEX, pInput); + @Override + public boolean canParse(final String input) { + return Regex.find(WIND_SHEAR_REGEX, input); } } diff --git a/src/main/java/io/github/mivek/command/common/package-info.java b/metarParser-parsers/src/main/java/io/github/mivek/command/common/package-info.java similarity index 100% rename from src/main/java/io/github/mivek/command/common/package-info.java rename to metarParser-parsers/src/main/java/io/github/mivek/command/common/package-info.java diff --git a/metarParser-parsers/src/main/java/io/github/mivek/command/metar/AltimeterCommand.java b/metarParser-parsers/src/main/java/io/github/mivek/command/metar/AltimeterCommand.java new file mode 100644 index 00000000..d7c84982 --- /dev/null +++ b/metarParser-parsers/src/main/java/io/github/mivek/command/metar/AltimeterCommand.java @@ -0,0 +1,32 @@ +package io.github.mivek.command.metar; + +import io.github.mivek.model.Metar; +import io.github.mivek.utils.Regex; + +import java.util.regex.Pattern; + +/** + * @author mivek + */ +public final class AltimeterCommand implements Command { + + /** Pattern of the altimeter (Pascals). */ + private static final Pattern ALTIMETER_REGEX = Pattern.compile("^Q(\\d{4})$"); + + /** + * Package private constructor. + */ + AltimeterCommand() { + } + + @Override + public void execute(final Metar metar, final String part) { + String[] matches = Regex.pregMatch(ALTIMETER_REGEX, part); + metar.setAltimeter(Integer.parseInt(matches[1])); + } + + @Override + public boolean canParse(final String input) { + return Regex.find(ALTIMETER_REGEX, input); + } +} diff --git a/src/main/java/io/github/mivek/command/metar/AltimeterMecuryCommand.java b/metarParser-parsers/src/main/java/io/github/mivek/command/metar/AltimeterMecuryCommand.java similarity index 59% rename from src/main/java/io/github/mivek/command/metar/AltimeterMecuryCommand.java rename to metarParser-parsers/src/main/java/io/github/mivek/command/metar/AltimeterMecuryCommand.java index b38cf251..59f03c25 100644 --- a/src/main/java/io/github/mivek/command/metar/AltimeterMecuryCommand.java +++ b/metarParser-parsers/src/main/java/io/github/mivek/command/metar/AltimeterMecuryCommand.java @@ -14,13 +14,21 @@ public final class AltimeterMecuryCommand implements Command { /** Pattern for the altimeter in inches of mercury. */ private static final Pattern ALTIMETER_MERCURY_REGEX = Pattern.compile("^A(\\d{4})$"); - @Override public void execute(final Metar pMetar, final String pPart) { - String[] matches = Regex.pregMatch(ALTIMETER_MERCURY_REGEX, pPart); + /** + * Package private constructor. + */ + AltimeterMecuryCommand() { + } + + @Override + public void execute(final Metar metar, final String part) { + String[] matches = Regex.pregMatch(ALTIMETER_MERCURY_REGEX, part); double mercury = Double.parseDouble(matches[1]) / 100; - pMetar.setAltimeter((int) Converter.inchesMercuryToHPascal(mercury)); + metar.setAltimeter((int) Converter.inchesMercuryToHPascal(mercury)); } - @Override public boolean canParse(final String pInput) { - return Regex.find(ALTIMETER_MERCURY_REGEX, pInput); + @Override + public boolean canParse(final String input) { + return Regex.find(ALTIMETER_MERCURY_REGEX, input); } } diff --git a/src/main/java/io/github/mivek/command/metar/Command.java b/metarParser-parsers/src/main/java/io/github/mivek/command/metar/Command.java similarity index 50% rename from src/main/java/io/github/mivek/command/metar/Command.java rename to metarParser-parsers/src/main/java/io/github/mivek/command/metar/Command.java index 2208e2eb..8f56f5ef 100644 --- a/src/main/java/io/github/mivek/command/metar/Command.java +++ b/metarParser-parsers/src/main/java/io/github/mivek/command/metar/Command.java @@ -10,16 +10,16 @@ public interface Command { /** - * Methode handling the pPart to parse. + * Method handling the part to parse. * - * @param pMetar the metar object to handle. - * @param pPart the string to parse. + * @param metar the metar object to handle. + * @param part the string to parse. */ - void execute(Metar pMetar, String pPart); + void execute(Metar metar, String part); /** - * @param pInput the input string to test. + * @param input the input string to test. * @return true if the input can be handled by the command. */ - boolean canParse(String pInput); + boolean canParse(String input); } diff --git a/src/main/java/io/github/mivek/command/metar/MetarParserCommandSupplier.java b/metarParser-parsers/src/main/java/io/github/mivek/command/metar/MetarParserCommandSupplier.java similarity index 90% rename from src/main/java/io/github/mivek/command/metar/MetarParserCommandSupplier.java rename to metarParser-parsers/src/main/java/io/github/mivek/command/metar/MetarParserCommandSupplier.java index 26ad8d67..eb7afb68 100644 --- a/src/main/java/io/github/mivek/command/metar/MetarParserCommandSupplier.java +++ b/metarParser-parsers/src/main/java/io/github/mivek/command/metar/MetarParserCommandSupplier.java @@ -19,9 +19,10 @@ public MetarParserCommandSupplier() { commands = buildCommandList(); } - @Override public Command get(final String pString) { + @Override + public Command get(final String string) { for (Command command : commands) { - if (command.canParse(pString)) { + if (command.canParse(string)) { return command; } } diff --git a/src/main/java/io/github/mivek/command/metar/RunwayCommand.java b/metarParser-parsers/src/main/java/io/github/mivek/command/metar/RunwayCommand.java similarity index 74% rename from src/main/java/io/github/mivek/command/metar/RunwayCommand.java rename to metarParser-parsers/src/main/java/io/github/mivek/command/metar/RunwayCommand.java index 48e16e4f..e7f52c6e 100644 --- a/src/main/java/io/github/mivek/command/metar/RunwayCommand.java +++ b/metarParser-parsers/src/main/java/io/github/mivek/command/metar/RunwayCommand.java @@ -19,27 +19,35 @@ public final class RunwayCommand implements Command { /** Pattern regex for runway visibility. */ private static final Pattern RUNWAY_REGEX = Pattern.compile("^R(\\d{2}\\w?)/(\\w)?(\\d{4})(\\w{0,2})$"); - @Override public void execute(final Metar pMetar, final String pPart) { + /** + * Package private constructor. + */ + RunwayCommand() { + } + + @Override + public void execute(final Metar metar, final String part) { RunwayInfo ri = new RunwayInfo(); - String[] matches = Regex.pregMatch(RUNWAY_REGEX, pPart); + String[] matches = Regex.pregMatch(RUNWAY_REGEX, part); if (ArrayUtils.isNotEmpty(matches)) { ri.setName(matches[1]); ri.setMinRange(Integer.parseInt(matches[3])); ri.setTrend(Converter.convertTrend(matches[4])); - pMetar.addRunwayInfo(ri); + metar.addRunwayInfo(ri); } - matches = Regex.pregMatch(RUNWAY_MAX_RANGE_REGEX, pPart); + matches = Regex.pregMatch(RUNWAY_MAX_RANGE_REGEX, part); if (ArrayUtils.isNotEmpty(matches)) { ri.setName(matches[1]); ri.setMinRange(Integer.parseInt(matches[2])); ri.setMaxRange(Integer.parseInt(matches[3])); ri.setTrend(Converter.convertTrend(matches[4])); - pMetar.addRunwayInfo(ri); + metar.addRunwayInfo(ri); } } - @Override public boolean canParse(final String pInput) { - return Regex.find(GENERIC_RUNWAY_REGEX, pInput); + @Override + public boolean canParse(final String input) { + return Regex.find(GENERIC_RUNWAY_REGEX, input); } } diff --git a/metarParser-parsers/src/main/java/io/github/mivek/command/metar/TemperatureCommand.java b/metarParser-parsers/src/main/java/io/github/mivek/command/metar/TemperatureCommand.java new file mode 100644 index 00000000..9177ea41 --- /dev/null +++ b/metarParser-parsers/src/main/java/io/github/mivek/command/metar/TemperatureCommand.java @@ -0,0 +1,33 @@ +package io.github.mivek.command.metar; + +import io.github.mivek.model.Metar; +import io.github.mivek.utils.Converter; +import io.github.mivek.utils.Regex; + +import java.util.regex.Pattern; + +/** + * @author mivek + */ +public final class TemperatureCommand implements Command { + /** Pattern of the temperature block. */ + private static final Pattern TEMPERATURE_REGEX = Pattern.compile("^(M?\\d{2})/(M?\\d{2})$"); + + /** + * Package private constructor. + */ + TemperatureCommand() { + } + + @Override + public void execute(final Metar metar, final String part) { + String[] matches = Regex.pregMatch(TEMPERATURE_REGEX, part); + metar.setTemperature(Converter.convertTemperature(matches[1])); + metar.setDewPoint(Converter.convertTemperature(matches[2])); + } + + @Override + public boolean canParse(final String input) { + return Regex.find(TEMPERATURE_REGEX, input); + } +} diff --git a/src/main/java/io/github/mivek/command/metar/package-info.java b/metarParser-parsers/src/main/java/io/github/mivek/command/metar/package-info.java similarity index 100% rename from src/main/java/io/github/mivek/command/metar/package-info.java rename to metarParser-parsers/src/main/java/io/github/mivek/command/metar/package-info.java diff --git a/src/main/java/io/github/mivek/command/package-info.java b/metarParser-parsers/src/main/java/io/github/mivek/command/package-info.java similarity index 100% rename from src/main/java/io/github/mivek/command/package-info.java rename to metarParser-parsers/src/main/java/io/github/mivek/command/package-info.java diff --git a/src/main/java/io/github/mivek/command/remark/CeilingHeightCommand.java b/metarParser-parsers/src/main/java/io/github/mivek/command/remark/CeilingHeightCommand.java similarity index 59% rename from src/main/java/io/github/mivek/command/remark/CeilingHeightCommand.java rename to metarParser-parsers/src/main/java/io/github/mivek/command/remark/CeilingHeightCommand.java index 64ce778a..08817775 100644 --- a/src/main/java/io/github/mivek/command/remark/CeilingHeightCommand.java +++ b/metarParser-parsers/src/main/java/io/github/mivek/command/remark/CeilingHeightCommand.java @@ -13,24 +13,26 @@ public final class CeilingHeightCommand implements Command { private static final Pattern CEILING_HEIGHT = Pattern.compile("^CIG (\\d{3})V(\\d{3})"); /** The message instance. */ - private final Messages fMessages; + private final Messages messages; /** * Default constructor. */ CeilingHeightCommand() { - fMessages = Messages.getInstance(); + messages = Messages.getInstance(); } - @Override public String execute(final String pRemark, final StringBuilder pStringBuilder) { - String[] ceilingParts = Regex.pregMatch(CEILING_HEIGHT, pRemark); + @Override + public String execute(final String remark, final StringBuilder stringBuilder) { + String[] ceilingParts = Regex.pregMatch(CEILING_HEIGHT, remark); int min = Integer.parseInt(ceilingParts[1]) * 100; int max = Integer.parseInt(ceilingParts[2]) * 100; - pStringBuilder.append(fMessages.getString("Remark.Ceiling.Height", min, max)).append(" "); - return pRemark.replaceFirst(CEILING_HEIGHT.pattern(), "").trim(); + stringBuilder.append(messages.getString("Remark.Ceiling.Height", min, max)).append(" "); + return remark.replaceFirst(CEILING_HEIGHT.pattern(), "").trim(); } - @Override public boolean canParse(final String pInput) { - return Regex.find(CEILING_HEIGHT, pInput); + @Override + public boolean canParse(final String input) { + return Regex.find(CEILING_HEIGHT, input); } } diff --git a/src/main/java/io/github/mivek/command/remark/CeilingSecondLocationCommand.java b/metarParser-parsers/src/main/java/io/github/mivek/command/remark/CeilingSecondLocationCommand.java similarity index 57% rename from src/main/java/io/github/mivek/command/remark/CeilingSecondLocationCommand.java rename to metarParser-parsers/src/main/java/io/github/mivek/command/remark/CeilingSecondLocationCommand.java index ee36a27e..84134fe9 100644 --- a/src/main/java/io/github/mivek/command/remark/CeilingSecondLocationCommand.java +++ b/metarParser-parsers/src/main/java/io/github/mivek/command/remark/CeilingSecondLocationCommand.java @@ -13,24 +13,26 @@ public final class CeilingSecondLocationCommand implements Command { private static final Pattern CEILING_SECOND_LOCATION = Pattern.compile("^CIG (\\d{3}) (\\w+)"); /** The messages instance. */ - private Messages fMessages; + private final Messages messages; /** * Default constructor. */ CeilingSecondLocationCommand() { - fMessages = Messages.getInstance(); + messages = Messages.getInstance(); } - @Override public String execute(final String pRemark, final StringBuilder pStringBuilder) { - String[] ceilingParts = Regex.pregMatch(CEILING_SECOND_LOCATION, pRemark); + @Override + public String execute(final String remark, final StringBuilder stringBuilder) { + String[] ceilingParts = Regex.pregMatch(CEILING_SECOND_LOCATION, remark); int height = 100 * Integer.parseInt(ceilingParts[1]); String location = ceilingParts[2]; - pStringBuilder.append(fMessages.getString("Remark.Ceiling.Second.Location", height, location)).append(" "); - return pRemark.replaceFirst(CEILING_SECOND_LOCATION.pattern(), "").trim(); + stringBuilder.append(messages.getString("Remark.Ceiling.Second.Location", height, location)).append(" "); + return remark.replaceFirst(CEILING_SECOND_LOCATION.pattern(), "").trim(); } - @Override public boolean canParse(final String pInput) { - return Regex.find(CEILING_SECOND_LOCATION, pInput); + @Override + public boolean canParse(final String input) { + return Regex.find(CEILING_SECOND_LOCATION, input); } } diff --git a/metarParser-parsers/src/main/java/io/github/mivek/command/remark/Command.java b/metarParser-parsers/src/main/java/io/github/mivek/command/remark/Command.java new file mode 100644 index 00000000..4c54070e --- /dev/null +++ b/metarParser-parsers/src/main/java/io/github/mivek/command/remark/Command.java @@ -0,0 +1,33 @@ +package io.github.mivek.command.remark; + +/** + * @author mivek + */ +public interface Command { + + /** + * @param remark the remark to parse. + * @param stringBuilder the string builder containing the decoded remark + * @return the remark without the parsed part + */ + String execute(String remark, StringBuilder stringBuilder); + + /** + * Checks if the string is null. + * + * @param string the string to test + * @return empty string if null string otherwise. + */ + default String verifyString(final String string) { + if (string == null) { + return ""; + } + return string; + } + + /** + * @param input the input string to test. + * @return true if the input can be handled by the command. + */ + boolean canParse(String input); +} diff --git a/src/main/java/io/github/mivek/command/remark/DefaultCommand.java b/metarParser-parsers/src/main/java/io/github/mivek/command/remark/DefaultCommand.java similarity index 64% rename from src/main/java/io/github/mivek/command/remark/DefaultCommand.java rename to metarParser-parsers/src/main/java/io/github/mivek/command/remark/DefaultCommand.java index 08c816aa..12cda40e 100644 --- a/src/main/java/io/github/mivek/command/remark/DefaultCommand.java +++ b/metarParser-parsers/src/main/java/io/github/mivek/command/remark/DefaultCommand.java @@ -13,36 +13,38 @@ public final class DefaultCommand implements Command { private static final Logger LOGGER = Logger.getLogger(DefaultCommand.class.getName()); /** Message instance. */ - private final Messages fMessages; + private final Messages messages; /** * Constructor. */ DefaultCommand() { - fMessages = Messages.getInstance(); + messages = Messages.getInstance(); } - @Override public boolean canParse(final String pInput) { + @Override + public boolean canParse(final String input) { return true; } /** * Handle the default behavior when a remark token is not recognized by regex. * - * @param pRemark the remark string - * @param pStringBuilder The string builder containing the parsed message of the remark + * @param remark the remark string + * @param stringBuilder The string builder containing the parsed message of the remark * @return the remark string. */ - @Override public String execute(final String pRemark, final StringBuilder pStringBuilder) { - String rmk = pRemark; + @Override + public String execute(final String remark, final StringBuilder stringBuilder) { + String rmk = remark; String[] strSlit = rmk.split(" ", 2); String token = strSlit[0]; try { - token = fMessages.getString("Remark." + token); + token = messages.getString("Remark." + token); } catch (MissingResourceException e) { LOGGER.info("Remark token \"" + token + "\" is unknown."); } - pStringBuilder.append(token).append(" "); + stringBuilder.append(token).append(" "); rmk = strSlit.length == 1 ? "" : strSlit[1]; return rmk; } diff --git a/metarParser-parsers/src/main/java/io/github/mivek/command/remark/HailSizeCommand.java b/metarParser-parsers/src/main/java/io/github/mivek/command/remark/HailSizeCommand.java new file mode 100644 index 00000000..e81a3b36 --- /dev/null +++ b/metarParser-parsers/src/main/java/io/github/mivek/command/remark/HailSizeCommand.java @@ -0,0 +1,36 @@ +package io.github.mivek.command.remark; + +import io.github.mivek.internationalization.Messages; +import io.github.mivek.utils.Regex; + +import java.util.regex.Pattern; + +/** + * @author mivek + */ +public final class HailSizeCommand implements Command { + /** Hail size. */ + private static final Pattern HAIL_SIZE = Pattern.compile("^GR ((\\d/\\d)|((\\d) ?(\\d/\\d)?))"); + + /** The message instance. */ + private final Messages messages; + + /** + * Default constructor. + */ + HailSizeCommand() { + messages = Messages.getInstance(); + } + + @Override + public String execute(final String remark, final StringBuilder stringBuilder) { + String[] hailParts = Regex.pregMatch(HAIL_SIZE, remark); + stringBuilder.append(messages.getString("Remark.Hail", hailParts[1])).append(" "); + return remark.replaceFirst(HAIL_SIZE.pattern(), "").trim(); + } + + @Override + public boolean canParse(final String input) { + return Regex.find(HAIL_SIZE, input); + } +} diff --git a/metarParser-parsers/src/main/java/io/github/mivek/command/remark/ObscurationCommand.java b/metarParser-parsers/src/main/java/io/github/mivek/command/remark/ObscurationCommand.java new file mode 100644 index 00000000..d5378067 --- /dev/null +++ b/metarParser-parsers/src/main/java/io/github/mivek/command/remark/ObscurationCommand.java @@ -0,0 +1,39 @@ +package io.github.mivek.command.remark; + +import io.github.mivek.internationalization.Messages; +import io.github.mivek.utils.Regex; + +import java.util.regex.Pattern; + +/** + * @author mivek + */ +public final class ObscurationCommand implements Command { + /** Obscuration pattern. */ + private static final Pattern OBSCURATION = Pattern.compile("^([A-Z]{2}) ([A-Z]{3})(\\d{3})"); + + /** The message instance. */ + private final Messages messages; + + /** + * Default constructor. + */ + ObscurationCommand() { + messages = Messages.getInstance(); + } + + @Override + public String execute(final String remark, final StringBuilder stringBuilder) { + String[] obscuration = Regex.pregMatch(OBSCURATION, remark); + String layer = messages.getString("CloudQuantity." + obscuration[2]); + int height = Integer.parseInt(obscuration[3]) * 100; + String obscDetail = messages.getString("Phenomenon." + obscuration[1]); + stringBuilder.append(messages.getString("Remark.Obscuration", layer, height, obscDetail)).append(" "); + return remark.replaceFirst(OBSCURATION.pattern(), "").trim(); + } + + @Override + public boolean canParse(final String input) { + return Regex.find(OBSCURATION, input); + } +} diff --git a/metarParser-parsers/src/main/java/io/github/mivek/command/remark/PrecipitationBegEndCommand.java b/metarParser-parsers/src/main/java/io/github/mivek/command/remark/PrecipitationBegEndCommand.java new file mode 100644 index 00000000..c80ae84b --- /dev/null +++ b/metarParser-parsers/src/main/java/io/github/mivek/command/remark/PrecipitationBegEndCommand.java @@ -0,0 +1,38 @@ +package io.github.mivek.command.remark; + +import io.github.mivek.internationalization.Messages; +import io.github.mivek.utils.Regex; + +import java.util.regex.Pattern; + +/** + * @author mivek + */ +public final class PrecipitationBegEndCommand implements Command { + /** Beginning and ending of precipitation. */ + private static final Pattern PRECIPITATION_BEG_END = Pattern.compile("^(([A-Z]{2})?([A-Z]{2})B(\\d{2})?(\\d{2})E(\\d{2})?(\\d{2}))"); + + /** The message instance. */ + private final Messages messages; + + /** + * Default constructor. + */ + PrecipitationBegEndCommand() { + messages = Messages.getInstance(); + } + + @Override + public String execute(final String remark, final StringBuilder stringBuilder) { + String[] precipitationBegEnd = Regex.pregMatch(PRECIPITATION_BEG_END, remark); + stringBuilder.append(messages.getString("Remark.Precipitation.Beg.End", precipitationBegEnd[2] == null ? "" : messages.getString("Descriptive." + precipitationBegEnd[2]), + messages.getString("Phenomenon." + precipitationBegEnd[3]), verifyString(precipitationBegEnd[4]), precipitationBegEnd[5], verifyString(precipitationBegEnd[6]), precipitationBegEnd[7])) + .append(" "); + return remark.replaceFirst(PRECIPITATION_BEG_END.pattern(), "").trim(); + } + + @Override + public boolean canParse(final String input) { + return Regex.find(PRECIPITATION_BEG_END, input); + } +} diff --git a/src/main/java/io/github/mivek/command/remark/PrevailingVisibilityCommand.java b/metarParser-parsers/src/main/java/io/github/mivek/command/remark/PrevailingVisibilityCommand.java similarity index 52% rename from src/main/java/io/github/mivek/command/remark/PrevailingVisibilityCommand.java rename to metarParser-parsers/src/main/java/io/github/mivek/command/remark/PrevailingVisibilityCommand.java index 282a9431..0a2bd971 100644 --- a/src/main/java/io/github/mivek/command/remark/PrevailingVisibilityCommand.java +++ b/metarParser-parsers/src/main/java/io/github/mivek/command/remark/PrevailingVisibilityCommand.java @@ -12,22 +12,24 @@ public final class PrevailingVisibilityCommand implements Command { /** Variable prevailing visibility. */ private static final Pattern VARIABLE_PREVAILING_VISIBILITY = Pattern.compile("^VIS ((\\d)*( )?(\\d?/?\\d))V((\\d)*( )?(\\d?/?\\d))"); /** The message instance. */ - private final Messages fMessages; + private final Messages messages; /** * Default constructor. */ PrevailingVisibilityCommand() { - fMessages = Messages.getInstance(); + messages = Messages.getInstance(); } - @Override public String execute(final String pRemark, final StringBuilder pStringBuilder) { - String[] visibilityParts = Regex.pregMatch(VARIABLE_PREVAILING_VISIBILITY, pRemark); - pStringBuilder.append(fMessages.getString("Remark.Variable.Prevailing.Visibility", visibilityParts[1], visibilityParts[5])).append(" "); - return pRemark.replaceFirst(VARIABLE_PREVAILING_VISIBILITY.pattern(), "").trim(); + @Override + public String execute(final String remark, final StringBuilder stringBuilder) { + String[] visibilityParts = Regex.pregMatch(VARIABLE_PREVAILING_VISIBILITY, remark); + stringBuilder.append(messages.getString("Remark.Variable.Prevailing.Visibility", visibilityParts[1], visibilityParts[5])).append(" "); + return remark.replaceFirst(VARIABLE_PREVAILING_VISIBILITY.pattern(), "").trim(); } - @Override public boolean canParse(final String pInput) { - return Regex.find(VARIABLE_PREVAILING_VISIBILITY, pInput); + @Override + public boolean canParse(final String input) { + return Regex.find(VARIABLE_PREVAILING_VISIBILITY, input); } } diff --git a/src/main/java/io/github/mivek/command/remark/RemarkCommandSupplier.java b/metarParser-parsers/src/main/java/io/github/mivek/command/remark/RemarkCommandSupplier.java similarity index 95% rename from src/main/java/io/github/mivek/command/remark/RemarkCommandSupplier.java rename to metarParser-parsers/src/main/java/io/github/mivek/command/remark/RemarkCommandSupplier.java index 1389dac3..243b9cf7 100644 --- a/src/main/java/io/github/mivek/command/remark/RemarkCommandSupplier.java +++ b/metarParser-parsers/src/main/java/io/github/mivek/command/remark/RemarkCommandSupplier.java @@ -23,9 +23,10 @@ public RemarkCommandSupplier() { commands = buildCommandList(); } - @Override public Command get(final String pString) { + @Override + public Command get(final String string) { for (Command command : commands) { - if (command.canParse(pString)) { + if (command.canParse(string)) { return command; } } diff --git a/src/main/java/io/github/mivek/command/remark/SeaLevelPressureCommand.java b/metarParser-parsers/src/main/java/io/github/mivek/command/remark/SeaLevelPressureCommand.java similarity index 63% rename from src/main/java/io/github/mivek/command/remark/SeaLevelPressureCommand.java rename to metarParser-parsers/src/main/java/io/github/mivek/command/remark/SeaLevelPressureCommand.java index 0a916ce4..ae88f56a 100644 --- a/src/main/java/io/github/mivek/command/remark/SeaLevelPressureCommand.java +++ b/metarParser-parsers/src/main/java/io/github/mivek/command/remark/SeaLevelPressureCommand.java @@ -13,17 +13,18 @@ public final class SeaLevelPressureCommand implements Command { private static final Pattern SEAL_LEVEL_PRESSURE = Pattern.compile("^SLP(\\d{2})(\\d)"); /** The message instance. */ - private Messages fMessages; + private final Messages messages; /** * Default constructor. */ SeaLevelPressureCommand() { - fMessages = Messages.getInstance(); + messages = Messages.getInstance(); } - @Override public String execute(final String pRemark, final StringBuilder pStringBuilder) { - String[] sealevelParts = Regex.pregMatch(SEAL_LEVEL_PRESSURE, pRemark); + @Override + public String execute(final String remark, final StringBuilder stringBuilder) { + String[] sealevelParts = Regex.pregMatch(SEAL_LEVEL_PRESSURE, remark); StringBuilder pressure = new StringBuilder(); if (sealevelParts[1].startsWith("9")) { pressure.append("9"); @@ -31,12 +32,13 @@ public final class SeaLevelPressureCommand implements Command { pressure.append("10"); } pressure.append(sealevelParts[1]).append(".").append(sealevelParts[2]); - pStringBuilder.append(fMessages.getString("Remark.Sea.Level.Pressure", pressure)).append(" "); - return pRemark.replaceFirst(SEAL_LEVEL_PRESSURE.pattern(), "").trim(); + stringBuilder.append(messages.getString("Remark.Sea.Level.Pressure", pressure)).append(" "); + return remark.replaceFirst(SEAL_LEVEL_PRESSURE.pattern(), "").trim(); } - @Override public boolean canParse(final String pInput) { - return Regex.find(SEAL_LEVEL_PRESSURE, pInput); + @Override + public boolean canParse(final String input) { + return Regex.find(SEAL_LEVEL_PRESSURE, input); } } diff --git a/src/main/java/io/github/mivek/command/remark/SecondLocationVisibilityCommand.java b/metarParser-parsers/src/main/java/io/github/mivek/command/remark/SecondLocationVisibilityCommand.java similarity index 51% rename from src/main/java/io/github/mivek/command/remark/SecondLocationVisibilityCommand.java rename to metarParser-parsers/src/main/java/io/github/mivek/command/remark/SecondLocationVisibilityCommand.java index d798b916..598eac69 100644 --- a/src/main/java/io/github/mivek/command/remark/SecondLocationVisibilityCommand.java +++ b/metarParser-parsers/src/main/java/io/github/mivek/command/remark/SecondLocationVisibilityCommand.java @@ -14,22 +14,24 @@ public final class SecondLocationVisibilityCommand implements Command { private static final Pattern SECOND_LOCATION_VISIBILITY = Pattern.compile("^VIS ((\\d)*( )?(\\d?/?\\d)) (\\w+)"); /** The message instance. */ - private final Messages fMessages; + private final Messages messages; /** * Default constructor. */ SecondLocationVisibilityCommand() { - fMessages = Messages.getInstance(); + messages = Messages.getInstance(); } - @Override public String execute(final String pRemark, final StringBuilder pStringBuilder) { - String[] secondLocationVisibilityParts = Regex.pregMatch(SECOND_LOCATION_VISIBILITY, pRemark); - pStringBuilder.append(fMessages.getString("Remark.Second.Location.Visibility", secondLocationVisibilityParts[1], secondLocationVisibilityParts[5])).append(" "); - return pRemark.replaceFirst(SECOND_LOCATION_VISIBILITY.pattern(), "").trim(); + @Override + public String execute(final String remark, final StringBuilder stringBuilder) { + String[] secondLocationVisibilityParts = Regex.pregMatch(SECOND_LOCATION_VISIBILITY, remark); + stringBuilder.append(messages.getString("Remark.Second.Location.Visibility", secondLocationVisibilityParts[1], secondLocationVisibilityParts[5])).append(" "); + return remark.replaceFirst(SECOND_LOCATION_VISIBILITY.pattern(), "").trim(); } - @Override public boolean canParse(final String pInput) { - return Regex.find(SECOND_LOCATION_VISIBILITY, pInput); + @Override + public boolean canParse(final String input) { + return Regex.find(SECOND_LOCATION_VISIBILITY, input); } } diff --git a/src/main/java/io/github/mivek/command/remark/SectorVisibilityCommand.java b/metarParser-parsers/src/main/java/io/github/mivek/command/remark/SectorVisibilityCommand.java similarity index 50% rename from src/main/java/io/github/mivek/command/remark/SectorVisibilityCommand.java rename to metarParser-parsers/src/main/java/io/github/mivek/command/remark/SectorVisibilityCommand.java index ec4981ba..5955918d 100644 --- a/src/main/java/io/github/mivek/command/remark/SectorVisibilityCommand.java +++ b/metarParser-parsers/src/main/java/io/github/mivek/command/remark/SectorVisibilityCommand.java @@ -13,22 +13,24 @@ public final class SectorVisibilityCommand implements Command { private static final Pattern SECTOR_VISIBILITY = Pattern.compile("^VIS ([A-Z]{1,2}) ((\\d)*( )?(\\d?/?\\d))"); /** The message instance. */ - private final Messages fMessages; + private final Messages messages; /** * Default constrctor. */ SectorVisibilityCommand() { - fMessages = Messages.getInstance(); + messages = Messages.getInstance(); } - @Override public String execute(final String pRemark, final StringBuilder pStringBuilder) { - String[] sectorVisibilityParts = Regex.pregMatch(SECTOR_VISIBILITY, pRemark); - pStringBuilder.append(fMessages.getString("Remark.Sector.Visibility", fMessages.getString("Converter." + sectorVisibilityParts[1]), sectorVisibilityParts[2])).append(" "); - return pRemark.replaceFirst(SECTOR_VISIBILITY.pattern(), "").trim(); + @Override + public String execute(final String remark, final StringBuilder stringBuilder) { + String[] sectorVisibilityParts = Regex.pregMatch(SECTOR_VISIBILITY, remark); + stringBuilder.append(messages.getString("Remark.Sector.Visibility", messages.getString("Converter." + sectorVisibilityParts[1]), sectorVisibilityParts[2])).append(" "); + return remark.replaceFirst(SECTOR_VISIBILITY.pattern(), "").trim(); } - @Override public boolean canParse(final String pInput) { - return Regex.find(SECTOR_VISIBILITY, pInput); + @Override + public boolean canParse(final String input) { + return Regex.find(SECTOR_VISIBILITY, input); } } diff --git a/src/main/java/io/github/mivek/command/remark/SmallHailSizeCommand.java b/metarParser-parsers/src/main/java/io/github/mivek/command/remark/SmallHailSizeCommand.java similarity index 54% rename from src/main/java/io/github/mivek/command/remark/SmallHailSizeCommand.java rename to metarParser-parsers/src/main/java/io/github/mivek/command/remark/SmallHailSizeCommand.java index 8a9ef0d2..bb6fb6a6 100644 --- a/src/main/java/io/github/mivek/command/remark/SmallHailSizeCommand.java +++ b/metarParser-parsers/src/main/java/io/github/mivek/command/remark/SmallHailSizeCommand.java @@ -12,24 +12,25 @@ public final class SmallHailSizeCommand implements Command { /** Hail size less than. */ private static final Pattern HAIL_SIZE_LESS_THAN = Pattern.compile("^GR LESS THAN ((\\d )?(\\d/\\d)?)"); - /** The message instance. */ - private final Messages fMessages; + private final Messages messages; /** * Default constructor. */ SmallHailSizeCommand() { - fMessages = Messages.getInstance(); + messages = Messages.getInstance(); } - @Override public String execute(final String pRemark, final StringBuilder pStringBuilder) { - String[] hailParts = Regex.pregMatch(HAIL_SIZE_LESS_THAN, pRemark); - pStringBuilder.append(fMessages.getString("Remark.Hail.LesserThan", hailParts[1])).append(" "); - return pRemark.replaceFirst(HAIL_SIZE_LESS_THAN.pattern(), "").trim(); + @Override + public String execute(final String remark, final StringBuilder stringBuilder) { + String[] hailParts = Regex.pregMatch(HAIL_SIZE_LESS_THAN, remark); + stringBuilder.append(messages.getString("Remark.Hail.LesserThan", hailParts[1])).append(" "); + return remark.replaceFirst(HAIL_SIZE_LESS_THAN.pattern(), "").trim(); } - @Override public boolean canParse(final String pInput) { - return Regex.find(HAIL_SIZE_LESS_THAN, pInput); + @Override + public boolean canParse(final String input) { + return Regex.find(HAIL_SIZE_LESS_THAN, input); } } diff --git a/src/main/java/io/github/mivek/command/remark/SnowIncreaseCommand.java b/metarParser-parsers/src/main/java/io/github/mivek/command/remark/SnowIncreaseCommand.java similarity index 53% rename from src/main/java/io/github/mivek/command/remark/SnowIncreaseCommand.java rename to metarParser-parsers/src/main/java/io/github/mivek/command/remark/SnowIncreaseCommand.java index 898e8298..a649ee08 100644 --- a/src/main/java/io/github/mivek/command/remark/SnowIncreaseCommand.java +++ b/metarParser-parsers/src/main/java/io/github/mivek/command/remark/SnowIncreaseCommand.java @@ -13,22 +13,24 @@ public final class SnowIncreaseCommand implements Command { private static final Pattern SNOW_INCR_RAPIDLY = Pattern.compile("^SNINCR (\\d+)/(\\d+)"); /** The message instance. */ - private final Messages fMessages; + private final Messages messages; /** * Default constructor. */ SnowIncreaseCommand() { - fMessages = Messages.getInstance(); + messages = Messages.getInstance(); } - @Override public String execute(final String pRemark, final StringBuilder pStringBuilder) { - String[] snowParts = Regex.pregMatch(SNOW_INCR_RAPIDLY, pRemark); - pStringBuilder.append(fMessages.getString("Remark.Snow.Increasing.Rapidly", snowParts[1], snowParts[2])).append(" "); - return pRemark.replaceFirst(SNOW_INCR_RAPIDLY.pattern(), "").trim(); + @Override + public String execute(final String remark, final StringBuilder stringBuilder) { + String[] snowParts = Regex.pregMatch(SNOW_INCR_RAPIDLY, remark); + stringBuilder.append(messages.getString("Remark.Snow.Increasing.Rapidly", snowParts[1], snowParts[2])).append(" "); + return remark.replaceFirst(SNOW_INCR_RAPIDLY.pattern(), "").trim(); } - @Override public boolean canParse(final String pInput) { - return Regex.find(SNOW_INCR_RAPIDLY, pInput); + @Override + public boolean canParse(final String input) { + return Regex.find(SNOW_INCR_RAPIDLY, input); } } diff --git a/src/main/java/io/github/mivek/command/remark/SnowPelletsCommand.java b/metarParser-parsers/src/main/java/io/github/mivek/command/remark/SnowPelletsCommand.java similarity index 51% rename from src/main/java/io/github/mivek/command/remark/SnowPelletsCommand.java rename to metarParser-parsers/src/main/java/io/github/mivek/command/remark/SnowPelletsCommand.java index c1f24528..e907eb92 100644 --- a/src/main/java/io/github/mivek/command/remark/SnowPelletsCommand.java +++ b/metarParser-parsers/src/main/java/io/github/mivek/command/remark/SnowPelletsCommand.java @@ -13,22 +13,24 @@ public final class SnowPelletsCommand implements Command { private static final Pattern SNOW_PELLETS_INTENSITY = Pattern.compile("^GS (LGT|MOD|HVY)"); /** The message instance. */ - private final Messages fMessages; + private final Messages messages; /** * Default constructor. */ SnowPelletsCommand() { - fMessages = Messages.getInstance(); + messages = Messages.getInstance(); } - @Override public String execute(final String pRemark, final StringBuilder pStringBuilder) { - String[] intensityParts = Regex.pregMatch(SNOW_PELLETS_INTENSITY, pRemark); - pStringBuilder.append(fMessages.getString("Remark.Snow.Pellets", fMessages.getString("Remark." + intensityParts[1]))).append(" "); - return pRemark.replaceFirst(SNOW_PELLETS_INTENSITY.pattern(), "").trim(); + @Override + public String execute(final String remark, final StringBuilder stringBuilder) { + String[] intensityParts = Regex.pregMatch(SNOW_PELLETS_INTENSITY, remark); + stringBuilder.append(messages.getString("Remark.Snow.Pellets", messages.getString("Remark." + intensityParts[1]))).append(" "); + return remark.replaceFirst(SNOW_PELLETS_INTENSITY.pattern(), "").trim(); } - @Override public boolean canParse(final String pInput) { - return Regex.find(SNOW_PELLETS_INTENSITY, pInput); + @Override + public boolean canParse(final String input) { + return Regex.find(SNOW_PELLETS_INTENSITY, input); } } diff --git a/src/main/java/io/github/mivek/command/remark/SurfaceVisibilityCommand.java b/metarParser-parsers/src/main/java/io/github/mivek/command/remark/SurfaceVisibilityCommand.java similarity index 53% rename from src/main/java/io/github/mivek/command/remark/SurfaceVisibilityCommand.java rename to metarParser-parsers/src/main/java/io/github/mivek/command/remark/SurfaceVisibilityCommand.java index 157cdb5d..19875262 100644 --- a/src/main/java/io/github/mivek/command/remark/SurfaceVisibilityCommand.java +++ b/metarParser-parsers/src/main/java/io/github/mivek/command/remark/SurfaceVisibilityCommand.java @@ -13,22 +13,24 @@ public final class SurfaceVisibilityCommand implements Command { private static final Pattern SURFACE_VISIBILITY = Pattern.compile("^SFC VIS ((\\d)*( )?(\\d?/?\\d))"); /** The messages instance. */ - private final Messages fMessages; + private final Messages messages; /** * Default constructor. */ SurfaceVisibilityCommand() { - fMessages = Messages.getInstance(); + messages = Messages.getInstance(); } - @Override public String execute(final String pRemark, final StringBuilder pStringBuilder) { - String[] surfaceVisivilityParts = Regex.pregMatch(SURFACE_VISIBILITY, pRemark); - pStringBuilder.append(fMessages.getString("Remark.Surface.Visibility", surfaceVisivilityParts[1])).append(" "); - return pRemark.replaceFirst(SURFACE_VISIBILITY.pattern(), "").trim(); + @Override + public String execute(final String remark, final StringBuilder stringBuilder) { + String[] surfaceVisivilityParts = Regex.pregMatch(SURFACE_VISIBILITY, remark); + stringBuilder.append(messages.getString("Remark.Surface.Visibility", surfaceVisivilityParts[1])).append(" "); + return remark.replaceFirst(SURFACE_VISIBILITY.pattern(), "").trim(); } - @Override public boolean canParse(final String pInput) { - return Regex.find(SURFACE_VISIBILITY, pInput); + @Override + public boolean canParse(final String input) { + return Regex.find(SURFACE_VISIBILITY, input); } } diff --git a/src/main/java/io/github/mivek/command/remark/ThunderStormLocationCommand.java b/metarParser-parsers/src/main/java/io/github/mivek/command/remark/ThunderStormLocationCommand.java similarity index 51% rename from src/main/java/io/github/mivek/command/remark/ThunderStormLocationCommand.java rename to metarParser-parsers/src/main/java/io/github/mivek/command/remark/ThunderStormLocationCommand.java index 217bb595..21555115 100644 --- a/src/main/java/io/github/mivek/command/remark/ThunderStormLocationCommand.java +++ b/metarParser-parsers/src/main/java/io/github/mivek/command/remark/ThunderStormLocationCommand.java @@ -14,22 +14,24 @@ public final class ThunderStormLocationCommand implements Command { private static final Pattern THUNDERSTORM_LOCATION = Pattern.compile("^TS ([A-Z]{2})"); /** The message instance. */ - private final Messages fMessages; + private final Messages messages; /** * Default constructor. */ ThunderStormLocationCommand() { - fMessages = Messages.getInstance(); + messages = Messages.getInstance(); } - @Override public String execute(final String pRemark, final StringBuilder pStringBuilder) { - String[] thunderStormParts = Regex.pregMatch(THUNDERSTORM_LOCATION, pRemark); - pStringBuilder.append(fMessages.getString("Remark.Thunderstorm.Location", fMessages.getString("Converter." + thunderStormParts[1]))).append(" "); - return pRemark.replaceFirst(THUNDERSTORM_LOCATION.pattern(), "").trim(); + @Override + public String execute(final String remark, final StringBuilder stringBuilder) { + String[] thunderStormParts = Regex.pregMatch(THUNDERSTORM_LOCATION, remark); + stringBuilder.append(messages.getString("Remark.Thunderstorm.Location", messages.getString("Converter." + thunderStormParts[1]))).append(" "); + return remark.replaceFirst(THUNDERSTORM_LOCATION.pattern(), "").trim(); } - @Override public boolean canParse(final String pInput) { - return Regex.find(THUNDERSTORM_LOCATION, pInput); + @Override + public boolean canParse(final String input) { + return Regex.find(THUNDERSTORM_LOCATION, input); } } diff --git a/src/main/java/io/github/mivek/command/remark/ThunderStormLocationMovingCommand.java b/metarParser-parsers/src/main/java/io/github/mivek/command/remark/ThunderStormLocationMovingCommand.java similarity index 50% rename from src/main/java/io/github/mivek/command/remark/ThunderStormLocationMovingCommand.java rename to metarParser-parsers/src/main/java/io/github/mivek/command/remark/ThunderStormLocationMovingCommand.java index c8df298c..b037bf20 100644 --- a/src/main/java/io/github/mivek/command/remark/ThunderStormLocationMovingCommand.java +++ b/metarParser-parsers/src/main/java/io/github/mivek/command/remark/ThunderStormLocationMovingCommand.java @@ -13,24 +13,26 @@ public final class ThunderStormLocationMovingCommand implements Command { private static final Pattern THUNDERSTORM_LOCATION_MOVING = Pattern.compile("^TS ([A-Z]{2}) MOV ([A-Z]{2})"); /** The message instance. */ - private final Messages fMessages; + private final Messages messages; /** * Default constructor. */ ThunderStormLocationMovingCommand() { - fMessages = Messages.getInstance(); + messages = Messages.getInstance(); } - @Override public String execute(final String pRemark, final StringBuilder pStringBuilder) { - String[] thunderStormParts = Regex.pregMatch(THUNDERSTORM_LOCATION_MOVING, pRemark); - pStringBuilder - .append(fMessages.getString("Remark.Thunderstorm.Location.Moving", fMessages.getString("Converter." + thunderStormParts[1]), fMessages.getString("Converter." + thunderStormParts[2]))) + @Override + public String execute(final String remark, final StringBuilder stringBuilder) { + String[] thunderStormParts = Regex.pregMatch(THUNDERSTORM_LOCATION_MOVING, remark); + stringBuilder + .append(messages.getString("Remark.Thunderstorm.Location.Moving", messages.getString("Converter." + thunderStormParts[1]), messages.getString("Converter." + thunderStormParts[2]))) .append(" "); - return pRemark.replaceFirst(THUNDERSTORM_LOCATION_MOVING.pattern(), "").trim(); + return remark.replaceFirst(THUNDERSTORM_LOCATION_MOVING.pattern(), "").trim(); } - @Override public boolean canParse(final String pInput) { - return Regex.find(THUNDERSTORM_LOCATION_MOVING, pInput); + @Override + public boolean canParse(final String input) { + return Regex.find(THUNDERSTORM_LOCATION_MOVING, input); } } diff --git a/src/main/java/io/github/mivek/command/remark/TornadicActivityBegCommand.java b/metarParser-parsers/src/main/java/io/github/mivek/command/remark/TornadicActivityBegCommand.java similarity index 51% rename from src/main/java/io/github/mivek/command/remark/TornadicActivityBegCommand.java rename to metarParser-parsers/src/main/java/io/github/mivek/command/remark/TornadicActivityBegCommand.java index ab26e6f1..511d3f51 100644 --- a/src/main/java/io/github/mivek/command/remark/TornadicActivityBegCommand.java +++ b/metarParser-parsers/src/main/java/io/github/mivek/command/remark/TornadicActivityBegCommand.java @@ -12,24 +12,26 @@ public final class TornadicActivityBegCommand implements Command { /** Tornadic activity with beginning time. */ private static final Pattern TORNADIC_ACTIVITY_BEGINNING = Pattern.compile("^(TORNADO|FUNNEL CLOUD|WATERSPOUT) (B(\\d{2})?(\\d{2}))( (\\d+)? ([A-Z]{1,2})?)?"); /** The message instance. */ - private final Messages fMessages; + private final Messages messages; /** * Default constructor. */ TornadicActivityBegCommand() { - fMessages = Messages.getInstance(); + messages = Messages.getInstance(); } - @Override public String execute(final String pRemark, final StringBuilder pStringBuilder) { - String[] tornadicParts = Regex.pregMatch(TORNADIC_ACTIVITY_BEGINNING, pRemark); - pStringBuilder.append(fMessages - .getString("Remark.Tornadic.Activity.Beginning", fMessages.getString("Remark." + tornadicParts[1].replace(" ", "")), verifyString(tornadicParts[3]), tornadicParts[4], tornadicParts[6], - fMessages.getString("Converter." + tornadicParts[7]))).append(" "); - return pRemark.replaceFirst(TORNADIC_ACTIVITY_BEGINNING.pattern(), "").trim(); + @Override + public String execute(final String remark, final StringBuilder stringBuilder) { + String[] tornadicParts = Regex.pregMatch(TORNADIC_ACTIVITY_BEGINNING, remark); + stringBuilder.append(messages + .getString("Remark.Tornadic.Activity.Beginning", messages.getString("Remark." + tornadicParts[1].replace(" ", "")), verifyString(tornadicParts[3]), tornadicParts[4], tornadicParts[6], + messages.getString("Converter." + tornadicParts[7]))).append(" "); + return remark.replaceFirst(TORNADIC_ACTIVITY_BEGINNING.pattern(), "").trim(); } - @Override public boolean canParse(final String pInput) { - return Regex.find(TORNADIC_ACTIVITY_BEGINNING, pInput); + @Override + public boolean canParse(final String input) { + return Regex.find(TORNADIC_ACTIVITY_BEGINNING, input); } } diff --git a/metarParser-parsers/src/main/java/io/github/mivek/command/remark/TornadicActivityBegEndCommand.java b/metarParser-parsers/src/main/java/io/github/mivek/command/remark/TornadicActivityBegEndCommand.java new file mode 100644 index 00000000..2c30dcb8 --- /dev/null +++ b/metarParser-parsers/src/main/java/io/github/mivek/command/remark/TornadicActivityBegEndCommand.java @@ -0,0 +1,37 @@ +package io.github.mivek.command.remark; + +import io.github.mivek.internationalization.Messages; +import io.github.mivek.utils.Regex; + +import java.util.regex.Pattern; + +/** + * @author mivek + */ +public final class TornadicActivityBegEndCommand implements Command { + /** Tornadic activity with beginning and ending time. */ + private static final Pattern TORNADIC_ACTIVITY_BEG_END = Pattern.compile("^(TORNADO|FUNNEL CLOUD|WATERSPOUT) (B(\\d{2})?(\\d{2}))(E(\\d{2})?(\\d{2}))( (\\d+)? ([A-Z]{1,2})?)?"); + + /** The message instance. */ + private final Messages messages; + + /** + * Default constructor. + */ + TornadicActivityBegEndCommand() { + messages = Messages.getInstance(); + } + + @Override + public String execute(final String remark, final StringBuilder stringBuilder) { + String[] tornadicParts = Regex.pregMatch(TORNADIC_ACTIVITY_BEG_END, remark); + stringBuilder.append(messages.getString("Remark.Tornadic.Activity.BegEnd", messages.getString("Remark." + tornadicParts[1].replace(" ", "")), verifyString(tornadicParts[3]), tornadicParts[4], + verifyString(tornadicParts[6]), tornadicParts[7], tornadicParts[9], messages.getString("Converter." + tornadicParts[10]))).append(" "); + return remark.replaceFirst(TORNADIC_ACTIVITY_BEG_END.pattern(), "").trim(); + } + + @Override + public boolean canParse(final String input) { + return Regex.find(TORNADIC_ACTIVITY_BEG_END, input); + } +} diff --git a/metarParser-parsers/src/main/java/io/github/mivek/command/remark/TornadicActivityEndCommand.java b/metarParser-parsers/src/main/java/io/github/mivek/command/remark/TornadicActivityEndCommand.java new file mode 100644 index 00000000..6b3a785c --- /dev/null +++ b/metarParser-parsers/src/main/java/io/github/mivek/command/remark/TornadicActivityEndCommand.java @@ -0,0 +1,38 @@ +package io.github.mivek.command.remark; + +import io.github.mivek.internationalization.Messages; +import io.github.mivek.utils.Regex; + +import java.util.regex.Pattern; + +/** + * @author mivek + */ +public final class TornadicActivityEndCommand implements Command { + /** Tornadic activity with ending time. */ + private static final Pattern TORNADIC_ACTIVITY_ENDING = Pattern.compile("^(TORNADO|FUNNEL CLOUD|WATERSPOUT) (E(\\d{2})?(\\d{2}))( (\\d+)? ([A-Z]{1,2})?)?"); + + /** The message instance. */ + private final Messages messages; + + /** + * Default constructor. + */ + TornadicActivityEndCommand() { + messages = Messages.getInstance(); + } + + @Override + public String execute(final String remark, final StringBuilder stringBuilder) { + String[] tornadicParts = Regex.pregMatch(TORNADIC_ACTIVITY_ENDING, remark); + stringBuilder.append(messages + .getString("Remark.Tornadic.Activity.Ending", messages.getString("Remark." + tornadicParts[1].replace(" ", "")), verifyString(tornadicParts[3]), tornadicParts[4], tornadicParts[6], + messages.getString("Converter." + tornadicParts[7]))).append(" "); + return remark.replaceFirst(TORNADIC_ACTIVITY_ENDING.pattern(), "").trim(); + } + + @Override + public boolean canParse(final String input) { + return Regex.find(TORNADIC_ACTIVITY_ENDING, input); + } +} diff --git a/src/main/java/io/github/mivek/command/remark/TowerVisibilityCommand.java b/metarParser-parsers/src/main/java/io/github/mivek/command/remark/TowerVisibilityCommand.java similarity index 53% rename from src/main/java/io/github/mivek/command/remark/TowerVisibilityCommand.java rename to metarParser-parsers/src/main/java/io/github/mivek/command/remark/TowerVisibilityCommand.java index a328421c..27c570af 100644 --- a/src/main/java/io/github/mivek/command/remark/TowerVisibilityCommand.java +++ b/metarParser-parsers/src/main/java/io/github/mivek/command/remark/TowerVisibilityCommand.java @@ -13,22 +13,24 @@ public final class TowerVisibilityCommand implements Command { private static final Pattern TOWER_VISIBILITY = Pattern.compile("^TWR VIS ((\\d)*( )?(\\d?/?\\d))"); /** The messages instance. */ - private final Messages fMessages; + private final Messages messages; /** * Default constructor. */ TowerVisibilityCommand() { - fMessages = Messages.getInstance(); + messages = Messages.getInstance(); } - @Override public String execute(final String pRemark, final StringBuilder pStringBuilder) { - String[] towerVisibilityParts = Regex.pregMatch(TOWER_VISIBILITY, pRemark); - pStringBuilder.append(fMessages.getString("Remark.Tower.Visibility", towerVisibilityParts[1])).append(" "); - return pRemark.replaceFirst(TOWER_VISIBILITY.pattern(), "").trim(); + @Override + public String execute(final String remark, final StringBuilder stringBuilder) { + String[] towerVisibilityParts = Regex.pregMatch(TOWER_VISIBILITY, remark); + stringBuilder.append(messages.getString("Remark.Tower.Visibility", towerVisibilityParts[1])).append(" "); + return remark.replaceFirst(TOWER_VISIBILITY.pattern(), "").trim(); } - @Override public boolean canParse(final String pInput) { - return Regex.find(TOWER_VISIBILITY, pInput); + @Override + public boolean canParse(final String input) { + return Regex.find(TOWER_VISIBILITY, input); } } diff --git a/metarParser-parsers/src/main/java/io/github/mivek/command/remark/VariableSkyCommand.java b/metarParser-parsers/src/main/java/io/github/mivek/command/remark/VariableSkyCommand.java new file mode 100644 index 00000000..0e0cf331 --- /dev/null +++ b/metarParser-parsers/src/main/java/io/github/mivek/command/remark/VariableSkyCommand.java @@ -0,0 +1,39 @@ +package io.github.mivek.command.remark; + +import io.github.mivek.internationalization.Messages; +import io.github.mivek.utils.Regex; + +import java.util.regex.Pattern; + +/** + * @author mivek + */ +public final class VariableSkyCommand implements Command { + /** Variable sky condition. */ + private static final Pattern VARIABLE_SKY = Pattern.compile("^([A-Z]{3}) V ([A-Z]{3})"); + + /** The messages instance. */ + private final Messages messages; + + /** + * Default constructor. + */ + VariableSkyCommand() { + messages = Messages.getInstance(); + } + + @Override + public String execute(final String remark, final StringBuilder stringBuilder) { + String[] variableSky = Regex.pregMatch(VARIABLE_SKY, remark); + String layer1 = messages.getString("CloudQuantity." + variableSky[1]); + String layer2 = messages.getString("CloudQuantity." + variableSky[2]); + stringBuilder.append(messages.getString("Remark.Variable.Sky.Condition", layer1, layer2)).append(" "); + return remark.replaceFirst(VARIABLE_SKY.pattern(), "").trim(); + } + + @Override + public boolean canParse(final String input) { + return Regex.find(VARIABLE_SKY, input); + } +} + diff --git a/metarParser-parsers/src/main/java/io/github/mivek/command/remark/VariableSkyHeightCommand.java b/metarParser-parsers/src/main/java/io/github/mivek/command/remark/VariableSkyHeightCommand.java new file mode 100644 index 00000000..250c8294 --- /dev/null +++ b/metarParser-parsers/src/main/java/io/github/mivek/command/remark/VariableSkyHeightCommand.java @@ -0,0 +1,39 @@ +package io.github.mivek.command.remark; + +import io.github.mivek.internationalization.Messages; +import io.github.mivek.utils.Regex; + +import java.util.regex.Pattern; + +/** + * @author mivek + */ +public final class VariableSkyHeightCommand implements Command { + /** Variable sky condition with height. */ + private static final Pattern VARIABLE_SKY_HEIGHT = Pattern.compile("^([A-Z]{3})(\\d{3}) V ([A-Z]{3})"); + + /** The message instance. */ + private final Messages messages; + + /** + * Default constructor. + */ + VariableSkyHeightCommand() { + messages = Messages.getInstance(); + } + + @Override + public String execute(final String remark, final StringBuilder stringBuilder) { + String[] variableSky = Regex.pregMatch(VARIABLE_SKY_HEIGHT, remark); + String layer1 = messages.getString("CloudQuantity." + variableSky[1]); + int height = Integer.parseInt(variableSky[2]) * 100; + String layer2 = messages.getString("CloudQuantity." + variableSky[3]); + stringBuilder.append(messages.getString("Remark.Variable.Sky.Condition.Height", height, layer1, layer2)).append(" "); + return remark.replaceFirst(VARIABLE_SKY_HEIGHT.pattern(), "").trim(); + } + + @Override + public boolean canParse(final String input) { + return Regex.find(VARIABLE_SKY_HEIGHT, input); + } +} diff --git a/src/main/java/io/github/mivek/command/remark/VirgaDirectionCommand.java b/metarParser-parsers/src/main/java/io/github/mivek/command/remark/VirgaDirectionCommand.java similarity index 52% rename from src/main/java/io/github/mivek/command/remark/VirgaDirectionCommand.java rename to metarParser-parsers/src/main/java/io/github/mivek/command/remark/VirgaDirectionCommand.java index ac2825c6..f731ed36 100644 --- a/src/main/java/io/github/mivek/command/remark/VirgaDirectionCommand.java +++ b/metarParser-parsers/src/main/java/io/github/mivek/command/remark/VirgaDirectionCommand.java @@ -13,22 +13,24 @@ public final class VirgaDirectionCommand implements Command { private static final Pattern VIRGA_DIRECTION = Pattern.compile("^VIRGA ([A-Z]{2})"); /** The message instance. */ - private final Messages fMessages; + private final Messages messages; /** * Default constructor. */ VirgaDirectionCommand() { - fMessages = Messages.getInstance(); + messages = Messages.getInstance(); } - @Override public String execute(final String pRemark, final StringBuilder pStringBuilder) { - String[] virgaDirection = Regex.pregMatch(VIRGA_DIRECTION, pRemark); - pStringBuilder.append(fMessages.getString("Remark.Virga.Direction", fMessages.getString("Converter." + virgaDirection[1]))).append(" "); - return pRemark.replaceFirst(VIRGA_DIRECTION.pattern(), "").trim(); + @Override + public String execute(final String remark, final StringBuilder stringBuilder) { + String[] virgaDirection = Regex.pregMatch(VIRGA_DIRECTION, remark); + stringBuilder.append(messages.getString("Remark.Virga.Direction", messages.getString("Converter." + virgaDirection[1]))).append(" "); + return remark.replaceFirst(VIRGA_DIRECTION.pattern(), "").trim(); } - @Override public boolean canParse(final String pInput) { - return Regex.find(VIRGA_DIRECTION, pInput); + @Override + public boolean canParse(final String input) { + return Regex.find(VIRGA_DIRECTION, input); } } diff --git a/metarParser-parsers/src/main/java/io/github/mivek/command/remark/WindPeakCommand.java b/metarParser-parsers/src/main/java/io/github/mivek/command/remark/WindPeakCommand.java new file mode 100644 index 00000000..8cf848bc --- /dev/null +++ b/metarParser-parsers/src/main/java/io/github/mivek/command/remark/WindPeakCommand.java @@ -0,0 +1,38 @@ +package io.github.mivek.command.remark; + +import io.github.mivek.internationalization.Messages; +import io.github.mivek.utils.Regex; + +import java.util.regex.Pattern; + +/** + * @author mivek + */ +public final class WindPeakCommand implements Command { + + /** Wind peak pattern. */ + private static final Pattern WIND_PEAK = Pattern.compile("^PK WND (\\d{3})(\\d{2,3})/(\\d{2})?(\\d{2})"); + + /** The messages instance. */ + private final Messages messages; + + /** + * Default constructor. + */ + WindPeakCommand() { + messages = Messages.getInstance(); + } + + @Override + public String execute(final String remark, final StringBuilder stringBuilder) { + String[] windPeakParts = Regex.pregMatch(WIND_PEAK, remark); + stringBuilder.append(messages.getString("Remark.PeakWind", windPeakParts[1], windPeakParts[2], verifyString(windPeakParts[3]), windPeakParts[4])); + stringBuilder.append(" "); + return remark.replaceFirst(WIND_PEAK.pattern(), "").trim(); + } + + @Override + public boolean canParse(final String input) { + return Regex.find(WIND_PEAK, input); + } +} diff --git a/metarParser-parsers/src/main/java/io/github/mivek/command/remark/WindShiftCommand.java b/metarParser-parsers/src/main/java/io/github/mivek/command/remark/WindShiftCommand.java new file mode 100644 index 00000000..f1148c3a --- /dev/null +++ b/metarParser-parsers/src/main/java/io/github/mivek/command/remark/WindShiftCommand.java @@ -0,0 +1,38 @@ +package io.github.mivek.command.remark; + +import io.github.mivek.internationalization.Messages; +import io.github.mivek.utils.Regex; + +import java.util.regex.Pattern; + +/** + * @author mivek + */ +public final class WindShiftCommand implements Command { + + /** Wind shift pattern. */ + private static final Pattern WIND_SHIFT = Pattern.compile("^WSHFT (\\d{2})?(\\d{2})"); + + /** The messages instance. */ + private final Messages messages; + + /** + * Default constructor. + */ + WindShiftCommand() { + messages = Messages.getInstance(); + } + + @Override + public String execute(final String remark, final StringBuilder stringBuilder) { + String[] windShiftParts = Regex.pregMatch(WIND_SHIFT, remark); + stringBuilder.append(messages.getString("Remark.WindShift", verifyString(windShiftParts[1]), windShiftParts[2])); + stringBuilder.append(" "); + return remark.replaceFirst(WIND_SHIFT.pattern(), "").trim(); + } + + @Override + public boolean canParse(final String input) { + return Regex.find(WIND_SHIFT, input); + } +} diff --git a/src/main/java/io/github/mivek/command/remark/WindShiftFropaCommand.java b/metarParser-parsers/src/main/java/io/github/mivek/command/remark/WindShiftFropaCommand.java similarity index 52% rename from src/main/java/io/github/mivek/command/remark/WindShiftFropaCommand.java rename to metarParser-parsers/src/main/java/io/github/mivek/command/remark/WindShiftFropaCommand.java index f47485ac..03b26309 100644 --- a/src/main/java/io/github/mivek/command/remark/WindShiftFropaCommand.java +++ b/metarParser-parsers/src/main/java/io/github/mivek/command/remark/WindShiftFropaCommand.java @@ -13,23 +13,25 @@ public final class WindShiftFropaCommand implements Command { private static final Pattern WIND_SHIFT_FROPA = Pattern.compile("^WSHFT (\\d{2})?(\\d{2}) FROPA"); /** The messages instance. */ - private final Messages fMessages; + private final Messages messages; /** * Default constructor. */ WindShiftFropaCommand() { - fMessages = Messages.getInstance(); + messages = Messages.getInstance(); } - @Override public String execute(final String pRemark, final StringBuilder pStringBuilder) { - String[] windShiftParts = Regex.pregMatch(WIND_SHIFT_FROPA, pRemark); - pStringBuilder.append(fMessages.getString("Remark.WindShift.FROPA", verifyString(windShiftParts[1]), windShiftParts[2])); - pStringBuilder.append(" "); - return pRemark.replaceFirst(WIND_SHIFT_FROPA.pattern(), ""); + @Override + public String execute(final String remark, final StringBuilder stringBuilder) { + String[] windShiftParts = Regex.pregMatch(WIND_SHIFT_FROPA, remark); + stringBuilder.append(messages.getString("Remark.WindShift.FROPA", verifyString(windShiftParts[1]), windShiftParts[2])); + stringBuilder.append(" "); + return remark.replaceFirst(WIND_SHIFT_FROPA.pattern(), ""); } - @Override public boolean canParse(final String pInput) { - return Regex.find(WIND_SHIFT_FROPA, pInput); + @Override + public boolean canParse(final String input) { + return Regex.find(WIND_SHIFT_FROPA, input); } } diff --git a/src/main/java/io/github/mivek/command/remark/package-info.java b/metarParser-parsers/src/main/java/io/github/mivek/command/remark/package-info.java similarity index 100% rename from src/main/java/io/github/mivek/command/remark/package-info.java rename to metarParser-parsers/src/main/java/io/github/mivek/command/remark/package-info.java diff --git a/src/main/java/io/github/mivek/exception/ErrorCodes.java b/metarParser-parsers/src/main/java/io/github/mivek/exception/ErrorCodes.java similarity index 74% rename from src/main/java/io/github/mivek/exception/ErrorCodes.java rename to metarParser-parsers/src/main/java/io/github/mivek/exception/ErrorCodes.java index 2a464509..6e1211ec 100644 --- a/src/main/java/io/github/mivek/exception/ErrorCodes.java +++ b/metarParser-parsers/src/main/java/io/github/mivek/exception/ErrorCodes.java @@ -1,49 +1,49 @@ -package io.github.mivek.exception; - -import io.github.mivek.internationalization.Messages; - -/** - * @author mivek - * - */ -public enum ErrorCodes { - /** Error for an invalid ICAO. */ - ERROR_CODE_INVALID_ICAO(1, Messages.getInstance().getString("MetarFacade.InvalidIcao")), - /** Error for an invalid message. */ - ERROR_CODE_INVALID_MESSAGE(2, Messages.getInstance().getString("ErrorCode.InvalidMessage")), - /** Error code for when the airport is not found. */ - ERROR_CODE_AIRPORT_NOT_FOUND(3, Messages.getInstance().getString("ErrorCode.AirportNotFound")); - /** The code of the error. */ - private int fCode; - /** The message of the error. */ - private String fMessage; - - /** - * constructor. - * @param pCode the code of the error. - * @param pMessage the message to set. - */ - ErrorCodes(final int pCode, final String pMessage) { - fCode = pCode; - fMessage = pMessage; - } - - /** - * @return the code - */ - public int getCode() { - return fCode; - } - - /** - * @return the message - */ - public String getMessage() { - return fMessage; - } - - @Override - public String toString() { - return Messages.getInstance().getString("Error.prefix") + getCode() + " " + getMessage(); - } -} +package io.github.mivek.exception; + +import io.github.mivek.internationalization.Messages; + +/** + * @author mivek + */ +public enum ErrorCodes { + /** Error for an invalid ICAO. */ + ERROR_CODE_INVALID_ICAO(1, Messages.getInstance().getString("MetarFacade.InvalidIcao")), + /** Error for an invalid message. */ + ERROR_CODE_INVALID_MESSAGE(2, Messages.getInstance().getString("ErrorCode.InvalidMessage")), + /** Error code for when the airport is not found. */ + ERROR_CODE_AIRPORT_NOT_FOUND(3, Messages.getInstance().getString("ErrorCode.AirportNotFound")); + /** The code of the error. */ + private final int code; + /** The message of the error. */ + private final String message; + + /** + * constructor. + * + * @param code the code of the error. + * @param message the message to set. + */ + ErrorCodes(final int code, final String message) { + this.code = code; + this.message = message; + } + + /** + * @return the code + */ + public int getCode() { + return code; + } + + /** + * @return the message + */ + public String getMessage() { + return message; + } + + @Override + public String toString() { + return Messages.getInstance().getString("Error.prefix") + getCode() + " " + getMessage(); + } +} diff --git a/src/main/java/io/github/mivek/exception/InvalidIcaoException.java b/metarParser-parsers/src/main/java/io/github/mivek/exception/InvalidIcaoException.java similarity index 94% rename from src/main/java/io/github/mivek/exception/InvalidIcaoException.java rename to metarParser-parsers/src/main/java/io/github/mivek/exception/InvalidIcaoException.java index 514faeda..06ea69ec 100644 --- a/src/main/java/io/github/mivek/exception/InvalidIcaoException.java +++ b/metarParser-parsers/src/main/java/io/github/mivek/exception/InvalidIcaoException.java @@ -1,12 +1,12 @@ -package io.github.mivek.exception; - -/** - * @author mivek - */ -public final class InvalidIcaoException extends Exception { - - /** - * Version UID. - */ - private static final long serialVersionUID = 1L; -} +package io.github.mivek.exception; + +/** + * @author mivek + */ +public final class InvalidIcaoException extends Exception { + + /** + * Version UID. + */ + private static final long serialVersionUID = 1L; +} diff --git a/src/main/java/io/github/mivek/exception/ParseException.java b/metarParser-parsers/src/main/java/io/github/mivek/exception/ParseException.java similarity index 51% rename from src/main/java/io/github/mivek/exception/ParseException.java rename to metarParser-parsers/src/main/java/io/github/mivek/exception/ParseException.java index 90fba440..9809be51 100644 --- a/src/main/java/io/github/mivek/exception/ParseException.java +++ b/metarParser-parsers/src/main/java/io/github/mivek/exception/ParseException.java @@ -1,32 +1,28 @@ -package io.github.mivek.exception; - -/** - * @author mivek - * - */ -public class ParseException extends Exception { - /** - * serialVersionUID. - */ - private static final long serialVersionUID = -9022781702124062628L; - /** - * The error code. - */ - private final ErrorCodes fCode; - - /** - * Constructor with error code. - * @param pCode the error code. - */ - public ParseException(final ErrorCodes pCode) { - super(pCode.toString()); - fCode = pCode; - } - - /** - * @return the error code. - */ - public ErrorCodes getErrorCode() { - return fCode; - } -} +package io.github.mivek.exception; + +/** + * @author mivek + */ +public class ParseException extends Exception { + /** serialVersionUID. */ + private static final long serialVersionUID = -9022781702124062628L; + /** The error code. */ + private final ErrorCodes codes; + + /** + * Constructor with error code. + * + * @param code the error code. + */ + public ParseException(final ErrorCodes code) { + super(code.toString()); + this.codes = code; + } + + /** + * @return the error code. + */ + public ErrorCodes getErrorCode() { + return codes; + } +} diff --git a/src/main/java/io/github/mivek/exception/package-info.java b/metarParser-parsers/src/main/java/io/github/mivek/exception/package-info.java similarity index 96% rename from src/main/java/io/github/mivek/exception/package-info.java rename to metarParser-parsers/src/main/java/io/github/mivek/exception/package-info.java index 03defc92..af7c7cbc 100644 --- a/src/main/java/io/github/mivek/exception/package-info.java +++ b/metarParser-parsers/src/main/java/io/github/mivek/exception/package-info.java @@ -1,4 +1,4 @@ -/** - * @author mivek This package contains all exceptions of the application. - */ -package io.github.mivek.exception; +/** + * @author mivek This package contains all exceptions of the application. + */ +package io.github.mivek.exception; diff --git a/src/main/java/io/github/mivek/parser/AbstractParser.java b/metarParser-parsers/src/main/java/io/github/mivek/parser/AbstractParser.java similarity index 62% rename from src/main/java/io/github/mivek/parser/AbstractParser.java rename to metarParser-parsers/src/main/java/io/github/mivek/parser/AbstractParser.java index d5de16f0..adb5f389 100644 --- a/src/main/java/io/github/mivek/parser/AbstractParser.java +++ b/metarParser-parsers/src/main/java/io/github/mivek/parser/AbstractParser.java @@ -1,171 +1,172 @@ -package io.github.mivek.parser; - -import io.github.mivek.command.AirportSupplier; -import io.github.mivek.command.common.Command; -import io.github.mivek.command.common.CommonCommandSupplier; -import io.github.mivek.enums.Descriptive; -import io.github.mivek.enums.Intensity; -import io.github.mivek.enums.Phenomenon; -import io.github.mivek.exception.ParseException; -import io.github.mivek.model.AbstractWeatherCode; -import io.github.mivek.model.AbstractWeatherContainer; -import io.github.mivek.model.Visibility; -import io.github.mivek.model.WeatherCondition; -import io.github.mivek.utils.Regex; - -import java.time.LocalTime; -import java.util.Arrays; -import java.util.regex.Pattern; - -/** - * Abstract class for parser. - * - * @param a concrete subclass of {@link AbstractWeatherCode}. - * @author mivek - * Abstract class for Parser. - */ -public abstract class AbstractParser { - - /** From shortcut constant. */ - protected static final String FM = "FM"; - /** Tempo shortcut constant. */ - protected static final String TEMPO = "TEMPO"; - /** BECMG shortcut constant. */ - protected static final String BECMG = "BECMG"; - /** Pattern for RMK. */ - protected static final String RMK = "RMK"; - /** Pattern regex to tokenize the code. */ - private static final Pattern TOKENIZE_REGEX = Pattern.compile("\\s((?=\\d/\\dSM)(?10km"); - return true; - } - - Command command = commonSupplier.get(pPart); - if (command != null && command.canParse(pPart)) { - return command.execute(pContainer, pPart); - } - - WeatherCondition wc = parseWeatherCondition(pPart); - return pContainer.addWeatherCondition(wc); - } - - /*** - * Adds the remark part to the event. - * @param pContainer the event to update - * @param pParts the tokens of the event - * @param index the RMK index in the event. - */ - void parseRMK(final AbstractWeatherContainer pContainer, final String[] pParts, final int index) { - String[] subArray = Arrays.copyOfRange(pParts, index + 1, pParts.length); - pContainer.setRemark(remarkParser.parse(String.join(" ", subArray))); - } - - /** - * Splits a string between spaces except if the space is between two digits with - * SM. - * - * @param pCode the string to parse - * @return a array of tokens - */ - String[] tokenize(final String pCode) { - return TOKENIZE_REGEX.split(pCode); - } - - /** - * @return the Airport supplier. - */ - AirportSupplier getAirportSupplier() { - return airportSupplier; - } -} +package io.github.mivek.parser; + +import io.github.mivek.command.AirportSupplier; +import io.github.mivek.command.common.Command; +import io.github.mivek.command.common.CommonCommandSupplier; +import io.github.mivek.enums.Descriptive; +import io.github.mivek.enums.Intensity; +import io.github.mivek.enums.Phenomenon; +import io.github.mivek.exception.ParseException; +import io.github.mivek.model.AbstractWeatherCode; +import io.github.mivek.model.AbstractWeatherContainer; +import io.github.mivek.model.Visibility; +import io.github.mivek.model.WeatherCondition; +import io.github.mivek.utils.Regex; + +import java.time.LocalTime; +import java.util.Arrays; +import java.util.regex.Pattern; + +/** + * Abstract class for parser. + * + * @param a concrete subclass of {@link AbstractWeatherCode}. + * @author mivek + * Abstract class for Parser. + */ +public abstract class AbstractParser { + + /** From shortcut constant. */ + protected static final String FM = "FM"; + /** Tempo shortcut constant. */ + protected static final String TEMPO = "TEMPO"; + /** BECMG shortcut constant. */ + protected static final String BECMG = "BECMG"; + /** Pattern for RMK. */ + protected static final String RMK = "RMK"; + /** Pattern regex to tokenize the code. */ + private static final Pattern TOKENIZE_REGEX = Pattern.compile("\\s((?=\\d/\\dSM)(?10km"); + return true; + } + + Command command = commonSupplier.get(part); + if (command != null && command.canParse(part)) { + return command.execute(container, part); + } + + WeatherCondition wc = parseWeatherCondition(part); + return container.addWeatherCondition(wc); + } + + /*** + * Adds the remark part to the event. + * @param container the event to update + * @param parts the tokens of the event + * @param index the RMK index in the event. + */ + void parseRMK(final AbstractWeatherContainer container, final String[] parts, final int index) { + String[] subArray = Arrays.copyOfRange(parts, index + 1, parts.length); + container.setRemark(remarkParser.parse(String.join(" ", subArray))); + } + + /** + * Splits a string between spaces except if the space is between two digits with + * SM. + * + * @param code the string to parse + * @return a array of tokens + */ + String[] tokenize(final String code) { + return TOKENIZE_REGEX.split(code); + } + + /** + * @return the Airport supplier. + */ + AirportSupplier getAirportSupplier() { + return airportSupplier; + } +} diff --git a/src/main/java/io/github/mivek/parser/MetarParser.java b/metarParser-parsers/src/main/java/io/github/mivek/parser/MetarParser.java similarity index 58% rename from src/main/java/io/github/mivek/parser/MetarParser.java rename to metarParser-parsers/src/main/java/io/github/mivek/parser/MetarParser.java index a226979c..5f235bb8 100644 --- a/src/main/java/io/github/mivek/parser/MetarParser.java +++ b/metarParser-parsers/src/main/java/io/github/mivek/parser/MetarParser.java @@ -1,171 +1,174 @@ -package io.github.mivek.parser; - -import io.github.mivek.command.AirportSupplier; -import io.github.mivek.command.common.CommonCommandSupplier; -import io.github.mivek.command.metar.Command; -import io.github.mivek.command.metar.MetarParserCommandSupplier; -import io.github.mivek.model.Airport; -import io.github.mivek.model.Metar; -import io.github.mivek.model.trend.AbstractMetarTrend; -import io.github.mivek.model.trend.BECMGMetarTrend; -import io.github.mivek.model.trend.TEMPOMetarTrend; -import io.github.mivek.model.trend.validity.ATTime; -import io.github.mivek.model.trend.validity.FMTime; -import io.github.mivek.model.trend.validity.TLTime; -import io.github.mivek.utils.Converter; - -/** - * This controller contains methods that parse the metar code. This class is a - * singleton. - * - * @author mivek - */ -public final class MetarParser extends AbstractParser { - /** Constant string for TL. */ - private static final String TILL = "TL"; - /** Constant string for AT. */ - private static final String AT = "AT"; - /** Instance of the class. */ - private static MetarParser instance = new MetarParser(); - /** The command supplier. */ - private final MetarParserCommandSupplier supplier; - - /** - * Private constructor. - */ - private MetarParser() { - this(new CommonCommandSupplier(), RemarkParser.getInstance(), new AirportSupplier(), new MetarParserCommandSupplier()); - } - - /** - * Dependency injection constructor. - * - * @param pCommonCommandSupplier the command command supplier - * @param pRemarkParser the remark parser - * @param pMetarParserCommandSupplier the metar command supplier. - * @param pAirportSupplier the airport supplier - */ - protected MetarParser(final CommonCommandSupplier pCommonCommandSupplier, final RemarkParser pRemarkParser, final AirportSupplier pAirportSupplier, - final MetarParserCommandSupplier pMetarParserCommandSupplier) { - super(pCommonCommandSupplier, pRemarkParser, pAirportSupplier); - supplier = pMetarParserCommandSupplier; - } - - /** - * Get instance method. - * - * @return the instance of MetarParser. - */ - public static MetarParser getInstance() { - return instance; - } - - /** - * This is the main method of the parser. This method checks if the airport - * exists. If it does then the metar code is decoded. - * - * @param pMetarCode String representing the metar. - * @return a decoded metar object. - */ - @Override public Metar parse(final String pMetarCode) { - Metar m = new Metar(); - String[] metarTab = tokenize(pMetarCode); - Airport airport = getAirportSupplier().get(metarTab[0]); - m.setStation(metarTab[0]); - m.setAirport(airport); - m.setMessage(pMetarCode); - parseDeliveryTime(m, metarTab[1]); - int metarTabLength = metarTab.length; - for (int i = 2; i < metarTabLength; i++) { - if (!generalParse(m, metarTab[i])) { - if ("NOSIG".equals(metarTab[i])) { - m.setNosig(true); - } else if ("AUTO".equals(metarTab[i])) { - m.setAuto(true); - } else if (RMK.equals(metarTab[i])) { - parseRMK(m, metarTab, i); - break; - } else if (metarTab[i].equals(TEMPO) || metarTab[i].equals(BECMG)) { - AbstractMetarTrend trend; - trend = initTrend(metarTab[i]); - i = iterTrend(i, trend, metarTab); - m.addTrend(trend); - } else { - executeCommand(m, metarTab[i]); - } - } - } - return m; - } - - /** - * Initiate the trend according to string. - * - * @param pS the string to parse. - * @return a concrete Trends object. - */ - private AbstractMetarTrend initTrend(final String pS) { - AbstractMetarTrend trend; - if (pS.equals(TEMPO)) { - trend = new TEMPOMetarTrend(); - } else { - trend = new BECMGMetarTrend(); - } - return trend; - } - - /** - * Execute the command given by the supplier. - * - * @param pM the metar - * @param pInput the string to parse. - */ - private void executeCommand(final Metar pM, final String pInput) { - Command command = supplier.get(pInput); - if (command != null) { - command.execute(pM, pInput); - } - } - - /** - * Iterates over an array and parses the trends. - * - * @param pIndex the starting index. - * @param pTrend the trend to update - * @param pParts an array of strings - * @return the next index to parse. - */ - private int iterTrend(final int pIndex, final AbstractMetarTrend pTrend, final String[] pParts) { - int i = pIndex + 1; - while (i < pParts.length && !pParts[i].equals(TEMPO) && !pParts[i].equals(BECMG)) { - processChange(pTrend, pParts[i]); - i++; - } - return i - 1; - } - - /** - * Parses a string and updates the trend. - * - * @param pTrend the abstractMetarTrend object to update. - * @param pPart The token to parse. - */ - private void processChange(final AbstractMetarTrend pTrend, final String pPart) { - if (pPart.startsWith(AT)) { - ATTime at = new ATTime(); - at.setTime(Converter.stringToTime(pPart.substring(2))); - pTrend.addTime(at); - } else if (pPart.startsWith(FM)) { - FMTime fm = new FMTime(); - fm.setTime(Converter.stringToTime(pPart.substring(2))); - pTrend.addTime(fm); - } else if (pPart.startsWith(TILL)) { - TLTime tl = new TLTime(); - tl.setTime(Converter.stringToTime(pPart.substring(2))); - pTrend.addTime(tl); - } else { - generalParse(pTrend, pPart); - } - } - -} +package io.github.mivek.parser; + +import io.github.mivek.command.AirportSupplier; +import io.github.mivek.command.common.CommonCommandSupplier; +import io.github.mivek.command.metar.Command; +import io.github.mivek.command.metar.MetarParserCommandSupplier; +import io.github.mivek.model.Airport; +import io.github.mivek.model.Metar; +import io.github.mivek.model.trend.AbstractMetarTrend; +import io.github.mivek.model.trend.BECMGMetarTrend; +import io.github.mivek.model.trend.TEMPOMetarTrend; +import io.github.mivek.model.trend.validity.ATTime; +import io.github.mivek.model.trend.validity.FMTime; +import io.github.mivek.model.trend.validity.TLTime; +import io.github.mivek.utils.Converter; + +/** + * This controller contains methods that parse the metar code. This class is a + * singleton. + * + * @author mivek + */ +public final class MetarParser extends AbstractParser { + /** Constant string for TL. */ + private static final String TILL = "TL"; + /** Constant string for AT. */ + private static final String AT = "AT"; + /** Instance of the class. */ + private static final MetarParser INSTANCE = new MetarParser(); + /** The command supplier. */ + private final MetarParserCommandSupplier supplier; + + /** + * Private constructor. + */ + private MetarParser() { + this(new CommonCommandSupplier(), RemarkParser.getInstance(), new AirportSupplier(), new MetarParserCommandSupplier()); + } + + /** + * Dependency injection constructor. + * + * @param commonCommandSupplier the command command supplier + * @param remarkParser the remark parser + * @param metarParserCommandSupplier the metar command supplier. + * @param airportSupplier the airport supplier + */ + protected MetarParser(final CommonCommandSupplier commonCommandSupplier, final RemarkParser remarkParser, final AirportSupplier airportSupplier, + final MetarParserCommandSupplier metarParserCommandSupplier) { + super(commonCommandSupplier, remarkParser, airportSupplier); + supplier = metarParserCommandSupplier; + } + + /** + * Get instance method. + * + * @return the instance of MetarParser. + */ + public static MetarParser getInstance() { + return INSTANCE; + } + + /** + * This is the main method of the parser. This method checks if the airport + * exists. If it does then the metar code is decoded. + * + * @param code String representing the metar. + * @return a decoded metar object. + */ + @Override + public Metar parse(final String code) { + Metar m = new Metar(); + String[] metarTab = tokenize(code); + Airport airport = getAirportSupplier().get(metarTab[0]); + m.setStation(metarTab[0]); + m.setAirport(airport); + m.setMessage(code); + parseDeliveryTime(m, metarTab[1]); + int metarTabLength = metarTab.length; + int i = 2; + while (i < metarTabLength) { + if (!generalParse(m, metarTab[i])) { + if ("NOSIG".equals(metarTab[i])) { + m.setNosig(true); + } else if ("AUTO".equals(metarTab[i])) { + m.setAuto(true); + } else if (RMK.equals(metarTab[i])) { + parseRMK(m, metarTab, i); + break; + } else if (metarTab[i].equals(TEMPO) || metarTab[i].equals(BECMG)) { + AbstractMetarTrend trend; + trend = initTrend(metarTab[i]); + i = iterTrend(i, trend, metarTab); + m.addTrend(trend); + } else { + executeCommand(m, metarTab[i]); + } + } + i++; + } + return m; + } + + /** + * Initiate the trend according to string. + * + * @param trendpart the string to parse. + * @return a concrete Trends object. + */ + private AbstractMetarTrend initTrend(final String trendpart) { + AbstractMetarTrend trend; + if (trendpart.equals(TEMPO)) { + trend = new TEMPOMetarTrend(); + } else { + trend = new BECMGMetarTrend(); + } + return trend; + } + + /** + * Execute the command given by the supplier. + * + * @param metar the metar + * @param input the string to parse. + */ + private void executeCommand(final Metar metar, final String input) { + Command command = supplier.get(input); + if (command != null) { + command.execute(metar, input); + } + } + + /** + * Iterates over an array and parses the trends. + * + * @param index the starting index. + * @param trend the trend to update + * @param parts an array of strings + * @return the next index to parse. + */ + private int iterTrend(final int index, final AbstractMetarTrend trend, final String[] parts) { + int i = index + 1; + while (i < parts.length && !parts[i].equals(TEMPO) && !parts[i].equals(BECMG)) { + processChange(trend, parts[i]); + i++; + } + return i - 1; + } + + /** + * Parses a string and updates the trend. + * + * @param trend the abstractMetarTrend object to update. + * @param part The token to parse. + */ + private void processChange(final AbstractMetarTrend trend, final String part) { + if (part.startsWith(AT)) { + ATTime at = new ATTime(); + at.setTime(Converter.stringToTime(part.substring(2))); + trend.addTime(at); + } else if (part.startsWith(FM)) { + FMTime fm = new FMTime(); + fm.setTime(Converter.stringToTime(part.substring(2))); + trend.addTime(fm); + } else if (part.startsWith(TILL)) { + TLTime tl = new TLTime(); + tl.setTime(Converter.stringToTime(part.substring(2))); + trend.addTime(tl); + } else { + generalParse(trend, part); + } + } + +} diff --git a/src/main/java/io/github/mivek/parser/RemarkParser.java b/metarParser-parsers/src/main/java/io/github/mivek/parser/RemarkParser.java similarity index 83% rename from src/main/java/io/github/mivek/parser/RemarkParser.java rename to metarParser-parsers/src/main/java/io/github/mivek/parser/RemarkParser.java index fad886eb..8830d170 100644 --- a/src/main/java/io/github/mivek/parser/RemarkParser.java +++ b/metarParser-parsers/src/main/java/io/github/mivek/parser/RemarkParser.java @@ -1,47 +1,48 @@ -package io.github.mivek.parser; - -import io.github.mivek.command.remark.RemarkCommandSupplier; - -import java.util.MissingResourceException; - -/** - * @author mivek - */ -public final class RemarkParser { - - /** The instance of the parser. */ - private static final RemarkParser INSTANCE = new RemarkParser(); - - /** The command supplier. */ - private final RemarkCommandSupplier supplier; - /*** - * Private constructor. - */ - private RemarkParser() { - supplier = new RemarkCommandSupplier(); - } - - /** - * @param pRemark the remark to parse. - * @return the remark string - */ - public String parse(final String pRemark) { - String rmk = pRemark; - StringBuilder sb = new StringBuilder(); - while (!rmk.equals("")) { - try { - rmk = supplier.get(rmk).execute(rmk, sb); - } catch (MissingResourceException e) { - rmk = supplier.getDefaultCommand().execute(rmk, sb); - } - } - return sb.toString(); - } - - /** - * @return the instance of the parser. - */ - public static RemarkParser getInstance() { - return INSTANCE; - } -} +package io.github.mivek.parser; + +import io.github.mivek.command.remark.RemarkCommandSupplier; + +import java.util.MissingResourceException; + +/** + * @author mivek + */ +public final class RemarkParser { + + /** The instance of the parser. */ + private static final RemarkParser INSTANCE = new RemarkParser(); + + /** The command supplier. */ + private final RemarkCommandSupplier supplier; + + /*** + * Private constructor. + */ + private RemarkParser() { + supplier = new RemarkCommandSupplier(); + } + + /** + * @param remark the remark to parse. + * @return the remark string + */ + public String parse(final String remark) { + String rmk = remark; + StringBuilder sb = new StringBuilder(); + while (!"".equals(rmk)) { + try { + rmk = supplier.get(rmk).execute(rmk, sb); + } catch (MissingResourceException e) { + rmk = supplier.getDefaultCommand().execute(rmk, sb); + } + } + return sb.toString(); + } + + /** + * @return the instance of the parser. + */ + public static RemarkParser getInstance() { + return INSTANCE; + } +} diff --git a/src/main/java/io/github/mivek/parser/TAFParser.java b/metarParser-parsers/src/main/java/io/github/mivek/parser/TAFParser.java similarity index 62% rename from src/main/java/io/github/mivek/parser/TAFParser.java rename to metarParser-parsers/src/main/java/io/github/mivek/parser/TAFParser.java index 9c97f2b1..c0ff3455 100644 --- a/src/main/java/io/github/mivek/parser/TAFParser.java +++ b/metarParser-parsers/src/main/java/io/github/mivek/parser/TAFParser.java @@ -1,281 +1,280 @@ -package io.github.mivek.parser; - -import io.github.mivek.command.AirportSupplier; -import io.github.mivek.command.common.CommonCommandSupplier; -import io.github.mivek.exception.ErrorCodes; -import io.github.mivek.exception.ParseException; -import io.github.mivek.model.Airport; -import io.github.mivek.model.TAF; -import io.github.mivek.model.TemperatureDated; -import io.github.mivek.model.trend.AbstractTafTrend; -import io.github.mivek.model.trend.BECMGTafTrend; -import io.github.mivek.model.trend.FMTafTrend; -import io.github.mivek.model.trend.PROBTafTrend; -import io.github.mivek.model.trend.TEMPOTafTrend; -import io.github.mivek.model.trend.validity.BeginningValidity; -import io.github.mivek.model.trend.validity.Validity; -import io.github.mivek.utils.Converter; -import io.github.mivek.utils.Regex; - -import java.util.Arrays; -import java.util.List; -import java.util.regex.Pattern; -import java.util.stream.Collectors; -import java.util.stream.Stream; - -/** - * @author mivek - */ -public final class TAFParser extends AbstractParser { - /** String constant for TAF. */ - public static final String TAF = "TAF"; - /** Probability string constant. */ - private static final String PROB = "PROB"; - /** Temperature Maximum Constant. */ - private static final String TX = "TX"; - /** Temperature Minimum Constant. */ - private static final String TN = "TN"; - /** Regex for the validity. */ - private static final Pattern REGEX_VALIDITY = Pattern.compile("^\\d{4}/\\d{4}$"); - /** Instance of the TAFParser. */ - private static TAFParser instance = new TAFParser(); - - /** - * Default constructor. - */ - private TAFParser() { - this(new CommonCommandSupplier(), RemarkParser.getInstance(), new AirportSupplier()); - } - - /** - * Dependency injection constructor. - * - * @param pCommonCommandSupplier the common command supplier - * @param pRemarkParser the remark parser. - * @param pAirportSupplier the airport supplier. - */ - protected TAFParser(final CommonCommandSupplier pCommonCommandSupplier, final RemarkParser pRemarkParser, final AirportSupplier pAirportSupplier) { - super(pCommonCommandSupplier, pRemarkParser, pAirportSupplier); - } - /** - * @return the instance. - */ - public static TAFParser getInstance() { - return instance; - } - - /* - * (non-Javadoc) - * @see io.github.mivek.parser.AbstractParser#parse(java.lang.String) - */ - @Override - public TAF parse(final String pTAFCode) throws ParseException { - String[][] lines = extractLineTokens(pTAFCode); - if (!TAF.equals(lines[0][0])) { - throw new ParseException(ErrorCodes.ERROR_CODE_INVALID_MESSAGE); - } - TAF taf = new TAF(); - - // Handle the 1st line. - String[] line1parts = lines[0]; - int i = 1; - if (TAF.equals(line1parts[1])) { - i = 2; - } - // Handle case the taf event is AMD. - if ("AMD".equals(line1parts[i])) { - taf.setAmendment(true); - i++; - } - // Airport - Airport airport = getAirportSupplier().get(line1parts[i]); - taf.setStation(line1parts[i]); - i++; - taf.setAirport(airport); - taf.setMessage(pTAFCode); - // Day and time - parseDeliveryTime(taf, line1parts[i]); - // Validity Time - i++; - taf.setValidity(parseValidity(line1parts[i])); - - // Handle rest of second line. - for (int j = i; j < line1parts.length; j++) { - String part = line1parts[j]; - if (RMK.equals(part)) { - parseRMK(taf, line1parts, j); - } else if (part.startsWith(TX)) { - taf.setMaxTemperature(parseTemperature(part)); - } else if (part.startsWith(TN)) { - taf.setMinTemperature(parseTemperature(part)); - } else { - generalParse(taf, part); - } - } - // Process other lines. - for (int j = 1; j < lines.length; j++) { - // Split the line. - String[] parts = lines[j]; - processLines(taf, parts); - } - return taf; - } - - /** - * Extracts all lines and tokenize them. - * @param pTAFCode raw TAF which may already contains some linebreaks - * @return 2d jagged array containing lines and their tokens - */ - private String[][] extractLineTokens(final String pTAFCode) { - String cleanedInput = pTAFCode - .replace("\n", " ") // remove all linebreaks - .replaceAll("\\s{2,}", " "); // remove unnecessary whitespaces - - String[] lines = cleanedInput - .replaceAll("\\s(PROB\\d{2}\\sTEMPO|TEMPO|BECMG|FM|PROB)", "\n$1") - .split("\n"); - String[][] lineTokens = Arrays.stream(lines).map(this::tokenize).toArray(String[][]::new); - if (lineTokens.length > 1) { - // often temperatures are set in the end of the TAF report - String[] last = lineTokens[lines.length - 1]; - List temperatures = Arrays.stream(last).filter(code -> code.startsWith(TX) || code.startsWith(TN)).collect(Collectors.toList()); - if (!temperatures.isEmpty()) { - lineTokens[0] = Stream.concat(Arrays.stream(lineTokens[0]), temperatures.stream()).toArray(String[]::new); - lineTokens[lines.length - 1] = Arrays.stream(last).filter(code -> !code.startsWith(TX) && !code.startsWith(TN)).toArray(String[]::new); - } - } - return lineTokens; - } - - /** - * Handles the parsing of a line. - * - * @param pTaf the TAF object to build - * @param pParts the token of the line - */ - private void processLines(final TAF pTaf, final String[] pParts) { - if (pParts[0].equals(BECMG)) { - BECMGTafTrend change = new BECMGTafTrend(); - iterChanges(1, pParts, change); - pTaf.addBECMG(change); - } else if (pParts[0].equals(TEMPO)) { - TEMPOTafTrend change = new TEMPOTafTrend(); - iterChanges(1, pParts, change); - pTaf.addTempo(change); - } else if (pParts[0].startsWith(FM)) { - FMTafTrend change = new FMTafTrend(); - change.setValidity(parseBasicValidity(pParts[0])); - for (int k = 1; k < pParts.length; k++) { - processGeneralChanges(change, pParts[k]); - } - pTaf.addFM(change); - } else if (pParts[0].startsWith(PROB)) { - int probability = parseProbability(pParts[0]); - if (pParts.length > 1 && pParts[1].equals(TEMPO)) { - TEMPOTafTrend change = new TEMPOTafTrend(); - iterChanges(2, pParts, change); - change.setProbability(probability); - pTaf.addTempo(change); - } else { - PROBTafTrend change = new PROBTafTrend(); - change.setProbability(probability); - iterChanges(1, pParts, change); - pTaf.addProb(change); - } - } - } - - /** - * Updates the change object according to the string. - * - * @param change the change object to update. - * @param pPart the string to parse. - */ - private void processChanges(final AbstractTafTrend change, final String pPart) { - if (Regex.match(REGEX_VALIDITY, pPart)) { - change.setValidity(parseValidity(pPart)); - } else { - processGeneralChanges(change, pPart); - } - } - - /** - * Updates the change object according to the string. - * - * @param pChange the change object to update. - * @param pPart String containing the information. - */ - protected void processGeneralChanges(final AbstractTafTrend pChange, final String pPart) { - generalParse(pChange, pPart); - } - - /** - * parses the probability out of PROB?? - * - * @param pPart the string to parse. - * @return probability of the trend. - */ - protected int parseProbability(final String pPart) { - return Integer.parseInt(pPart.substring(4)); - } - - /** - * Parse the validity part of a {@link TAFParser} or an - * {@link AbstractTafTrend}. - * @param pValidity the string representing the validity. - * @return a {@link Validity} object. - */ - protected Validity parseValidity(final String pValidity) { - Validity validity = new Validity(); - String[] validityPart = pValidity.split("/"); - validity.setStartDay(Integer.parseInt(validityPart[0].substring(0, 2))); - validity.setStartHour(Integer.parseInt(validityPart[0].substring(2))); - validity.setEndDay(Integer.parseInt(validityPart[1].substring(0, 2))); - validity.setEndHour(Integer.parseInt(validityPart[1].substring(2))); - return validity; - } - - /** - * Parses the validity of a {@link FMTafTrend} object. - * @param pValidity the string to parse - * @return a {@link BeginningValidity} object. - */ - protected BeginningValidity parseBasicValidity(final String pValidity) { - BeginningValidity validity = new BeginningValidity(); - validity.setStartDay(Integer.parseInt(pValidity.substring(2, 4))); - validity.setStartHour(Integer.parseInt(pValidity.substring(4, 6))); - validity.setStartMinutes(Integer.parseInt(pValidity.substring(6, 8))); - return validity; - } - - /** - * Iterates over the string array and build the abstractWeather change. - * @param pIndex the starting index of the array. - * @param pParts the array of string. - * @param pChange the abstractWeatherChange to update. - */ - private void iterChanges(final int pIndex, final String[] pParts, final AbstractTafTrend pChange) { - for (int i = pIndex; i < pParts.length; i++) { - if (RMK.equals(pParts[i])) { - parseRMK(pChange, pParts, i); - } else { - processChanges(pChange, pParts[i]); - } - } - } - - /** - * Parse the temperature. - * @param pTempPart the string to parse. - * @return a temperature with its date. - */ - protected TemperatureDated parseTemperature(final String pTempPart) { - TemperatureDated temperature = new TemperatureDated(); - String[] parts = pTempPart.split("/"); - temperature.setTemperature(Converter.convertTemperature(parts[0].substring(2))); - temperature.setDay(Integer.parseInt(parts[1].substring(0, 2))); - temperature.setHour(Integer.parseInt(parts[1].substring(2, 4))); - return temperature; - } - -} +package io.github.mivek.parser; + +import io.github.mivek.command.AirportSupplier; +import io.github.mivek.command.common.CommonCommandSupplier; +import io.github.mivek.exception.ErrorCodes; +import io.github.mivek.exception.ParseException; +import io.github.mivek.model.Airport; +import io.github.mivek.model.TAF; +import io.github.mivek.model.TemperatureDated; +import io.github.mivek.model.trend.AbstractTafTrend; +import io.github.mivek.model.trend.BECMGTafTrend; +import io.github.mivek.model.trend.FMTafTrend; +import io.github.mivek.model.trend.PROBTafTrend; +import io.github.mivek.model.trend.TEMPOTafTrend; +import io.github.mivek.model.trend.validity.BeginningValidity; +import io.github.mivek.model.trend.validity.Validity; +import io.github.mivek.utils.Converter; +import io.github.mivek.utils.Regex; + +import java.util.Arrays; +import java.util.List; +import java.util.regex.Pattern; +import java.util.stream.Collectors; +import java.util.stream.Stream; + +/** + * @author mivek + */ +public final class TAFParser extends AbstractParser { + /** String constant for TAF. */ + public static final String TAF = "TAF"; + /** Probability string constant. */ + private static final String PROB = "PROB"; + /** Temperature Maximum Constant. */ + private static final String TX = "TX"; + /** Temperature Minimum Constant. */ + private static final String TN = "TN"; + /** Regex for the validity. */ + private static final Pattern REGEX_VALIDITY = Pattern.compile("^\\d{4}/\\d{4}$"); + /** Instance of the TAFParser. */ + private static final TAFParser INSTANCE = new TAFParser(); + + /** + * Default constructor. + */ + private TAFParser() { + this(new CommonCommandSupplier(), RemarkParser.getInstance(), new AirportSupplier()); + } + + /** + * Dependency injection constructor. + * + * @param commonCommandSupplier the common command supplier + * @param remarkParser the remark parser. + * @param airportSupplier the airport supplier. + */ + protected TAFParser(final CommonCommandSupplier commonCommandSupplier, final RemarkParser remarkParser, final AirportSupplier airportSupplier) { + super(commonCommandSupplier, remarkParser, airportSupplier); + } + + /** + * @return the instance. + */ + public static TAFParser getInstance() { + return INSTANCE; + } + + @Override + public TAF parse(final String code) throws ParseException { + String[][] lines = extractLineTokens(code); + if (!TAF.equals(lines[0][0])) { + throw new ParseException(ErrorCodes.ERROR_CODE_INVALID_MESSAGE); + } + TAF taf = new TAF(); + + // Handle the 1st line. + String[] line1parts = lines[0]; + int i = 1; + if (TAF.equals(line1parts[1])) { + i = 2; + } + // Handle case the taf event is AMD. + if ("AMD".equals(line1parts[i])) { + taf.setAmendment(true); + i++; + } + // Airport + Airport airport = getAirportSupplier().get(line1parts[i]); + taf.setStation(line1parts[i]); + i++; + taf.setAirport(airport); + taf.setMessage(code); + // Day and time + parseDeliveryTime(taf, line1parts[i]); + // Validity Time + i++; + taf.setValidity(parseValidity(line1parts[i])); + + // Handle rest of second line. + for (int j = i; j < line1parts.length; j++) { + String part = line1parts[j]; + if (RMK.equals(part)) { + parseRMK(taf, line1parts, j); + } else if (part.startsWith(TX)) { + taf.setMaxTemperature(parseTemperature(part)); + } else if (part.startsWith(TN)) { + taf.setMinTemperature(parseTemperature(part)); + } else { + generalParse(taf, part); + } + } + // Process other lines. + for (int j = 1; j < lines.length; j++) { + // Split the line. + String[] parts = lines[j]; + processLines(taf, parts); + } + return taf; + } + + /** + * Extracts all lines and tokenize them. + * + * @param tafCode raw TAF which may already contains some linebreaks + * @return 2d jagged array containing lines and their tokens + */ + private String[][] extractLineTokens(final String tafCode) { + String cleanedInput = tafCode.replace("\n", " ") // remove all linebreaks + .replaceAll("\\s{2,}", " "); // remove unnecessary whitespaces + + String[] lines = cleanedInput.replaceAll("\\s(PROB\\d{2}\\sTEMPO|TEMPO|BECMG|FM|PROB)", "\n$1").split("\n"); + String[][] lineTokens = Arrays.stream(lines).map(this::tokenize).toArray(String[][]::new); + if (lineTokens.length > 1) { + // often temperatures are set in the end of the TAF report + String[] last = lineTokens[lines.length - 1]; + List temperatures = Arrays.stream(last).filter(code -> code.startsWith(TX) || code.startsWith(TN)).collect(Collectors.toList()); + if (!temperatures.isEmpty()) { + lineTokens[0] = Stream.concat(Arrays.stream(lineTokens[0]), temperatures.stream()).toArray(String[]::new); + lineTokens[lines.length - 1] = Arrays.stream(last).filter(code -> !code.startsWith(TX) && !code.startsWith(TN)).toArray(String[]::new); + } + } + return lineTokens; + } + + /** + * Handles the parsing of a line. + * + * @param taf the TAF object to build + * @param parts the token of the line + */ + private void processLines(final TAF taf, final String[] parts) { + if (parts[0].equals(BECMG)) { + BECMGTafTrend change = new BECMGTafTrend(); + iterChanges(1, parts, change); + taf.addBECMG(change); + } else if (parts[0].equals(TEMPO)) { + TEMPOTafTrend change = new TEMPOTafTrend(); + iterChanges(1, parts, change); + taf.addTempo(change); + } else if (parts[0].startsWith(FM)) { + FMTafTrend change = new FMTafTrend(); + change.setValidity(parseBasicValidity(parts[0])); + for (int k = 1; k < parts.length; k++) { + processGeneralChanges(change, parts[k]); + } + taf.addFM(change); + } else if (parts[0].startsWith(PROB)) { + int probability = parseProbability(parts[0]); + if (parts.length > 1 && parts[1].equals(TEMPO)) { + TEMPOTafTrend change = new TEMPOTafTrend(); + iterChanges(2, parts, change); + change.setProbability(probability); + taf.addTempo(change); + } else { + PROBTafTrend change = new PROBTafTrend(); + change.setProbability(probability); + iterChanges(1, parts, change); + taf.addProb(change); + } + } + } + + /** + * Updates the change object according to the string. + * + * @param change the change object to update. + * @param part the string to parse. + */ + private void processChanges(final AbstractTafTrend change, final String part) { + if (Regex.match(REGEX_VALIDITY, part)) { + change.setValidity(parseValidity(part)); + } else { + processGeneralChanges(change, part); + } + } + + /** + * Updates the change object according to the string. + * + * @param change the change object to update. + * @param part String containing the information. + */ + protected void processGeneralChanges(final AbstractTafTrend change, final String part) { + generalParse(change, part); + } + + /** + * parses the probability out of PROB?? + * + * @param part the string to parse. + * @return probability of the trend. + */ + protected int parseProbability(final String part) { + return Integer.parseInt(part.substring(4)); + } + + /** + * Parse the validity part of a {@link TAFParser} or an + * {@link AbstractTafTrend}. + * + * @param validityString the string representing the validity. + * @return a {@link Validity} object. + */ + protected Validity parseValidity(final String validityString) { + Validity validity = new Validity(); + String[] validityPart = validityString.split("/"); + validity.setStartDay(Integer.parseInt(validityPart[0].substring(0, 2))); + validity.setStartHour(Integer.parseInt(validityPart[0].substring(2))); + validity.setEndDay(Integer.parseInt(validityPart[1].substring(0, 2))); + validity.setEndHour(Integer.parseInt(validityPart[1].substring(2))); + return validity; + } + + /** + * Parses the validity of a {@link FMTafTrend} object. + * + * @param validityString the string to parse + * @return a {@link BeginningValidity} object. + */ + protected BeginningValidity parseBasicValidity(final String validityString) { + BeginningValidity validity = new BeginningValidity(); + validity.setStartDay(Integer.parseInt(validityString.substring(2, 4))); + validity.setStartHour(Integer.parseInt(validityString.substring(4, 6))); + validity.setStartMinutes(Integer.parseInt(validityString.substring(6, 8))); + return validity; + } + + /** + * Iterates over the string array and build the abstractWeather change. + * + * @param index the starting index of the array. + * @param parts the array of string. + * @param change the abstractWeatherChange to update. + */ + private void iterChanges(final int index, final String[] parts, final AbstractTafTrend change) { + for (int i = index; i < parts.length; i++) { + if (RMK.equals(parts[i])) { + parseRMK(change, parts, i); + } else { + processChanges(change, parts[i]); + } + } + } + + /** + * Parse the temperature. + * + * @param tempPart the string to parse. + * @return a temperature with its date. + */ + protected TemperatureDated parseTemperature(final String tempPart) { + TemperatureDated temperature = new TemperatureDated(); + String[] parts = tempPart.split("/"); + temperature.setTemperature(Converter.convertTemperature(parts[0].substring(2))); + temperature.setDay(Integer.parseInt(parts[1].substring(0, 2))); + temperature.setHour(Integer.parseInt(parts[1].substring(2, 4))); + return temperature; + } + +} diff --git a/src/main/java/io/github/mivek/parser/package-info.java b/metarParser-parsers/src/main/java/io/github/mivek/parser/package-info.java similarity index 95% rename from src/main/java/io/github/mivek/parser/package-info.java rename to metarParser-parsers/src/main/java/io/github/mivek/parser/package-info.java index b785ca12..9797a92d 100644 --- a/src/main/java/io/github/mivek/parser/package-info.java +++ b/metarParser-parsers/src/main/java/io/github/mivek/parser/package-info.java @@ -1,6 +1,6 @@ -/** - * Contains the parsers of the application. - * +/** + * Contains the parsers of the application. + * * @author mivek - */ -package io.github.mivek.parser; + */ +package io.github.mivek.parser; diff --git a/src/test/java/io/github/mivek/command/AirportSupplierTest.java b/metarParser-parsers/src/test/java/io/github/mivek/command/AirportSupplierTest.java similarity index 77% rename from src/test/java/io/github/mivek/command/AirportSupplierTest.java rename to metarParser-parsers/src/test/java/io/github/mivek/command/AirportSupplierTest.java index a5a1a8a5..107bdec3 100644 --- a/src/test/java/io/github/mivek/command/AirportSupplierTest.java +++ b/metarParser-parsers/src/test/java/io/github/mivek/command/AirportSupplierTest.java @@ -14,16 +14,19 @@ public class AirportSupplierTest { private AirportSupplier sut; - @Before public void setUp() { + @Before + public void setUp() { sut = new AirportSupplier(); } - @Test public void testGetWithExistingIcao() { + @Test + public void testGetWithExistingIcao() { Airport res = sut.get("LFPG"); assertNotNull(res); } - @Test public void testWithNonExistingIcao() { + @Test + public void testWithNonExistingIcao() { Airport res = sut.get("AA"); assertNull(res); } diff --git a/src/test/java/io/github/mivek/command/common/CloudCommandTest.java b/metarParser-parsers/src/test/java/io/github/mivek/command/common/CloudCommandTest.java similarity index 77% rename from src/test/java/io/github/mivek/command/common/CloudCommandTest.java rename to metarParser-parsers/src/test/java/io/github/mivek/command/common/CloudCommandTest.java index f9de0f5c..75586ea9 100644 --- a/src/test/java/io/github/mivek/command/common/CloudCommandTest.java +++ b/metarParser-parsers/src/test/java/io/github/mivek/command/common/CloudCommandTest.java @@ -15,11 +15,13 @@ public class CloudCommandTest { private CloudCommand sut; - @Before public void setUp() { + @Before + public void setUp() { sut = new CloudCommand(); } - @Test public void testParseCloudNullCloudQuantity() { + @Test + public void testParseCloudNullCloudQuantity() { String cloud = "AZE015"; Cloud res = sut.parseCloud(cloud); @@ -27,43 +29,44 @@ public class CloudCommandTest { assertNull(res); } - @Test public void testParseCloudSkyClear() { + @Test + public void testParseCloudSkyClear() { String cloud = "SKC"; Cloud res = sut.parseCloud(cloud); assertNotNull(res); assertEquals(CloudQuantity.SKC, res.getQuantity()); - assertEquals(0, res.getAltitude()); assertEquals(0, res.getHeight()); assertNull(res.getType()); } - @Test public void testParseCloudWithAltitude() { + @Test + public void testParseCloudWithAltitude() { String cloud = "SCT016"; Cloud res = sut.parseCloud(cloud); assertNotNull(res); assertEquals(CloudQuantity.SCT, res.getQuantity()); - assertEquals(480, res.getAltitude()); assertEquals(1600, res.getHeight()); assertNull(res.getType()); } - @Test public void testParseCloudWithType() { + @Test + public void testParseCloudWithType() { String cloud = "SCT026CB"; Cloud res = sut.parseCloud(cloud); assertNotNull(res); assertEquals(CloudQuantity.SCT, res.getQuantity()); - assertEquals(30 * 26, res.getAltitude()); assertEquals(2600, res.getHeight()); assertNotNull(res.getType()); assertEquals(CloudType.CB, res.getType()); } - @Test public void testParseCloudWithNSC() { + @Test + public void testParseCloudWithNSC() { String cloud = "NSC"; Cloud res = sut.parseCloud(cloud); assertNotNull(res); diff --git a/metarParser-parsers/src/test/java/io/github/mivek/command/common/CommonCommandArchitectureTest.java b/metarParser-parsers/src/test/java/io/github/mivek/command/common/CommonCommandArchitectureTest.java new file mode 100644 index 00000000..c8b963fe --- /dev/null +++ b/metarParser-parsers/src/test/java/io/github/mivek/command/common/CommonCommandArchitectureTest.java @@ -0,0 +1,30 @@ +package io.github.mivek.command.common; + +import com.tngtech.archunit.core.importer.ImportOption; +import com.tngtech.archunit.junit.AnalyzeClasses; +import com.tngtech.archunit.junit.ArchTest; +import com.tngtech.archunit.junit.ArchUnitRunner; +import com.tngtech.archunit.lang.ArchRule; +import io.github.mivek.command.common.Command; +import org.junit.runner.RunWith; + +import static com.tngtech.archunit.lang.syntax.ArchRuleDefinition.classes; +import static com.tngtech.archunit.lang.syntax.ArchRuleDefinition.noClasses; + +/** + * @author mivek + */ +@RunWith(ArchUnitRunner.class) +@AnalyzeClasses(packages = { "io.github.mivek.command.common" }, importOptions = { ImportOption.DoNotIncludeTests.class }) +public class CommonCommandArchitectureTest { + + @ArchTest + public static final ArchRule dependancyRule = noClasses().should(). + dependOnClassesThat().resideInAnyPackage("io.github.mivek.parser"). + andShould().onlyBeAccessed().byClassesThat().resideInAPackage("io.github.mivel.parser"); + + @ArchTest + public static final ArchRule implementationRule = classes().that().areNotInterfaces().and().haveNameMatching(".*Command").should().implement(Command.class); +} + + diff --git a/src/test/java/io/github/mivek/command/common/CommonCommandSupplierTest.java b/metarParser-parsers/src/test/java/io/github/mivek/command/common/CommonCommandSupplierTest.java similarity index 80% rename from src/test/java/io/github/mivek/command/common/CommonCommandSupplierTest.java rename to metarParser-parsers/src/test/java/io/github/mivek/command/common/CommonCommandSupplierTest.java index 0d139ceb..57a1551f 100644 --- a/src/test/java/io/github/mivek/command/common/CommonCommandSupplierTest.java +++ b/metarParser-parsers/src/test/java/io/github/mivek/command/common/CommonCommandSupplierTest.java @@ -6,14 +6,15 @@ import java.util.List; import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertThat; +import static org.hamcrest.MatcherAssert.assertThat; /** * @author mivek */ public class CommonCommandSupplierTest { - @Test public void testBuildCommands() { + @Test + public void testBuildCommands() { List commands = new CommonCommandSupplier().buildCommands(); assertNotNull(commands); diff --git a/src/test/java/io/github/mivek/command/common/WindCommandTest.java b/metarParser-parsers/src/test/java/io/github/mivek/command/common/WindCommandTest.java similarity index 85% rename from src/test/java/io/github/mivek/command/common/WindCommandTest.java rename to metarParser-parsers/src/test/java/io/github/mivek/command/common/WindCommandTest.java index b9e982f1..50cd14a1 100644 --- a/src/test/java/io/github/mivek/command/common/WindCommandTest.java +++ b/metarParser-parsers/src/test/java/io/github/mivek/command/common/WindCommandTest.java @@ -7,6 +7,7 @@ import static org.hamcrest.Matchers.is; import static org.junit.Assert.*; +import static org.hamcrest.MatcherAssert.assertThat; /** * @author mivek @@ -15,11 +16,13 @@ public class WindCommandTest { private WindCommand sut; - @Before public void setUp() { + @Before + public void setUp() { sut = new WindCommand(); } - @Test public void testParseWindSimple() { + @Test + public void testParseWindSimple() { String windPart = "34008KT"; Wind res = sut.parseWind(windPart); @@ -33,7 +36,8 @@ public class WindCommandTest { } - @Test public void testParseWindWithGusts() { + @Test + public void testParseWindWithGusts() { String windPart = "12017G20KT"; Wind res = sut.parseWind(windPart); @@ -46,7 +50,8 @@ public class WindCommandTest { assertEquals("KT", res.getUnit()); } - @Test public void testParseWindVariable() { + @Test + public void testParseWindVariable() { String windPart = "VRB08KT"; Wind res = sut.parseWind(windPart); diff --git a/metarParser-parsers/src/test/java/io/github/mivek/command/metar/MetarCommandArchitectureTest.java b/metarParser-parsers/src/test/java/io/github/mivek/command/metar/MetarCommandArchitectureTest.java new file mode 100644 index 00000000..23f24c01 --- /dev/null +++ b/metarParser-parsers/src/test/java/io/github/mivek/command/metar/MetarCommandArchitectureTest.java @@ -0,0 +1,28 @@ +package io.github.mivek.command.metar; + +import com.tngtech.archunit.core.importer.ImportOption; +import com.tngtech.archunit.junit.AnalyzeClasses; +import com.tngtech.archunit.junit.ArchTest; +import com.tngtech.archunit.junit.ArchUnitRunner; +import com.tngtech.archunit.lang.ArchRule; +import org.junit.runner.RunWith; + +import static com.tngtech.archunit.lang.syntax.ArchRuleDefinition.classes; +import static com.tngtech.archunit.lang.syntax.ArchRuleDefinition.noClasses; + +/** + * @author mivek + */ +@RunWith(ArchUnitRunner.class) +@AnalyzeClasses(packages = { "io.github.mivek.command.metar" }, importOptions = { ImportOption.DoNotIncludeTests.class }) +public class MetarCommandArchitectureTest { + + @ArchTest + public static final ArchRule dependancyRule = noClasses().should(). + dependOnClassesThat().resideInAnyPackage("io.github.mivek.parser"). + andShould().onlyBeAccessed().byClassesThat().haveSimpleName("MetarParser"); + + @ArchTest + public static final ArchRule implementationRule = classes().that().areNotInterfaces().and().haveNameMatching(".*Command").should().implement(Command.class); +} + diff --git a/src/test/java/io/github/mivek/command/metar/MetarParserCommandSupplierTest.java b/metarParser-parsers/src/test/java/io/github/mivek/command/metar/MetarParserCommandSupplierTest.java similarity index 80% rename from src/test/java/io/github/mivek/command/metar/MetarParserCommandSupplierTest.java rename to metarParser-parsers/src/test/java/io/github/mivek/command/metar/MetarParserCommandSupplierTest.java index 632e9dd8..dafcd5c7 100644 --- a/src/test/java/io/github/mivek/command/metar/MetarParserCommandSupplierTest.java +++ b/metarParser-parsers/src/test/java/io/github/mivek/command/metar/MetarParserCommandSupplierTest.java @@ -6,14 +6,15 @@ import java.util.List; import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertThat; +import static org.hamcrest.MatcherAssert.assertThat; /** * @author mivek */ public class MetarParserCommandSupplierTest { - @Test public void testBuildCommandList() { + @Test + public void testBuildCommandList() { List commands = new MetarParserCommandSupplier().buildCommandList(); assertNotNull(commands); diff --git a/src/test/java/io/github/mivek/command/metar/RunwayCommandTest.java b/metarParser-parsers/src/test/java/io/github/mivek/command/metar/RunwayCommandTest.java similarity index 85% rename from src/test/java/io/github/mivek/command/metar/RunwayCommandTest.java rename to metarParser-parsers/src/test/java/io/github/mivek/command/metar/RunwayCommandTest.java index 39b5eb7f..2b05c5e0 100644 --- a/src/test/java/io/github/mivek/command/metar/RunwayCommandTest.java +++ b/metarParser-parsers/src/test/java/io/github/mivek/command/metar/RunwayCommandTest.java @@ -8,6 +8,7 @@ import static org.hamcrest.Matchers.hasSize; import static org.junit.Assert.*; +import static org.hamcrest.MatcherAssert.assertThat; /** * @author mivek @@ -16,11 +17,13 @@ public class RunwayCommandTest { private RunwayCommand command; - @Before public void setUp() { + @Before + public void setUp() { command = new RunwayCommand(); } - @Test public void testExecuteSimple() { + @Test + public void testExecuteSimple() { String riString = "R26/0600U"; Metar m = new Metar(); command.execute(m, riString); @@ -33,7 +36,8 @@ public class RunwayCommandTest { assertEquals(Messages.getInstance().getString("Converter.U"), ri.getTrend()); } - @Test public void testParseRunWaysComplex() { + @Test + public void testParseRunWaysComplex() { String riString = "R26L/0550V700U"; Metar m = new Metar(); @@ -47,7 +51,8 @@ public class RunwayCommandTest { assertEquals(Messages.getInstance().getString("Converter.U"), ri.getTrend()); } - @Test public void testParseRunWayNull() { + @Test + public void testParseRunWayNull() { String riString = "R26R/AZEZFDFS"; Metar m = new Metar(); diff --git a/src/test/java/io/github/mivek/command/remark/DefaultCommandTest.java b/metarParser-parsers/src/test/java/io/github/mivek/command/remark/DefaultCommandTest.java similarity index 85% rename from src/test/java/io/github/mivek/command/remark/DefaultCommandTest.java rename to metarParser-parsers/src/test/java/io/github/mivek/command/remark/DefaultCommandTest.java index 566f4a48..94c323b6 100644 --- a/src/test/java/io/github/mivek/command/remark/DefaultCommandTest.java +++ b/metarParser-parsers/src/test/java/io/github/mivek/command/remark/DefaultCommandTest.java @@ -9,7 +9,8 @@ */ public class DefaultCommandTest { - @Test public void canParse() { + @Test + public void canParse() { assertTrue(new DefaultCommand().canParse("")); } } diff --git a/metarParser-parsers/src/test/java/io/github/mivek/command/remark/RemarkCommandArchitectureTest.java b/metarParser-parsers/src/test/java/io/github/mivek/command/remark/RemarkCommandArchitectureTest.java new file mode 100644 index 00000000..a4dbd2d0 --- /dev/null +++ b/metarParser-parsers/src/test/java/io/github/mivek/command/remark/RemarkCommandArchitectureTest.java @@ -0,0 +1,27 @@ +package io.github.mivek.command.remark; + +import com.tngtech.archunit.core.importer.ImportOption; +import com.tngtech.archunit.junit.AnalyzeClasses; +import com.tngtech.archunit.junit.ArchTest; +import com.tngtech.archunit.junit.ArchUnitRunner; +import com.tngtech.archunit.lang.ArchRule; +import org.junit.runner.RunWith; + +import static com.tngtech.archunit.lang.syntax.ArchRuleDefinition.classes; +import static com.tngtech.archunit.lang.syntax.ArchRuleDefinition.noClasses; + +/** + * @author mivek + */ +@RunWith(ArchUnitRunner.class) +@AnalyzeClasses(packages = { "io.github.mivek.command.remark" }, importOptions = { ImportOption.DoNotIncludeTests.class }) +public class RemarkCommandArchitectureTest { + @ArchTest + public static final ArchRule dependancyRule = noClasses().should(). + dependOnClassesThat().resideInAnyPackage("io.github.mivek.parser"). + andShould().onlyBeAccessed().byClassesThat().haveSimpleName("RemarkParser"); + + @ArchTest + public static final ArchRule implementationRule = classes().that().areNotInterfaces().and().haveNameMatching(".*Command").should().implement(Command.class); +} + diff --git a/src/test/java/io/github/mivek/command/remark/RemarkCommandSupplierTest.java b/metarParser-parsers/src/test/java/io/github/mivek/command/remark/RemarkCommandSupplierTest.java similarity index 79% rename from src/test/java/io/github/mivek/command/remark/RemarkCommandSupplierTest.java rename to metarParser-parsers/src/test/java/io/github/mivek/command/remark/RemarkCommandSupplierTest.java index b7c283e1..5996e142 100644 --- a/src/test/java/io/github/mivek/command/remark/RemarkCommandSupplierTest.java +++ b/metarParser-parsers/src/test/java/io/github/mivek/command/remark/RemarkCommandSupplierTest.java @@ -4,16 +4,17 @@ import java.util.List; +import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.hasSize; import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertThat; /** * @author mivek */ public class RemarkCommandSupplierTest { - @Test public void testBuildCommandList() { + @Test + public void testBuildCommandList() { List commands = new RemarkCommandSupplier().buildCommandList(); assertNotNull(commands); diff --git a/src/test/java/io/github/mivek/parser/AbstractParserTest.java b/metarParser-parsers/src/test/java/io/github/mivek/parser/AbstractParserTest.java similarity index 82% rename from src/test/java/io/github/mivek/parser/AbstractParserTest.java rename to metarParser-parsers/src/test/java/io/github/mivek/parser/AbstractParserTest.java index 5f6c69ba..f5d61206 100644 --- a/src/test/java/io/github/mivek/parser/AbstractParserTest.java +++ b/metarParser-parsers/src/test/java/io/github/mivek/parser/AbstractParserTest.java @@ -1,88 +1,83 @@ -package io.github.mivek.parser; - -import io.github.mivek.enums.Descriptive; -import io.github.mivek.enums.Intensity; -import io.github.mivek.enums.Phenomenon; -import io.github.mivek.exception.ParseException; -import io.github.mivek.model.AbstractWeatherCode; -import io.github.mivek.model.Visibility; -import io.github.mivek.model.WeatherCondition; -import org.junit.Ignore; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.ExpectedException; - -import static org.hamcrest.Matchers.*; -import static org.junit.Assert.*; - -/** - * Test class for {@link AbstractParser} - * - * @author mivek - */ -@Ignore -public abstract class AbstractParserTest { - @Rule - public ExpectedException thrown = ExpectedException.none(); - - /* - * =================== WEATHER CONDITION =================== - */ - @Test - public void testParseWCSimple() { - String wcPart = "-DZ"; - - WeatherCondition wc = getSut().parseWeatherCondition(wcPart); - - assertEquals(Intensity.LIGHT, wc.getIntensity()); - assertNull(wc.getDescriptive()); - assertThat(wc.getPhenomenons(), hasSize(1)); - assertThat(wc.getPhenomenons(), hasItem(Phenomenon.DRIZZLE)); - } - - @Test - public void testParseWCMultiplePHE() { - String wcPart = "SHRAGR"; - - WeatherCondition wc = getSut().parseWeatherCondition(wcPart); - - assertNull(wc.getIntensity()); - assertNotNull(wc.getDescriptive()); - assertEquals(Descriptive.SHOWERS, wc.getDescriptive()); - assertThat(wc.getPhenomenons(), hasSize(2)); - assertThat(wc.getPhenomenons(), hasItems(Phenomenon.RAIN, Phenomenon.HAIL)); - } - - @Test - public void testParseWCNull() { - String wcPart = "-SH"; - - WeatherCondition wc = getSut().parseWeatherCondition(wcPart); - - assertNull(wc); - } - - @Test - public void testParseWCDescriptiveIsNotNullButPhenomenonCanBeEmptyAndIntensityCanBeNull() { - String wcPart = "SH"; - - WeatherCondition wc = getSut().parseWeatherCondition(wcPart); - - assertNull(wc); - } - - @Test - public void testTokenize() { - // GIVEN a string with 1 1/2SM - String code = "METAR KTTN 051853Z 04011KT 1 1/2SM VCTS SN FZFG BKN003 OVC010 M02/M02 A3006 RMK AO2 TSB40 SLP176 P0002 T10171017="; - String[] tokens = {"METAR", "KTTN", "051853Z", "04011KT", "1 1/2SM", "VCTS", "SN", "FZFG", "BKN003", "OVC010", "M02/M02", "A3006", "RMK", "AO2", "TSB40", "SLP176", "P0002", "T10171017"}; - // WHEN tokenizing the string - String[] result = getSut().tokenize(code); - // THEN the visibility part is 1 1/2SM - assertNotNull(result); - assertArrayEquals(tokens, result); - - } - - protected abstract AbstractParser getSut(); -} +package io.github.mivek.parser; + +import io.github.mivek.enums.Descriptive; +import io.github.mivek.enums.Intensity; +import io.github.mivek.enums.Phenomenon; +import io.github.mivek.model.AbstractWeatherCode; +import io.github.mivek.model.WeatherCondition; +import org.junit.Ignore; +import org.junit.Test; + +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.*; +import static org.junit.Assert.*; + +/** + * Test class for {@link AbstractParser} + * + * @author mivek + */ +@Ignore +public abstract class AbstractParserTest { + /* + * =================== WEATHER CONDITION =================== + */ + @Test + public void testParseWCSimple() { + String wcPart = "-DZ"; + + WeatherCondition wc = getSut().parseWeatherCondition(wcPart); + + assertEquals(Intensity.LIGHT, wc.getIntensity()); + assertNull(wc.getDescriptive()); + + assertThat(wc.getPhenomenons(), hasSize(1)); + assertThat(wc.getPhenomenons(), hasItem(Phenomenon.DRIZZLE)); + } + + @Test + public void testParseWCMultiplePHE() { + String wcPart = "SHRAGR"; + + WeatherCondition wc = getSut().parseWeatherCondition(wcPart); + + assertNull(wc.getIntensity()); + assertNotNull(wc.getDescriptive()); + assertEquals(Descriptive.SHOWERS, wc.getDescriptive()); + assertThat(wc.getPhenomenons(), hasSize(2)); + assertThat(wc.getPhenomenons(), hasItems(Phenomenon.RAIN, Phenomenon.HAIL)); + } + + @Test + public void testParseWCNull() { + String wcPart = "-SH"; + + WeatherCondition wc = getSut().parseWeatherCondition(wcPart); + + assertNull(wc); + } + + @Test + public void testParseWCDescriptiveIsNotNullButPhenomenonCanBeEmptyAndIntensityCanBeNull() { + String wcPart = "SH"; + + WeatherCondition wc = getSut().parseWeatherCondition(wcPart); + + assertNull(wc); + } + + @Test + public void testTokenize() { + // GIVEN a string with 1 1/2SM + String code = "METAR KTTN 051853Z 04011KT 1 1/2SM VCTS SN FZFG BKN003 OVC010 M02/M02 A3006 RMK AO2 TSB40 SLP176 P0002 T10171017="; + String[] tokens = { "METAR", "KTTN", "051853Z", "04011KT", "1 1/2SM", "VCTS", "SN", "FZFG", "BKN003", "OVC010", "M02/M02", "A3006", "RMK", "AO2", "TSB40", "SLP176", "P0002", "T10171017" }; + // WHEN tokenizing the string + String[] result = getSut().tokenize(code); + // THEN the visibility part is 1 1/2SM + assertNotNull(result); + assertArrayEquals(tokens, result); + + } + + protected abstract AbstractParser getSut(); +} diff --git a/src/test/java/io/github/mivek/parser/GeneralParseMetarTest.java b/metarParser-parsers/src/test/java/io/github/mivek/parser/GeneralParseMetarTest.java similarity index 96% rename from src/test/java/io/github/mivek/parser/GeneralParseMetarTest.java rename to metarParser-parsers/src/test/java/io/github/mivek/parser/GeneralParseMetarTest.java index 7a94546d..55ab2d58 100644 --- a/src/test/java/io/github/mivek/parser/GeneralParseMetarTest.java +++ b/metarParser-parsers/src/test/java/io/github/mivek/parser/GeneralParseMetarTest.java @@ -1,28 +1,28 @@ -package io.github.mivek.parser; - -import io.github.mivek.model.Metar; -import io.github.mivek.model.Visibility; -import io.github.mivek.model.Wind; -import io.github.mivek.model.WindShear; - -public class GeneralParseMetarTest extends GeneralParseTest { - - public GeneralParseMetarTest(String pPartToParse, boolean pExpected) { - super(pPartToParse, pExpected); - } - - @Override - protected Metar getWeatherCode() { - Metar m = new Metar(); - m.setWind(new Wind()); - m.setVisibility(new Visibility()); - m.setWindShear(new WindShear()); - return m; - } - - @Override - protected MetarParser getSut() { - return MetarParser.getInstance(); - } - -} +package io.github.mivek.parser; + +import io.github.mivek.model.Metar; +import io.github.mivek.model.Visibility; +import io.github.mivek.model.Wind; +import io.github.mivek.model.WindShear; + +public class GeneralParseMetarTest extends GeneralParseTest { + + public GeneralParseMetarTest(String pPartToParse, boolean pExpected) { + super(pPartToParse, pExpected); + } + + @Override + protected Metar getWeatherCode() { + Metar m = new Metar(); + m.setWind(new Wind()); + m.setVisibility(new Visibility()); + m.setWindShear(new WindShear()); + return m; + } + + @Override + protected MetarParser getSut() { + return MetarParser.getInstance(); + } + +} diff --git a/src/test/java/io/github/mivek/parser/GeneralParseTAFTest.java b/metarParser-parsers/src/test/java/io/github/mivek/parser/GeneralParseTAFTest.java similarity index 95% rename from src/test/java/io/github/mivek/parser/GeneralParseTAFTest.java rename to metarParser-parsers/src/test/java/io/github/mivek/parser/GeneralParseTAFTest.java index 40a85b70..fe3d675d 100644 --- a/src/test/java/io/github/mivek/parser/GeneralParseTAFTest.java +++ b/metarParser-parsers/src/test/java/io/github/mivek/parser/GeneralParseTAFTest.java @@ -1,26 +1,26 @@ -package io.github.mivek.parser; - -import io.github.mivek.model.TAF; -import io.github.mivek.model.Visibility; -import io.github.mivek.model.Wind; - -public class GeneralParseTAFTest extends GeneralParseTest { - - public GeneralParseTAFTest(String pPartToParse, boolean pExpected) { - super(pPartToParse, pExpected); - } - - @Override - protected TAF getWeatherCode() { - TAF taf = new TAF(); - taf.setVisibility(new Visibility()); - taf.setWind(new Wind()); - return taf; - } - - @Override - protected AbstractParser getSut() { - return TAFParser.getInstance(); - } - -} +package io.github.mivek.parser; + +import io.github.mivek.model.TAF; +import io.github.mivek.model.Visibility; +import io.github.mivek.model.Wind; + +public class GeneralParseTAFTest extends GeneralParseTest { + + public GeneralParseTAFTest(String pPartToParse, boolean pExpected) { + super(pPartToParse, pExpected); + } + + @Override + protected TAF getWeatherCode() { + TAF taf = new TAF(); + taf.setVisibility(new Visibility()); + taf.setWind(new Wind()); + return taf; + } + + @Override + protected AbstractParser getSut() { + return TAFParser.getInstance(); + } + +} diff --git a/src/test/java/io/github/mivek/parser/GeneralParseTest.java b/metarParser-parsers/src/test/java/io/github/mivek/parser/GeneralParseTest.java similarity index 55% rename from src/test/java/io/github/mivek/parser/GeneralParseTest.java rename to metarParser-parsers/src/test/java/io/github/mivek/parser/GeneralParseTest.java index 92c83e0f..4ff624a1 100644 --- a/src/test/java/io/github/mivek/parser/GeneralParseTest.java +++ b/metarParser-parsers/src/test/java/io/github/mivek/parser/GeneralParseTest.java @@ -1,55 +1,53 @@ -package io.github.mivek.parser; - -import io.github.mivek.model.AbstractWeatherCode; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.Parameterized; -import org.junit.runners.Parameterized.Parameters; - -import java.util.Arrays; -import java.util.Collection; - -import static org.junit.Assert.assertEquals; - -/** - * @author mivek - * - */ -@RunWith(Parameterized.class) -public abstract class GeneralParseTest { - - private String fPartToParse; - private boolean fExpected; - - @Parameters - public static Collection data() { - return Arrays.asList(new Object[][] { - { "WS020/24045KT", true }, // Wind shear - { "05009KT", true }, // Wind - { "030V113", true }, // Wind variable - { "9999", true }, // Main visibility - { "6 1/2SM", true}, //Main visibility SM - { "1100w", true }, // Min visibility - { "VV002", true }, // Vertical visibility - { "CAVOK", true }, // CAVOK - { "SCT026CB", true }, // Cloud - { "ZZZ026CB", false }, // Cloud null - { "+SHGSRA", true }, // Weather condition - { "+ZERT", false } // Weather null - }); - } - - public GeneralParseTest(final String pPartToParse, final boolean pExpected) { - fPartToParse = pPartToParse; - fExpected = pExpected; - } - - @Test - public void testGeneralParse() { - assertEquals(fExpected, getSut().generalParse(getWeatherCode(), fPartToParse)); - } - - protected abstract T getWeatherCode(); - - protected abstract AbstractParser getSut(); -} +package io.github.mivek.parser; + +import io.github.mivek.model.AbstractWeatherCode; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.Parameterized; +import org.junit.runners.Parameterized.Parameters; + +import java.util.Arrays; +import java.util.Collection; + +import static org.junit.Assert.assertEquals; + +/** + * @author mivek + */ +@RunWith(Parameterized.class) +public abstract class GeneralParseTest { + + private final String fPartToParse; + private final boolean fExpected; + + @Parameters + public static Collection data() { + return Arrays.asList(new Object[][] { { "WS020/24045KT", true }, // Wind shear + { "05009KT", true }, // Wind + { "030V113", true }, // Wind variable + { "9999", true }, // Main visibility + { "6 1/2SM", true }, //Main visibility SM + { "1100w", true }, // Min visibility + { "VV002", true }, // Vertical visibility + { "CAVOK", true }, // CAVOK + { "SCT026CB", true }, // Cloud + { "ZZZ026CB", false }, // Cloud null + { "+SHGSRA", true }, // Weather condition + { "+ZERT", false } // Weather null + }); + } + + public GeneralParseTest(final String pPartToParse, final boolean pExpected) { + fPartToParse = pPartToParse; + fExpected = pExpected; + } + + @Test + public void testGeneralParse() { + assertEquals(fExpected, getSut().generalParse(getWeatherCode(), fPartToParse)); + } + + protected abstract T getWeatherCode(); + + protected abstract AbstractParser getSut(); +} diff --git a/src/test/java/io/github/mivek/parser/MetarParserTest.java b/metarParser-parsers/src/test/java/io/github/mivek/parser/MetarParserTest.java similarity index 94% rename from src/test/java/io/github/mivek/parser/MetarParserTest.java rename to metarParser-parsers/src/test/java/io/github/mivek/parser/MetarParserTest.java index dbf2419d..9a427f76 100644 --- a/src/test/java/io/github/mivek/parser/MetarParserTest.java +++ b/metarParser-parsers/src/test/java/io/github/mivek/parser/MetarParserTest.java @@ -1,375 +1,375 @@ -package io.github.mivek.parser; - -import io.github.mivek.enums.CloudQuantity; -import io.github.mivek.enums.CloudType; -import io.github.mivek.enums.Descriptive; -import io.github.mivek.enums.Phenomenon; -import io.github.mivek.enums.TimeIndicator; -import io.github.mivek.enums.WeatherChangeType; -import io.github.mivek.exception.ParseException; -import io.github.mivek.internationalization.Messages; -import io.github.mivek.model.Cloud; -import io.github.mivek.model.Metar; -import io.github.mivek.model.Visibility; -import io.github.mivek.model.WeatherCondition; -import io.github.mivek.model.Wind; -import io.github.mivek.model.trend.AbstractMetarTrend; -import org.junit.Before; -import org.junit.Test; - -import static org.hamcrest.Matchers.*; -import static org.junit.Assert.*; - -/** - * Test class for {@link MetarParser} - * - * @author mivek - */ -public class MetarParserTest extends AbstractParserTest { - - private MetarParser fSut; - - @Override - protected MetarParser getSut() { - return fSut; - } - - @Before - public void setUp() { - fSut = MetarParser.getInstance(); - } - - - /** - * =========================== Test ParseMetarAction =========================== - */ - - @Test - public void testParse() { - String metarString = "LFPG 170830Z 00000KT 0350 R27L/0375N R09R/0175N R26R/0500D R08L/0400N R26L/0275D R08R/0250N R27R/0300N R09L/0200N FG SCT000 M01/M01 Q1026 NOSIG"; - - Metar m = fSut.parse(metarString); - - assertNotNull(m); - - assertEquals(fSut.getAirportSupplier().get("LFPG"), m.getAirport()); - assertEquals(Integer.valueOf(17), m.getDay()); - assertEquals(8, m.getTime().getHour()); - assertEquals(30, m.getTime().getMinute()); - assertNotNull(m.getWind()); - assertEquals(0, m.getWind().getSpeed()); - assertEquals(Messages.getInstance().getString("Converter.N"), m.getWind().getDirection()); - assertEquals("KT", m.getWind().getUnit()); - assertNotNull(m.getVisibility()); - assertEquals(metarString, m.getMessage()); - assertEquals("350m", m.getVisibility().getMainVisibility()); - assertThat(m.getRunways(), is(not(empty()))); - assertThat(m.getRunways(), hasSize(8)); - // Check if runways are correctly parsed - assertEquals("27L", m.getRunways().get(0).getName()); - assertEquals(375, m.getRunways().get(0).getMinRange()); - assertEquals(Messages.getInstance().getString("Converter.NSC"), m.getRunways().get(0).getTrend()); - } - - @Test - public void testParseNullAirport() { - String metarString = "AAAA 170830Z 00000KT 0350 R27L/0375N R09R/0175N R26R/0500D R08L/0400N R26L/0275D R08R/0250N R27R/0300N R09L/0200N FG SCT000 M01/M01 Q1026 NOSIG"; - Metar m = fSut.parse(metarString); - assertEquals("AAAA", m.getStation()); - assertNull(m.getAirport()); - } - - @Test - public void testParseWithTempo() { - String metarString = "LFBG 081130Z AUTO 23012KT 9999 SCT022 BKN072 BKN090 22/16 Q1011 TEMPO 26015G25KT 3000 TSRA SCT025CB BKN050"; - - Metar m = fSut.parse(metarString); - assertNotNull(m); - assertTrue(m.isAuto()); - assertThat(m.getClouds(), hasSize(3)); - assertThat(m.getTrends(), hasSize(1)); - AbstractMetarTrend trend = m.getTrends().get(0); - assertThat(trend.getType(), is(WeatherChangeType.TEMPO)); - assertNotNull(trend.getWind()); - assertEquals(Integer.valueOf(260), trend.getWind().getDirectionDegrees()); - assertEquals(15, trend.getWind().getSpeed()); - assertEquals(25, trend.getWind().getGust()); - assertThat(trend.getTimes(), hasSize(0)); - assertNotNull(trend.getVisibility()); - assertEquals("3000m", trend.getVisibility().getMainVisibility()); - assertThat(trend.getWeatherConditions(), hasSize(1)); - WeatherCondition wc = trend.getWeatherConditions().get(0); - assertEquals(Descriptive.THUNDERSTORM, wc.getDescriptive()); - assertThat(wc.getPhenomenons(), hasSize(1)); - assertEquals(Phenomenon.RAIN, wc.getPhenomenons().get(0)); - assertThat(trend.getClouds(), hasSize(2)); - Cloud c1 = trend.getClouds().get(0); - assertEquals(CloudQuantity.SCT, c1.getQuantity()); - assertEquals(2500, c1.getHeight()); - assertEquals(CloudType.CB, c1.getType()); - Cloud c2 = trend.getClouds().get(1); - assertEquals(CloudQuantity.BKN, c2.getQuantity()); - assertEquals(5000, c2.getHeight()); - } - - @Test - public void testParseWithTempoAndBecmg() { - String metarString = "LFRM 081630Z AUTO 30007KT 260V360 9999 24/15 Q1008 TEMPO SHRA BECMG SKC"; - - Metar m = fSut.parse(metarString); - - assertNotNull(m); - assertThat(m.getTrends(), hasSize(2)); - assertThat(m.getTrends().get(0).getType(), is(WeatherChangeType.TEMPO)); - assertThat(m.getTrends().get(0).getWeatherConditions(), hasSize(1)); - WeatherCondition wc = m.getTrends().get(0).getWeatherConditions().get(0); - assertEquals(Descriptive.SHOWERS, wc.getDescriptive()); - assertThat(wc.getPhenomenons(), hasSize(1)); - assertThat(m.getTrends().get(1).getType(), is(WeatherChangeType.BECMG)); - assertThat(m.getTrends().get(1).getClouds(), hasSize(1)); - } - - @Test - public void testParseWithTempoAndAT() { - String metarString = "LFRM 081630Z AUTO 30007KT 260V360 9999 24/15 Q1008 TEMPO AT0800 SHRA "; - - Metar m = fSut.parse(metarString); - - assertNotNull(m); - assertThat(m.getTrends(), hasSize(1)); - assertThat(m.getTrends().get(0).getType(), is(WeatherChangeType.TEMPO)); - assertThat(m.getTrends().get(0).getWeatherConditions(), hasSize(1)); - AbstractMetarTrend trend = m.getTrends().get(0); - WeatherCondition wc = trend.getWeatherConditions().get(0); - assertEquals(Descriptive.SHOWERS, wc.getDescriptive()); - assertThat(wc.getPhenomenons(), hasSize(1)); - assertThat(trend.getTimes(), hasSize(1)); - assertEquals(TimeIndicator.AT, trend.getTimes().get(0).getType()); - assertEquals(8, trend.getTimes().get(0).getTime().getHour()); - assertEquals(0, trend.getTimes().get(0).getTime().getMinute()); - } - - @Test - public void testParseWithTempoAndTL() { - String metarString = "LFRM 081630Z AUTO 30007KT 260V360 9999 24/15 Q1008 TEMPO TL1830 SHRA "; - - Metar m = fSut.parse(metarString); - - assertNotNull(m); - assertThat(m.getTrends(), hasSize(1)); - assertThat(m.getTrends().get(0).getType(), is(WeatherChangeType.TEMPO)); - assertThat(m.getTrends().get(0).getWeatherConditions(), hasSize(1)); - AbstractMetarTrend trend = m.getTrends().get(0); - WeatherCondition wc = trend.getWeatherConditions().get(0); - assertEquals(Descriptive.SHOWERS, wc.getDescriptive()); - assertThat(wc.getPhenomenons(), hasSize(1)); - assertThat(trend.getTimes(), hasSize(1)); - assertEquals(TimeIndicator.TL, trend.getTimes().get(0).getType()); - assertEquals(18, trend.getTimes().get(0).getTime().getHour()); - assertEquals(30, trend.getTimes().get(0).getTime().getMinute()); - } - - @Test - public void testParseWithTempoAndFM() { - String metarString = "LFRM 081630Z AUTO 30007KT 260V360 9999 24/15 Q1008 TEMPO FM1830 SHRA "; - - Metar m = fSut.parse(metarString); - - assertNotNull(m); - assertThat(m.getTrends(), hasSize(1)); - assertThat(m.getTrends().get(0).getType(), is(WeatherChangeType.TEMPO)); - assertThat(m.getTrends().get(0).getWeatherConditions(), hasSize(1)); - AbstractMetarTrend trend = m.getTrends().get(0); - WeatherCondition wc = trend.getWeatherConditions().get(0); - assertEquals(Descriptive.SHOWERS, wc.getDescriptive()); - assertThat(wc.getPhenomenons(), hasSize(1)); - assertThat(trend.getTimes(), hasSize(1)); - assertEquals(TimeIndicator.FM, trend.getTimes().get(0).getType()); - assertEquals(18, trend.getTimes().get(0).getTime().getHour()); - assertEquals(30, trend.getTimes().get(0).getTime().getMinute()); - } - - @Test - public void testParseWithTempoAndFMAndTL() { - String metarString = "LFRM 081630Z AUTO 30007KT 260V360 9999 24/15 Q1008 TEMPO FM1700 TL1830 SHRA "; - - Metar m = fSut.parse(metarString); - - assertNotNull(m); - assertThat(m.getTrends(), hasSize(1)); - assertThat(m.getTrends().get(0).getType(), is(WeatherChangeType.TEMPO)); - assertThat(m.getTrends().get(0).getWeatherConditions(), hasSize(1)); - AbstractMetarTrend trend = m.getTrends().get(0); - WeatherCondition wc = trend.getWeatherConditions().get(0); - assertEquals(Descriptive.SHOWERS, wc.getDescriptive()); - assertEquals(Phenomenon.RAIN, wc.getPhenomenons().get(0)); - assertThat(wc.getPhenomenons(), hasSize(1)); - assertThat(trend.getTimes(), hasSize(2)); - assertEquals(TimeIndicator.FM, trend.getTimes().get(0).getType()); - assertEquals(17, trend.getTimes().get(0).getTime().getHour()); - assertEquals(0, trend.getTimes().get(0).getTime().getMinute()); - assertEquals(TimeIndicator.TL, trend.getTimes().get(1).getType()); - assertEquals(18, trend.getTimes().get(1).getTime().getHour()); - assertEquals(30, trend.getTimes().get(1).getTime().getMinute()); - String toString = m.toString(); - assertThat(toString, containsString(Messages.getInstance().getString("WeatherChangeType.FM") + " 17:00")); - assertThat(toString, containsString(Messages.getInstance().getString("TimeIndicator.TL") + " 18:30")); - assertThat(toString, containsString(Descriptive.SHOWERS.toString())); - assertThat(toString, containsString(Phenomenon.RAIN.toString())); - assertNotNull(m.getVisibility()); - assertEquals(">10km", m.getVisibility().getMainVisibility()); - } - - @Test - public void testParseWithMinVisibility() { - String code = "LFPG 161430Z 24015G25KT 5000 1100w"; - - Metar m = fSut.parse(code); - - assertNotNull(m); - assertEquals(16, m.getDay().intValue()); - assertEquals(14, m.getTime().getHour()); - assertEquals(30, m.getTime().getMinute()); - assertNotNull(m.getWind()); - Wind w = m.getWind(); - assertEquals(240, w.getDirectionDegrees().intValue()); - assertEquals(15, w.getSpeed()); - assertEquals(25, w.getGust()); - assertNotNull(m.getVisibility()); - Visibility v = m.getVisibility(); - assertEquals("5000m", v.getMainVisibility()); - assertEquals(1100, v.getMinVisibility()); - assertEquals("w", v.getMinDirection()); - String des = m.toString(); - - assertThat(des, containsString(Messages.getInstance().getString("ToString.day.month") + "=16")); - assertThat(des, containsString(Messages.getInstance().getString("ToString.report.time") + "=14:30")); - assertThat(des, containsString(Messages.getInstance().getString("ToString.wind.direction.degrees") + "=240")); - } - - @Test - public void testParseWithMaximalWind() { - // Given a code with wind variation. - String code = "LFPG 161430Z 24015G25KT 180V300"; - //WHEN parsing the code. - Metar m = fSut.parse(code); - // THEN the wind contains information on variation - assertNotNull(m); - assertEquals(240, m.getWind().getDirectionDegrees().intValue()); - assertEquals(15, m.getWind().getSpeed()); - assertEquals(25, m.getWind().getGust()); - assertEquals("KT", m.getWind().getUnit()); - assertEquals(180, m.getWind().getExtreme1()); - assertEquals(300, m.getWind().getExtreme2()); - - } - - @Test - public void testParseWithVerticalVisibility() { - String code = "LFLL 160730Z 28002KT 0350 FG VV002"; - - Metar m = fSut.parse(code); - - assertNotNull(m); - assertEquals(16, m.getDay().intValue()); - assertEquals(7, m.getTime().getHour()); - assertEquals(30, m.getTime().getMinute()); - assertNotNull(m.getWind()); - Wind w = m.getWind(); - assertEquals(280, w.getDirectionDegrees().intValue()); - assertEquals(2, w.getSpeed()); - - assertNotNull(m.getVisibility()); - assertEquals("350m", m.getVisibility().getMainVisibility()); - assertThat(m.getWeatherConditions(), hasSize(1)); - assertEquals(Phenomenon.FOG, m.getWeatherConditions().get(0).getPhenomenons().get(0)); - assertNotNull(m.getVerticalVisibility()); - assertEquals(200, m.getVerticalVisibility().intValue()); - assertThat(m.toString(), containsString(Messages.getInstance().getString("ToString.visibility.main") + "=350m")); - } - - @Test - public void testParseVisibilityWithNDV() { - String code = "LSZL 300320Z AUTO 00000KT 9999NDV BKN060 OVC074 00/M04 Q1001\n" + "RMK="; - Metar m = fSut.parse(code); - assertNotNull(m); - assertEquals(">10km", m.getVisibility().getMainVisibility()); - } - - @Test - public void testParseWithCavok() { - // GIVEN a metar with token CAVOK - String code = "LFPG 212030Z 03003KT CAVOK 09/06 Q1031 NOSIG"; - // WHEN parsing the metar. - Metar m = fSut.parse(code); - // THEN the attribute cavok is true and the main visibility is > 10km. - assertNotNull(m); - assertTrue(m.isCavok()); - assertEquals(">10km", m.getVisibility().getMainVisibility()); - assertEquals(Integer.valueOf(9), m.getTemperature()); - assertEquals(Integer.valueOf(6), m.getDewPoint()); - assertEquals(Integer.valueOf(1031), m.getAltimeter()); - assertTrue(m.isNosig()); - } - - @Test - public void testParseWithAltimeterInMercury() { - // GIVEN a metar with altimeter in inches of mercury - String code = "KTTN 051853Z 04011KT 9999 VCTS SN FZFG BKN003 OVC010 M02/M02 A3006"; - // WHEN parsing the metar - Metar m = fSut.parse(code); - // THEN the altimeter is converted in HPa - assertNotNull(m); - assertEquals(Integer.valueOf(1017), m.getAltimeter()); - assertThat(m.getWeatherConditions(), is(notNullValue())); - assertThat(m.getWeatherConditions(), hasSize(3)); - } - - @Test - public void testParseWithRMK() { - //GIVEN a metar with RMK - String code = "CYWG 172000Z 30015G25KT 1 3/4SM R36/4000FT/D -SN BLSN BKN008 OVC040 M05/M08 Q1001 RMK SF5NS3 SLP134"; - // WHEN parsing the metar - Metar m = fSut.parse(code); - // THEN the remark is not null - assertNotNull(m); - assertNotNull(m.getVisibility()); - assertEquals("1 3/4SM", m.getVisibility().getMainVisibility()); - assertThat(m.getRemark(), containsString("SF5NS3 " + Messages.getInstance().getString("Remark.Sea.Level.Pressure", "1013.4"))); - } - - @Test - public void testParseRMK() { - Metar m = new Metar(); - String[] array = {"RMK", "AO2", "TSB40", "SLP176", "P0002", "T10171017="}; - getSut().parseRMK(m, array, 0); - String rmk = m.getRemark(); - assertNotNull(rmk); - assertThat(rmk, not(containsString("RMK"))); - } - - @Test - public void alternativeWindForm() { - String code = "ENLK 081350Z 26026G40 240V300 9999 VCSH FEW025 BKN030 02/M01 Q0996"; - Metar m = fSut.parse(code); - assertNotNull(m); - assertNotNull(m.getWind()); - assertEquals(Integer.valueOf(260), m.getWind().getDirectionDegrees()); - assertEquals(26, m.getWind().getSpeed()); - assertEquals(40, m.getWind().getGust()); - assertEquals("KT", m.getWind().getUnit()); - assertEquals(240, m.getWind().getExtreme1()); - assertEquals(300, m.getWind().getExtreme2()); - } - - @Test - public void desriptiveFieldIsPreservedAlsoWithoutWeatherConditions() { - //example form field - String code = "AGGH 140340Z 05010KT 9999 TS FEW020 SCT021CB BKN300 32/26 Q1010"; - Metar m = fSut.parse(code); - assertNotNull(m); - assertEquals(1, m.getWeatherConditions().size()); - assertEquals(Descriptive.THUNDERSTORM, m.getWeatherConditions().get(0).getDescriptive()); - } - -} +package io.github.mivek.parser; + +import io.github.mivek.enums.CloudQuantity; +import io.github.mivek.enums.CloudType; +import io.github.mivek.enums.Descriptive; +import io.github.mivek.enums.Phenomenon; +import io.github.mivek.enums.TimeIndicator; +import io.github.mivek.enums.WeatherChangeType; +import io.github.mivek.internationalization.Messages; +import io.github.mivek.model.Cloud; +import io.github.mivek.model.Metar; +import io.github.mivek.model.Visibility; +import io.github.mivek.model.WeatherCondition; +import io.github.mivek.model.Wind; +import io.github.mivek.model.trend.AbstractMetarTrend; +import org.junit.Before; +import org.junit.Test; + +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.*; +import static org.junit.Assert.*; + +/** + * Test class for {@link MetarParser} + * + * @author mivek + */ +public class MetarParserTest extends AbstractParserTest { + + public static final String TEN_KM = ">10km"; + private MetarParser fSut; + + @Override + protected MetarParser getSut() { + return fSut; + } + + @Before + public void setUp() { + fSut = MetarParser.getInstance(); + } + + /** + * =========================== Test ParseMetarAction =========================== + */ + + @Test + public void testParse() { + String metarString = "LFPG 170830Z 00000KT 0350 R27L/0375N R09R/0175N R26R/0500D R08L/0400N R26L/0275D R08R/0250N R27R/0300N R09L/0200N FG SCT000 M01/M01 Q1026 NOSIG"; + + Metar m = fSut.parse(metarString); + + assertNotNull(m); + + assertEquals(fSut.getAirportSupplier().get("LFPG"), m.getAirport()); + assertEquals(Integer.valueOf(17), m.getDay()); + assertEquals(8, m.getTime().getHour()); + assertEquals(30, m.getTime().getMinute()); + assertNotNull(m.getWind()); + assertEquals(0, m.getWind().getSpeed()); + assertEquals(Messages.getInstance().getString("Converter.N"), m.getWind().getDirection()); + assertEquals("KT", m.getWind().getUnit()); + assertNotNull(m.getVisibility()); + assertEquals(metarString, m.getMessage()); + assertEquals("350m", m.getVisibility().getMainVisibility()); + assertThat(m.getRunways(), is(not(empty()))); + assertThat(m.getRunways(), hasSize(8)); + // Check if runways are correctly parsed + assertEquals("27L", m.getRunways().get(0).getName()); + assertEquals(375, m.getRunways().get(0).getMinRange()); + assertEquals(Messages.getInstance().getString("Converter.NSC"), m.getRunways().get(0).getTrend()); + } + + @Test + public void testParseNullAirport() { + String metarString = "AAAA 170830Z 00000KT 0350 R27L/0375N R09R/0175N R26R/0500D R08L/0400N R26L/0275D R08R/0250N R27R/0300N R09L/0200N FG SCT000 M01/M01 Q1026 NOSIG"; + Metar m = fSut.parse(metarString); + assertEquals("AAAA", m.getStation()); + assertNull(m.getAirport()); + } + + @Test + public void testParseWithTempo() { + String metarString = "LFBG 081130Z AUTO 23012KT 9999 SCT022 BKN072 BKN090 22/16 Q1011 TEMPO 26015G25KT 3000 TSRA SCT025CB BKN050"; + + Metar m = fSut.parse(metarString); + assertNotNull(m); + assertTrue(m.isAuto()); + assertThat(m.getClouds(), hasSize(3)); + assertThat(m.getTrends(), hasSize(1)); + AbstractMetarTrend trend = m.getTrends().get(0); + assertThat(trend.getType(), is(WeatherChangeType.TEMPO)); + assertNotNull(trend.getWind()); + assertEquals(Integer.valueOf(260), trend.getWind().getDirectionDegrees()); + assertEquals(15, trend.getWind().getSpeed()); + assertEquals(25, trend.getWind().getGust()); + assertThat(trend.getTimes(), hasSize(0)); + assertNotNull(trend.getVisibility()); + assertEquals("3000m", trend.getVisibility().getMainVisibility()); + assertThat(trend.getWeatherConditions(), hasSize(1)); + WeatherCondition wc = trend.getWeatherConditions().get(0); + assertEquals(Descriptive.THUNDERSTORM, wc.getDescriptive()); + assertThat(wc.getPhenomenons(), hasSize(1)); + assertEquals(Phenomenon.RAIN, wc.getPhenomenons().get(0)); + assertThat(trend.getClouds(), hasSize(2)); + Cloud c1 = trend.getClouds().get(0); + assertEquals(CloudQuantity.SCT, c1.getQuantity()); + assertEquals(2500, c1.getHeight()); + assertEquals(CloudType.CB, c1.getType()); + Cloud c2 = trend.getClouds().get(1); + assertEquals(CloudQuantity.BKN, c2.getQuantity()); + assertEquals(5000, c2.getHeight()); + } + + @Test + public void testParseWithTempoAndBecmg() { + String metarString = "LFRM 081630Z AUTO 30007KT 260V360 9999 24/15 Q1008 TEMPO SHRA BECMG SKC"; + + Metar m = fSut.parse(metarString); + + assertNotNull(m); + assertThat(m.getTrends(), hasSize(2)); + assertThat(m.getTrends().get(0).getType(), is(WeatherChangeType.TEMPO)); + assertThat(m.getTrends().get(0).getWeatherConditions(), hasSize(1)); + WeatherCondition wc = m.getTrends().get(0).getWeatherConditions().get(0); + assertEquals(Descriptive.SHOWERS, wc.getDescriptive()); + assertThat(wc.getPhenomenons(), hasSize(1)); + assertThat(m.getTrends().get(1).getType(), is(WeatherChangeType.BECMG)); + assertThat(m.getTrends().get(1).getClouds(), hasSize(1)); + } + + @Test + public void testParseWithTempoAndAT() { + String metarString = "LFRM 081630Z AUTO 30007KT 260V360 9999 24/15 Q1008 TEMPO AT0800 SHRA "; + + Metar m = fSut.parse(metarString); + + assertNotNull(m); + assertThat(m.getTrends(), hasSize(1)); + assertThat(m.getTrends().get(0).getType(), is(WeatherChangeType.TEMPO)); + assertThat(m.getTrends().get(0).getWeatherConditions(), hasSize(1)); + AbstractMetarTrend trend = m.getTrends().get(0); + WeatherCondition wc = trend.getWeatherConditions().get(0); + assertEquals(Descriptive.SHOWERS, wc.getDescriptive()); + assertThat(wc.getPhenomenons(), hasSize(1)); + assertThat(trend.getTimes(), hasSize(1)); + assertEquals(TimeIndicator.AT, trend.getTimes().get(0).getType()); + assertEquals(8, trend.getTimes().get(0).getTime().getHour()); + assertEquals(0, trend.getTimes().get(0).getTime().getMinute()); + } + + @Test + public void testParseWithTempoAndTL() { + String metarString = "LFRM 081630Z AUTO 30007KT 260V360 9999 24/15 Q1008 TEMPO TL1830 SHRA "; + + Metar m = fSut.parse(metarString); + + assertNotNull(m); + assertThat(m.getTrends(), hasSize(1)); + assertThat(m.getTrends().get(0).getType(), is(WeatherChangeType.TEMPO)); + assertThat(m.getTrends().get(0).getWeatherConditions(), hasSize(1)); + AbstractMetarTrend trend = m.getTrends().get(0); + WeatherCondition wc = trend.getWeatherConditions().get(0); + assertEquals(Descriptive.SHOWERS, wc.getDescriptive()); + assertThat(wc.getPhenomenons(), hasSize(1)); + assertThat(trend.getTimes(), hasSize(1)); + assertEquals(TimeIndicator.TL, trend.getTimes().get(0).getType()); + assertEquals(18, trend.getTimes().get(0).getTime().getHour()); + assertEquals(30, trend.getTimes().get(0).getTime().getMinute()); + } + + @Test + public void testParseWithTempoAndFM() { + String metarString = "LFRM 081630Z AUTO 30007KT 260V360 9999 24/15 Q1008 TEMPO FM1830 SHRA "; + + Metar m = fSut.parse(metarString); + + assertNotNull(m); + assertThat(m.getTrends(), hasSize(1)); + assertThat(m.getTrends().get(0).getType(), is(WeatherChangeType.TEMPO)); + assertThat(m.getTrends().get(0).getWeatherConditions(), hasSize(1)); + AbstractMetarTrend trend = m.getTrends().get(0); + WeatherCondition wc = trend.getWeatherConditions().get(0); + assertEquals(Descriptive.SHOWERS, wc.getDescriptive()); + assertThat(wc.getPhenomenons(), hasSize(1)); + assertThat(trend.getTimes(), hasSize(1)); + assertEquals(TimeIndicator.FM, trend.getTimes().get(0).getType()); + assertEquals(18, trend.getTimes().get(0).getTime().getHour()); + assertEquals(30, trend.getTimes().get(0).getTime().getMinute()); + } + + @Test + public void testParseWithTempoAndFMAndTL() { + String metarString = "LFRM 081630Z AUTO 30007KT 260V360 9999 24/15 Q1008 TEMPO FM1700 TL1830 SHRA "; + + Metar m = fSut.parse(metarString); + + assertNotNull(m); + assertThat(m.getTrends(), hasSize(1)); + assertThat(m.getTrends().get(0).getType(), is(WeatherChangeType.TEMPO)); + assertThat(m.getTrends().get(0).getWeatherConditions(), hasSize(1)); + AbstractMetarTrend trend = m.getTrends().get(0); + WeatherCondition wc = trend.getWeatherConditions().get(0); + assertEquals(Descriptive.SHOWERS, wc.getDescriptive()); + assertEquals(Phenomenon.RAIN, wc.getPhenomenons().get(0)); + assertThat(wc.getPhenomenons(), hasSize(1)); + assertThat(trend.getTimes(), hasSize(2)); + assertEquals(TimeIndicator.FM, trend.getTimes().get(0).getType()); + assertEquals(17, trend.getTimes().get(0).getTime().getHour()); + assertEquals(0, trend.getTimes().get(0).getTime().getMinute()); + assertEquals(TimeIndicator.TL, trend.getTimes().get(1).getType()); + assertEquals(18, trend.getTimes().get(1).getTime().getHour()); + assertEquals(30, trend.getTimes().get(1).getTime().getMinute()); + String toString = m.toString(); + assertThat(toString, containsString(Messages.getInstance().getString("WeatherChangeType.FM") + " 17:00")); + assertThat(toString, containsString(Messages.getInstance().getString("TimeIndicator.TL") + " 18:30")); + assertThat(toString, containsString(Descriptive.SHOWERS.toString())); + assertThat(toString, containsString(Phenomenon.RAIN.toString())); + assertNotNull(m.getVisibility()); + assertEquals(TEN_KM, m.getVisibility().getMainVisibility()); + } + + @Test + public void testParseWithMinVisibility() { + String code = "LFPG 161430Z 24015G25KT 5000 1100w"; + + Metar m = fSut.parse(code); + + assertNotNull(m); + assertEquals(16, m.getDay().intValue()); + assertEquals(14, m.getTime().getHour()); + assertEquals(30, m.getTime().getMinute()); + assertNotNull(m.getWind()); + Wind w = m.getWind(); + assertEquals(240, w.getDirectionDegrees().intValue()); + assertEquals(15, w.getSpeed()); + assertEquals(25, w.getGust()); + assertNotNull(m.getVisibility()); + Visibility v = m.getVisibility(); + assertEquals("5000m", v.getMainVisibility()); + assertEquals(1100, v.getMinVisibility()); + assertEquals("w", v.getMinDirection()); + String des = m.toString(); + + assertThat(des, containsString(Messages.getInstance().getString("ToString.day.month") + "=16")); + assertThat(des, containsString(Messages.getInstance().getString("ToString.report.time") + "=14:30")); + assertThat(des, containsString(Messages.getInstance().getString("ToString.wind.direction.degrees") + "=240")); + } + + @Test + public void testParseWithMaximalWind() { + // Given a code with wind variation. + String code = "LFPG 161430Z 24015G25KT 180V300"; + //WHEN parsing the code. + Metar m = fSut.parse(code); + // THEN the wind contains information on variation + assertNotNull(m); + assertEquals(240, m.getWind().getDirectionDegrees().intValue()); + assertEquals(15, m.getWind().getSpeed()); + assertEquals(25, m.getWind().getGust()); + assertEquals("KT", m.getWind().getUnit()); + assertEquals(180, m.getWind().getMinVariation()); + assertEquals(300, m.getWind().getMaxVariation()); + + } + + @Test + public void testParseWithVerticalVisibility() { + String code = "LFLL 160730Z 28002KT 0350 FG VV002"; + + Metar m = fSut.parse(code); + + assertNotNull(m); + assertEquals(16, m.getDay().intValue()); + assertEquals(7, m.getTime().getHour()); + assertEquals(30, m.getTime().getMinute()); + assertNotNull(m.getWind()); + Wind w = m.getWind(); + assertEquals(280, w.getDirectionDegrees().intValue()); + assertEquals(2, w.getSpeed()); + + assertNotNull(m.getVisibility()); + assertEquals("350m", m.getVisibility().getMainVisibility()); + assertThat(m.getWeatherConditions(), hasSize(1)); + assertEquals(Phenomenon.FOG, m.getWeatherConditions().get(0).getPhenomenons().get(0)); + assertNotNull(m.getVerticalVisibility()); + assertEquals(200, m.getVerticalVisibility().intValue()); + assertThat(m.toString(), containsString(Messages.getInstance().getString("ToString.visibility.main") + "=350m")); + } + + @Test + public void testParseVisibilityWithNDV() { + String code = "LSZL 300320Z AUTO 00000KT 9999NDV BKN060 OVC074 00/M04 Q1001\n" + "RMK="; + Metar m = fSut.parse(code); + assertNotNull(m); + assertEquals(TEN_KM, m.getVisibility().getMainVisibility()); + } + + @Test + public void testParseWithCavok() { + // GIVEN a metar with token CAVOK + String code = "LFPG 212030Z 03003KT CAVOK 09/06 Q1031 NOSIG"; + // WHEN parsing the metar. + Metar m = fSut.parse(code); + // THEN the attribute cavok is true and the main visibility is > 10km. + assertNotNull(m); + assertTrue(m.isCavok()); + assertEquals(TEN_KM, m.getVisibility().getMainVisibility()); + assertEquals(Integer.valueOf(9), m.getTemperature()); + assertEquals(Integer.valueOf(6), m.getDewPoint()); + assertEquals(Integer.valueOf(1031), m.getAltimeter()); + assertTrue(m.isNosig()); + } + + @Test + public void testParseWithAltimeterInMercury() { + // GIVEN a metar with altimeter in inches of mercury + String code = "KTTN 051853Z 04011KT 9999 VCTS SN FZFG BKN003 OVC010 M02/M02 A3006"; + // WHEN parsing the metar + Metar m = fSut.parse(code); + // THEN the altimeter is converted in HPa + assertNotNull(m); + assertEquals(Integer.valueOf(1017), m.getAltimeter()); + assertThat(m.getWeatherConditions(), is(notNullValue())); + assertThat(m.getWeatherConditions(), hasSize(3)); + } + + @Test + public void testParseWithRMK() { + //GIVEN a metar with RMK + String code = "CYWG 172000Z 30015G25KT 1 3/4SM R36/4000FT/D -SN BLSN BKN008 OVC040 M05/M08 Q1001 RMK SF5NS3 SLP134"; + // WHEN parsing the metar + Metar m = fSut.parse(code); + // THEN the remark is not null + assertNotNull(m); + assertNotNull(m.getVisibility()); + assertEquals("1 3/4SM", m.getVisibility().getMainVisibility()); + assertThat(m.getRemark(), containsString("SF5NS3 " + Messages.getInstance().getString("Remark.Sea.Level.Pressure", "1013.4"))); + } + + @Test + public void testParseRMK() { + Metar m = new Metar(); + String[] array = { "RMK", "AO2", "TSB40", "SLP176", "P0002", "T10171017=" }; + getSut().parseRMK(m, array, 0); + String rmk = m.getRemark(); + assertNotNull(rmk); + assertThat(rmk, not(containsString("RMK"))); + } + + @Test + public void alternativeWindForm() { + String code = "ENLK 081350Z 26026G40 240V300 9999 VCSH FEW025 BKN030 02/M01 Q0996"; + Metar m = fSut.parse(code); + assertNotNull(m); + assertNotNull(m.getWind()); + assertEquals(Integer.valueOf(260), m.getWind().getDirectionDegrees()); + assertEquals(26, m.getWind().getSpeed()); + assertEquals(40, m.getWind().getGust()); + assertEquals("KT", m.getWind().getUnit()); + assertEquals(240, m.getWind().getMinVariation()); + assertEquals(300, m.getWind().getMaxVariation()); + } + + @Test + public void desriptiveFieldIsPreservedAlsoWithoutWeatherConditions() { + //example form field + String code = "AGGH 140340Z 05010KT 9999 TS FEW020 SCT021CB BKN300 32/26 Q1010"; + Metar m = fSut.parse(code); + assertNotNull(m); + assertEquals(1, m.getWeatherConditions().size()); + assertEquals(Descriptive.THUNDERSTORM, m.getWeatherConditions().get(0).getDescriptive()); + } + +} diff --git a/src/test/java/io/github/mivek/parser/RemarkParserTest.java b/metarParser-parsers/src/test/java/io/github/mivek/parser/RemarkParserTest.java similarity index 71% rename from src/test/java/io/github/mivek/parser/RemarkParserTest.java rename to metarParser-parsers/src/test/java/io/github/mivek/parser/RemarkParserTest.java index a6978525..ee6a5ec0 100644 --- a/src/test/java/io/github/mivek/parser/RemarkParserTest.java +++ b/metarParser-parsers/src/test/java/io/github/mivek/parser/RemarkParserTest.java @@ -1,342 +1,385 @@ -package io.github.mivek.parser; - -import io.github.mivek.internationalization.Messages; -import org.junit.Before; -import org.junit.Test; - -import static org.hamcrest.Matchers.containsString; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertThat; - -public class RemarkParserTest { - private RemarkParser sut; - - @Before public void setUp() { - sut = RemarkParser.getInstance(); - } - - @Test public void testParseWithAO1() { - // GIVEN a RMK with AO1 token. - String code = "Token AO1 End of remark"; - // WHEN parsing the remark. - String remark = sut.parse(code); - // THEN the token is parsed and translated - assertNotNull(remark); - assertThat(remark, containsString(Messages.getInstance().getString("Remark.AO1"))); - } - - @Test public void testParseWithAO2() { - // GIVEN a RMK with AO2 token - String code = "Token AO2 End of remark"; - // WHEN parsing the remark. - String remark = sut.parse(code); - // THEN the token is parsed and translated - assertNotNull(remark); - assertThat(remark, containsString(Messages.getInstance().getString("Remark.AO2"))); - } - - @Test public void testParseWithWindPeakAtTheHour() { - // GIVEN a RMK with Peak wind at the hour. - String code = "AO1 PK WND 28045/15"; - // WHEN parsing the remark. - String remark = sut.parse(code); - // THEN the token is parsed and translated - assertNotNull(remark); - String rmk = Messages.getInstance().getString("Remark.PeakWind", "280", "45", "", "15"); - assertThat(remark, containsString(rmk)); - } - - @Test public void testParseWithWindPeakAtAnotherHour() { - // GIVEN a RMK with Peak wind at the hour. - String code = "AO1 PK WND 28045/1515"; - // WHEN parsing the remark. - String remark = sut.parse(code); - // THEN the token is parsed and translated - assertNotNull(remark); - String rmk = Messages.getInstance().getString("Remark.PeakWind", "280", "45", "15", "15"); - assertThat(remark, containsString(rmk)); - } - - @Test public void testParseWindShiftAtTheHour() { - // GIVEN a RMK with Wind shift at the hour - String code = "AO1 WSHFT 30"; - // WHEN parsing the remark. - String remark = sut.parse(code); - // THEN the remark contains the decoded wind shift - assertNotNull(remark); - String expectedRmk = Messages.getInstance().getString("Remark.WindShift", "", "30"); - assertThat(remark, containsString(expectedRmk)); - } - - @Test public void testParseWindShift() { - // GIVEN a RMK with Wind shift at the hour - String code = "AO1 WSHFT 1530"; - // WHEN parsing the remark. - String remark = sut.parse(code); - // THEN the remark contains the decoded wind shift - assertNotNull(remark); - String expectedRmk = Messages.getInstance().getString("Remark.WindShift", "15", "30"); - assertThat(remark, containsString(expectedRmk)); - } - - @Test public void testParseWindShiftWithFrontal() { - // GIVEN a RMK with wind shift with frontal passage - String code = "AO1 WSHFT 1530 FROPA"; - // WHEN parsing the remark - String remark = sut.parse(code); - // THEN the remark contains the decoded wind shift fropa - assertNotNull(remark); - String expectedRmk = Messages.getInstance().getString("Remark.WindShift.FROPA", "15", "30"); - assertThat(remark, containsString(expectedRmk)); - } - - @Test public void testParseWindShiftWithFrontalAtTheHour() { - // GIVEN a RMK with wind shift with frontal passage - String code = "AO1 WSHFT 30 FROPA"; - // WHEN parsing the remark - String remark = sut.parse(code); - // THEN the remark contains the decoded wind shift fropa - assertNotNull(remark); - String expectedRmk = Messages.getInstance().getString("Remark.WindShift.FROPA", "", "30"); - assertThat(remark, containsString(expectedRmk)); - } - - @Test public void testParseTowerVisibility() { - // GIVEN a rmk with tower visibility - String code = "AO1 TWR VIS 16 1/2"; - // WHEN parsing the remark - String remark = sut.parse(code); - // THEN the tower visibility is decoded - String expectedRmk = Messages.getInstance().getString("Remark.Tower.Visibility", "16 1/2"); - assertThat(remark, containsString(expectedRmk)); - } - - @Test public void testParseSurfaceVisibility() { - // GIVEN a rmk with surface visibility - String code = "AO1 SFC VIS 16 1/2"; - // WHEN parsing the remark - String remark = sut.parse(code); - // THEN the surface visibility is decoded - String expectedRmk = Messages.getInstance().getString("Remark.Surface.Visibility", "16 1/2"); - assertThat(remark, containsString(expectedRmk)); - } - - @Test public void testParsePrevailingVisibility() { - // GIVEN a rmk with variable prevailing visibility - String code = "AO1 VIS 1/2V2"; - // WHEN parsing the remark - String remark = sut.parse(code); - // THEN the variable prevailing visibility is decoded - String expectedRmk = Messages.getInstance().getString("Remark.Variable.Prevailing.Visibility", "1/2", "2"); - assertThat(remark, containsString(expectedRmk)); - } - - @Test public void testParseSectorVisibility() { - // GIVEN a rmk with sector visibility - String code = "AO1 VIS NE 2 1/2"; - // WHEN parsing the remark - String remark = sut.parse(code); - // THEN the sector visibility is decoded - String expectedRmk = Messages.getInstance().getString("Remark.Sector.Visibility", Messages.getInstance().getString("Converter.NE"), "2 1/2"); - assertThat(remark, containsString(expectedRmk)); - } - - @Test public void testParseSecondLocationVisibility() { - // GIVEN a rmk with visibility at second location - String code = "AO1 VIS 2 1/2 RWY11"; - // WHEN parsing the remark - String remark = sut.parse(code); - // THEN the visibility at second location is decoded - String expectedRmk = Messages.getInstance().getString("Remark.Second.Location.Visibility", "2 1/2", "RWY11"); - assertThat(remark, containsString(expectedRmk)); - } - - @Test public void testParseTornadicActivityWithTornado() { - String code = "AO1 TORNADO B13 6 NE"; - String remark = sut.parse(code); - String expectedRmk = Messages.getInstance() - .getString("Remark.Tornadic.Activity.Beginning", Messages.getInstance().getString("Remark.TORNADO"), "", "13", "6", Messages.getInstance().getString("Converter.NE")); - assertThat(remark, containsString(expectedRmk)); - } - - @Test public void testParseTornadicActivityWithTornadoAndHour() { - String code = "AO1 TORNADO B1513 6 NE"; - String remark = sut.parse(code); - String expectedRmk = Messages.getInstance() - .getString("Remark.Tornadic.Activity.Beginning", Messages.getInstance().getString("Remark.TORNADO"), "15", "13", "6", Messages.getInstance().getString("Converter.NE")); - assertThat(remark, containsString(expectedRmk)); - } - - @Test public void testParseTornadicActivityWithFunnelCloud() { - String code = "AO1 FUNNEL CLOUD B1513E1630 6 NE"; - String remark = sut.parse(code); - String expectedRmk = Messages.getInstance() - .getString("Remark.Tornadic.Activity.BegEnd", Messages.getInstance().getString("Remark.FUNNELCLOUD"), "15", "13", "16", "30", "6", Messages.getInstance().getString("Converter.NE")); - assertThat(remark, containsString(expectedRmk)); - } - - @Test public void testParseTornadicActivityWithFunnelCloudAndHourEnd() { - String code = "AO1 FUNNEL CLOUD B13E1630 6 NE"; - String remark = sut.parse(code); - String expectedRmk = Messages.getInstance() - .getString("Remark.Tornadic.Activity.BegEnd", Messages.getInstance().getString("Remark.FUNNELCLOUD"), "", "13", "16", "30", "6", Messages.getInstance().getString("Converter.NE")); - assertThat(remark, containsString(expectedRmk)); - } - - @Test public void testParseTornadicActivityWithWaterSproutAndEndingTimeOnlyMinutes() { - String code = "AO1 WATERSPOUT E16 12 NE"; - String remark = sut.parse(code); - String expectedRmk = Messages.getInstance() - .getString("Remark.Tornadic.Activity.Ending", Messages.getInstance().getString("Remark.WATERSPOUT"), "", "16", "12", Messages.getInstance().getString("Converter.NE")); - assertThat(remark, containsString(expectedRmk)); - } - - @Test public void testParseTornadicActivityWithWaterSproutAndEndingTime() { - String code = "AO1 WATERSPOUT E1516 12 NE"; - String remark = sut.parse(code); - String expectedRmk = Messages.getInstance() - .getString("Remark.Tornadic.Activity.Ending", Messages.getInstance().getString("Remark.WATERSPOUT"), "15", "16", "12", Messages.getInstance().getString("Converter.NE")); - assertThat(remark, containsString(expectedRmk)); - } - - @Test public void testParseBeginningEndPrecipitation() { - String code = "AO1 RAB05E30SNB1520E1655"; - String remark = sut.parse(code); - String expectedRmk1 = Messages.getInstance().getString("Remark.Precipitation.Beg.End", "", Messages.getInstance().getString("Phenomenon.RA"), "", "05", "", "30"); - String expectedRmk2 = Messages.getInstance().getString("Remark.Precipitation.Beg.End", "", Messages.getInstance().getString("Phenomenon.SN"), "15", "20", "16", "55"); - assertThat(remark, containsString(expectedRmk1)); - assertThat(remark, containsString(expectedRmk2)); - } - - @Test public void testParseBeginningEndPrecipitationWithDescriptive() { - String code = "AO1 SHRAB05E30SHSNB20E55"; - String remark = sut.parse(code); - String expectedRmk1 = Messages.getInstance() - .getString("Remark.Precipitation.Beg.End", Messages.getInstance().getString("Descriptive.SH"), Messages.getInstance().getString("Phenomenon.RA"), "", "05", "", "30"); - String expectedRmk2 = Messages.getInstance() - .getString("Remark.Precipitation.Beg.End", Messages.getInstance().getString("Descriptive.SH"), Messages.getInstance().getString("Phenomenon.SN"), "", "20", "", "55"); - assertThat(remark, containsString(expectedRmk1)); - assertThat(remark, containsString(expectedRmk2)); - } - - @Test public void testParseBeginningThunderstorm() { - String code = "AO1 TSB0159E30"; - String remark = sut.parse(code); - String expectedRmk1 = Messages.getInstance().getString("Remark.Precipitation.Beg.End", "", Messages.getInstance().getString("Phenomenon.TS"), "01", "59", "", "30"); - assertThat(remark, containsString(expectedRmk1)); - } - - @Test public void testParseThunderStormLocation() { - String code = "AO1 TS SE"; - String remark = sut.parse(code); - String expected = Messages.getInstance().getString("Remark.Thunderstorm.Location", Messages.getInstance().getString("Converter.SE")); - assertThat(remark, containsString(expected)); - } - - @Test public void testParseThunderStormLocationWithMoving() { - String code = "AO1 TS SE MOV NE"; - String remark = sut.parse(code); - String expected = Messages.getInstance().getString("Remark.Thunderstorm.Location.Moving", Messages.getInstance().getString("Converter.SE"), Messages.getInstance().getString("Converter.NE")); - assertThat(remark, containsString(expected)); - } - - @Test public void testParseHailSize() { - String code = "AO1 GR 1 3/4"; - String remark = sut.parse(code); - String expected = Messages.getInstance().getString("Remark.Hail", "1 3/4"); - assertThat(remark, containsString(expected)); - } - - @Test public void testParseHailSizeWithLesserThan() { - String code = "AO1 GR LESS THAN 1/4"; - String remark = sut.parse(code); - String expected = Messages.getInstance().getString("Remark.Hail.LesserThan", "1/4"); - assertThat(remark, containsString(expected)); - } - - @Test public void testParseSnowPellets() { - String code = "AO1 GS MOD"; - String remark = sut.parse(code); - String expected = Messages.getInstance().getString("Remark.Snow.Pellets", Messages.getInstance().getString("Remark.MOD")); - assertThat(remark, containsString(expected)); - } - - @Test public void testParseVirgaWithDirection() { - String code = "AO1 VIRGA SW"; - String remark = sut.parse(code); - String expected = Messages.getInstance().getString("Remark.Virga.Direction", Messages.getInstance().getString("Converter.SW")); - assertThat(remark, containsString(expected)); - } - - @Test public void testParseVirga() { - String code = "AO1 VIRGA"; - String remark = sut.parse(code); - assertThat(remark, containsString(Messages.getInstance().getString("Remark.VIRGA"))); - } - - @Test public void testParseCeilingHeight() { - String code = "AO1 CIG 005V010"; - String remark = sut.parse(code); - String expected = Messages.getInstance().getString("Remark.Ceiling.Height", 500, 1000); - assertThat(remark, containsString(expected)); - } - - @Test public void testParseObscurations() { - String code = "AO1 FU BKN020"; - String remark = sut.parse(code); - String expected = Messages.getInstance().getString("Remark.Obscuration", Messages.getInstance().getString("CloudQuantity.BKN"), 2000, Messages.getInstance().getString("Phenomenon.FU")); - assertThat(remark, containsString(expected)); - } - - @Test public void testParseVariableSkyConditionWithoutLayer() { - String code = "BKN V OVC"; - String remark = sut.parse(code); - String expected = Messages.getInstance() - .getString("Remark.Variable.Sky.Condition", Messages.getInstance().getString("CloudQuantity.BKN"), Messages.getInstance().getString("CloudQuantity.OVC")); - assertThat(remark, containsString(expected)); - } - - @Test public void testParseVariableSkyCondition() { - String code = "BKN014 V OVC"; - String remark = sut.parse(code); - String expected = Messages.getInstance() - .getString("Remark.Variable.Sky.Condition.Height", 1400, Messages.getInstance().getString("CloudQuantity.BKN"), Messages.getInstance().getString("CloudQuantity.OVC")); - assertThat(remark, containsString(expected)); - } - - @Test public void testParseCeilingSecondLocation() { - String code = "CIG 002 RWY11"; - String remark = sut.parse(code); - String expected = Messages.getInstance().getString("Remark.Ceiling.Second.Location", 200, "RWY11"); - assertThat(remark, containsString(expected)); - } - - @Test public void testParseSealLevelPressure() { - String code = "AO1 SLP134"; - String remark = sut.parse(code); - String expected = Messages.getInstance().getString("Remark.Sea.Level.Pressure", "1013.4"); - assertThat(remark, containsString(expected)); - } - - @Test public void testParseSealLevelPressure2() { - String code = "AO1 SLP982"; - String remark = sut.parse(code); - String expected = Messages.getInstance().getString("Remark.Sea.Level.Pressure", "998.2"); - assertThat(remark, containsString(expected)); - } - - @Test public void testParseSnowIncreasingRapidly() { - String code = "AO1 SNINCR 2/10"; - String remark = sut.parse(code); - String expected = Messages.getInstance().getString("Remark.Snow.Increasing.Rapidly", 2, 10); - assertThat(remark, containsString(expected)); - } - - @Test public void testParseWithRmkSlp() { - String code = "CF1AC8 CF TR SLP091 DENSITY ALT 200FT"; - - String remark = sut.parse(code); - assertThat(remark, containsString("CF1AC8 CF TR")); - assertThat(remark, containsString(Messages.getInstance().getString("Remark.Sea.Level.Pressure", "1009.1"))); - } -} +package io.github.mivek.parser; + +import io.github.mivek.internationalization.Messages; +import org.junit.Before; +import org.junit.Test; + +import static org.hamcrest.Matchers.containsString; +import static org.junit.Assert.assertNotNull; +import static org.hamcrest.MatcherAssert.assertThat; + +public class RemarkParserTest { + public static final String CLOUD_QUANTITY_BKN = "CloudQuantity.BKN"; + public static final String REMARK_PRECIPITATION_BEG_END = "Remark.Precipitation.Beg.End"; + public static final String CONVERTER_NE = "Converter.NE"; + public static final String REMARK_SEA_LEVEL_PRESSURE = "Remark.Sea.Level.Pressure"; + private RemarkParser sut; + + @Before + public void setUp() { + sut = RemarkParser.getInstance(); + } + + @Test + public void testParseWithAO1() { + // GIVEN a RMK with AO1 token. + String code = "Token AO1 End of remark"; + // WHEN parsing the remark. + String remark = sut.parse(code); + // THEN the token is parsed and translated + assertNotNull(remark); + assertThat(remark, containsString(Messages.getInstance().getString("Remark.AO1"))); + } + + @Test + public void testParseWithAO2() { + // GIVEN a RMK with AO2 token + String code = "Token AO2 End of remark"; + // WHEN parsing the remark. + String remark = sut.parse(code); + // THEN the token is parsed and translated + assertNotNull(remark); + assertThat(remark, containsString(Messages.getInstance().getString("Remark.AO2"))); + } + + @Test + public void testParseWithWindPeakAtTheHour() { + // GIVEN a RMK with Peak wind at the hour. + String code = "AO1 PK WND 28045/15"; + // WHEN parsing the remark. + String remark = sut.parse(code); + // THEN the token is parsed and translated + assertNotNull(remark); + String rmk = Messages.getInstance().getString("Remark.PeakWind", "280", "45", "", "15"); + assertThat(remark, containsString(rmk)); + } + + @Test + public void testParseWithWindPeakAtAnotherHour() { + // GIVEN a RMK with Peak wind at the hour. + String code = "AO1 PK WND 28045/1515"; + // WHEN parsing the remark. + String remark = sut.parse(code); + // THEN the token is parsed and translated + assertNotNull(remark); + String rmk = Messages.getInstance().getString("Remark.PeakWind", "280", "45", "15", "15"); + assertThat(remark, containsString(rmk)); + } + + @Test + public void testParseWindShiftAtTheHour() { + // GIVEN a RMK with Wind shift at the hour + String code = "AO1 WSHFT 30"; + // WHEN parsing the remark. + String remark = sut.parse(code); + // THEN the remark contains the decoded wind shift + assertNotNull(remark); + String expectedRmk = Messages.getInstance().getString("Remark.WindShift", "", "30"); + assertThat(remark, containsString(expectedRmk)); + } + + @Test + public void testParseWindShift() { + // GIVEN a RMK with Wind shift at the hour + String code = "AO1 WSHFT 1530"; + // WHEN parsing the remark. + String remark = sut.parse(code); + // THEN the remark contains the decoded wind shift + assertNotNull(remark); + String expectedRmk = Messages.getInstance().getString("Remark.WindShift", "15", "30"); + assertThat(remark, containsString(expectedRmk)); + } + + @Test + public void testParseWindShiftWithFrontal() { + // GIVEN a RMK with wind shift with frontal passage + String code = "AO1 WSHFT 1530 FROPA"; + // WHEN parsing the remark + String remark = sut.parse(code); + // THEN the remark contains the decoded wind shift fropa + assertNotNull(remark); + String expectedRmk = Messages.getInstance().getString("Remark.WindShift.FROPA", "15", "30"); + assertThat(remark, containsString(expectedRmk)); + } + + @Test + public void testParseWindShiftWithFrontalAtTheHour() { + // GIVEN a RMK with wind shift with frontal passage + String code = "AO1 WSHFT 30 FROPA"; + // WHEN parsing the remark + String remark = sut.parse(code); + // THEN the remark contains the decoded wind shift fropa + assertNotNull(remark); + String expectedRmk = Messages.getInstance().getString("Remark.WindShift.FROPA", "", "30"); + assertThat(remark, containsString(expectedRmk)); + } + + @Test + public void testParseTowerVisibility() { + // GIVEN a rmk with tower visibility + String code = "AO1 TWR VIS 16 1/2"; + // WHEN parsing the remark + String remark = sut.parse(code); + // THEN the tower visibility is decoded + String expectedRmk = Messages.getInstance().getString("Remark.Tower.Visibility", "16 1/2"); + assertThat(remark, containsString(expectedRmk)); + } + + @Test + public void testParseSurfaceVisibility() { + // GIVEN a rmk with surface visibility + String code = "AO1 SFC VIS 16 1/2"; + // WHEN parsing the remark + String remark = sut.parse(code); + // THEN the surface visibility is decoded + String expectedRmk = Messages.getInstance().getString("Remark.Surface.Visibility", "16 1/2"); + assertThat(remark, containsString(expectedRmk)); + } + + @Test + public void testParsePrevailingVisibility() { + // GIVEN a rmk with variable prevailing visibility + String code = "AO1 VIS 1/2V2"; + // WHEN parsing the remark + String remark = sut.parse(code); + // THEN the variable prevailing visibility is decoded + String expectedRmk = Messages.getInstance().getString("Remark.Variable.Prevailing.Visibility", "1/2", "2"); + assertThat(remark, containsString(expectedRmk)); + } + + @Test + public void testParseSectorVisibility() { + // GIVEN a rmk with sector visibility + String code = "AO1 VIS NE 2 1/2"; + // WHEN parsing the remark + String remark = sut.parse(code); + // THEN the sector visibility is decoded + String expectedRmk = Messages.getInstance().getString("Remark.Sector.Visibility", Messages.getInstance().getString(CONVERTER_NE), "2 1/2"); + assertThat(remark, containsString(expectedRmk)); + } + + @Test + public void testParseSecondLocationVisibility() { + // GIVEN a rmk with visibility at second location + String code = "AO1 VIS 2 1/2 RWY11"; + // WHEN parsing the remark + String remark = sut.parse(code); + // THEN the visibility at second location is decoded + String expectedRmk = Messages.getInstance().getString("Remark.Second.Location.Visibility", "2 1/2", "RWY11"); + assertThat(remark, containsString(expectedRmk)); + } + + @Test + public void testParseTornadicActivityWithTornado() { + String code = "AO1 TORNADO B13 6 NE"; + String remark = sut.parse(code); + String expectedRmk = Messages.getInstance() + .getString("Remark.Tornadic.Activity.Beginning", Messages.getInstance().getString("Remark.TORNADO"), "", "13", "6", Messages.getInstance().getString(CONVERTER_NE)); + assertThat(remark, containsString(expectedRmk)); + } + + @Test + public void testParseTornadicActivityWithTornadoAndHour() { + String code = "AO1 TORNADO B1513 6 NE"; + String remark = sut.parse(code); + String expectedRmk = Messages.getInstance() + .getString("Remark.Tornadic.Activity.Beginning", Messages.getInstance().getString("Remark.TORNADO"), "15", "13", "6", Messages.getInstance().getString(CONVERTER_NE)); + assertThat(remark, containsString(expectedRmk)); + } + + @Test + public void testParseTornadicActivityWithFunnelCloud() { + String code = "AO1 FUNNEL CLOUD B1513E1630 6 NE"; + String remark = sut.parse(code); + String expectedRmk = Messages.getInstance() + .getString("Remark.Tornadic.Activity.BegEnd", Messages.getInstance().getString("Remark.FUNNELCLOUD"), "15", "13", "16", "30", "6", Messages.getInstance().getString(CONVERTER_NE)); + assertThat(remark, containsString(expectedRmk)); + } + + @Test + public void testParseTornadicActivityWithFunnelCloudAndHourEnd() { + String code = "AO1 FUNNEL CLOUD B13E1630 6 NE"; + String remark = sut.parse(code); + String expectedRmk = Messages.getInstance() + .getString("Remark.Tornadic.Activity.BegEnd", Messages.getInstance().getString("Remark.FUNNELCLOUD"), "", "13", "16", "30", "6", Messages.getInstance().getString(CONVERTER_NE)); + assertThat(remark, containsString(expectedRmk)); + } + + @Test + public void testParseTornadicActivityWithWaterSproutAndEndingTimeOnlyMinutes() { + String code = "AO1 WATERSPOUT E16 12 NE"; + String remark = sut.parse(code); + String expectedRmk = Messages.getInstance() + .getString("Remark.Tornadic.Activity.Ending", Messages.getInstance().getString("Remark.WATERSPOUT"), "", "16", "12", Messages.getInstance().getString(CONVERTER_NE)); + assertThat(remark, containsString(expectedRmk)); + } + + @Test + public void testParseTornadicActivityWithWaterSproutAndEndingTime() { + String code = "AO1 WATERSPOUT E1516 12 NE"; + String remark = sut.parse(code); + String expectedRmk = Messages.getInstance() + .getString("Remark.Tornadic.Activity.Ending", Messages.getInstance().getString("Remark.WATERSPOUT"), "15", "16", "12", Messages.getInstance().getString(CONVERTER_NE)); + assertThat(remark, containsString(expectedRmk)); + } + + @Test + public void testParseBeginningEndPrecipitation() { + String code = "AO1 RAB05E30SNB1520E1655"; + String remark = sut.parse(code); + String expectedRmk1 = Messages.getInstance().getString(REMARK_PRECIPITATION_BEG_END, "", Messages.getInstance().getString("Phenomenon.RA"), "", "05", "", "30"); + String expectedRmk2 = Messages.getInstance().getString(REMARK_PRECIPITATION_BEG_END, "", Messages.getInstance().getString("Phenomenon.SN"), "15", "20", "16", "55"); + assertThat(remark, containsString(expectedRmk1)); + assertThat(remark, containsString(expectedRmk2)); + } + + @Test + public void testParseBeginningEndPrecipitationWithDescriptive() { + String code = "AO1 SHRAB05E30SHSNB20E55"; + String remark = sut.parse(code); + String expectedRmk1 = Messages.getInstance() + .getString(REMARK_PRECIPITATION_BEG_END, Messages.getInstance().getString("Descriptive.SH"), Messages.getInstance().getString("Phenomenon.RA"), "", "05", "", "30"); + String expectedRmk2 = Messages.getInstance() + .getString(REMARK_PRECIPITATION_BEG_END, Messages.getInstance().getString("Descriptive.SH"), Messages.getInstance().getString("Phenomenon.SN"), "", "20", "", "55"); + assertThat(remark, containsString(expectedRmk1)); + assertThat(remark, containsString(expectedRmk2)); + } + + @Test + public void testParseBeginningThunderstorm() { + String code = "AO1 TSB0159E30"; + String remark = sut.parse(code); + String expectedRmk1 = Messages.getInstance().getString(REMARK_PRECIPITATION_BEG_END, "", Messages.getInstance().getString("Phenomenon.TS"), "01", "59", "", "30"); + assertThat(remark, containsString(expectedRmk1)); + } + + @Test + public void testParseThunderStormLocation() { + String code = "AO1 TS SE"; + String remark = sut.parse(code); + String expected = Messages.getInstance().getString("Remark.Thunderstorm.Location", Messages.getInstance().getString("Converter.SE")); + assertThat(remark, containsString(expected)); + } + + @Test + public void testParseThunderStormLocationWithMoving() { + String code = "AO1 TS SE MOV NE"; + String remark = sut.parse(code); + String expected = Messages.getInstance().getString("Remark.Thunderstorm.Location.Moving", Messages.getInstance().getString("Converter.SE"), Messages.getInstance().getString(CONVERTER_NE)); + assertThat(remark, containsString(expected)); + } + + @Test + public void testParseHailSize() { + String code = "AO1 GR 1 3/4"; + String remark = sut.parse(code); + String expected = Messages.getInstance().getString("Remark.Hail", "1 3/4"); + assertThat(remark, containsString(expected)); + } + + @Test + public void testParseHailSizeWithLesserThan() { + String code = "AO1 GR LESS THAN 1/4"; + String remark = sut.parse(code); + String expected = Messages.getInstance().getString("Remark.Hail.LesserThan", "1/4"); + assertThat(remark, containsString(expected)); + } + + @Test + public void testParseSnowPellets() { + String code = "AO1 GS MOD"; + String remark = sut.parse(code); + String expected = Messages.getInstance().getString("Remark.Snow.Pellets", Messages.getInstance().getString("Remark.MOD")); + assertThat(remark, containsString(expected)); + } + + @Test + public void testParseVirgaWithDirection() { + String code = "AO1 VIRGA SW"; + String remark = sut.parse(code); + String expected = Messages.getInstance().getString("Remark.Virga.Direction", Messages.getInstance().getString("Converter.SW")); + assertThat(remark, containsString(expected)); + } + + @Test + public void testParseVirga() { + String code = "AO1 VIRGA"; + String remark = sut.parse(code); + assertThat(remark, containsString(Messages.getInstance().getString("Remark.VIRGA"))); + } + + @Test + public void testParseCeilingHeight() { + String code = "AO1 CIG 005V010"; + String remark = sut.parse(code); + String expected = Messages.getInstance().getString("Remark.Ceiling.Height", 500, 1000); + assertThat(remark, containsString(expected)); + } + + @Test + public void testParseObscurations() { + String code = "AO1 FU BKN020"; + String remark = sut.parse(code); + String expected = Messages.getInstance().getString("Remark.Obscuration", Messages.getInstance().getString(CLOUD_QUANTITY_BKN), 2000, Messages.getInstance().getString("Phenomenon.FU")); + assertThat(remark, containsString(expected)); + } + + @Test + public void testParseVariableSkyConditionWithoutLayer() { + String code = "BKN V OVC"; + String remark = sut.parse(code); + String expected = Messages.getInstance() + .getString("Remark.Variable.Sky.Condition", Messages.getInstance().getString(CLOUD_QUANTITY_BKN), Messages.getInstance().getString("CloudQuantity.OVC")); + assertThat(remark, containsString(expected)); + } + + @Test + public void testParseVariableSkyCondition() { + String code = "BKN014 V OVC"; + String remark = sut.parse(code); + String expected = Messages.getInstance() + .getString("Remark.Variable.Sky.Condition.Height", 1400, Messages.getInstance().getString(CLOUD_QUANTITY_BKN), Messages.getInstance().getString("CloudQuantity.OVC")); + assertThat(remark, containsString(expected)); + } + + @Test + public void testParseCeilingSecondLocation() { + String code = "CIG 002 RWY11"; + String remark = sut.parse(code); + String expected = Messages.getInstance().getString("Remark.Ceiling.Second.Location", 200, "RWY11"); + assertThat(remark, containsString(expected)); + } + + @Test + public void testParseSealLevelPressure() { + String code = "AO1 SLP134"; + String remark = sut.parse(code); + String expected = Messages.getInstance().getString(REMARK_SEA_LEVEL_PRESSURE, "1013.4"); + assertThat(remark, containsString(expected)); + } + + @Test + public void testParseSealLevelPressure2() { + String code = "AO1 SLP982"; + String remark = sut.parse(code); + String expected = Messages.getInstance().getString(REMARK_SEA_LEVEL_PRESSURE, "998.2"); + assertThat(remark, containsString(expected)); + } + + @Test + public void testParseSnowIncreasingRapidly() { + String code = "AO1 SNINCR 2/10"; + String remark = sut.parse(code); + String expected = Messages.getInstance().getString("Remark.Snow.Increasing.Rapidly", 2, 10); + assertThat(remark, containsString(expected)); + } + + @Test + public void testParseWithRmkSlp() { + String code = "CF1AC8 CF TR SLP091 DENSITY ALT 200FT"; + + String remark = sut.parse(code); + assertThat(remark, containsString("CF1AC8 CF TR")); + assertThat(remark, containsString(Messages.getInstance().getString(REMARK_SEA_LEVEL_PRESSURE, "1009.1"))); + } +} diff --git a/src/test/java/io/github/mivek/parser/TAFParserTest.java b/metarParser-parsers/src/test/java/io/github/mivek/parser/TAFParserTest.java similarity index 88% rename from src/test/java/io/github/mivek/parser/TAFParserTest.java rename to metarParser-parsers/src/test/java/io/github/mivek/parser/TAFParserTest.java index e0ebc9e4..196a1def 100644 --- a/src/test/java/io/github/mivek/parser/TAFParserTest.java +++ b/metarParser-parsers/src/test/java/io/github/mivek/parser/TAFParserTest.java @@ -1,720 +1,694 @@ -package io.github.mivek.parser; - -import io.github.mivek.enums.CloudQuantity; -import io.github.mivek.enums.CloudType; -import io.github.mivek.enums.Descriptive; -import io.github.mivek.enums.Intensity; -import io.github.mivek.enums.Phenomenon; -import io.github.mivek.exception.ErrorCodes; -import io.github.mivek.exception.ParseException; -import io.github.mivek.internationalization.Messages; -import io.github.mivek.model.TAF; -import io.github.mivek.model.TemperatureDated; -import io.github.mivek.model.trend.AbstractTafTrend; -import io.github.mivek.model.trend.BECMGTafTrend; -import io.github.mivek.model.trend.FMTafTrend; -import io.github.mivek.model.trend.PROBTafTrend; -import io.github.mivek.model.trend.TEMPOTafTrend; -import io.github.mivek.model.trend.validity.BeginningValidity; -import io.github.mivek.model.trend.validity.Validity; -import io.github.mivek.utils.Converter; -import org.junit.Before; -import org.junit.Test; - -import static org.hamcrest.Matchers.*; -import static org.junit.Assert.*; - -/** - * Test class for {@link TAFParser} - * @author mivek - * - */ -public class TAFParserTest extends AbstractParserTest { - - private TAFParser fSut; - - @Override - protected TAFParser getSut() { - return fSut; - } - - @Before - public void setUp() { - fSut = TAFParser.getInstance(); - } - - - @Test - public void testProcessGeneralChangesWithTX() { - AbstractTafTrend change = new BECMGTafTrend(); - String part = "TX15/0612Z"; - fSut.processGeneralChanges(change, part); - - assertThat(change.getClouds(), is(empty())); - assertThat(change.getWeatherConditions(), is(empty())); - } - - @Test - public void testProcessGeneralChangesWithTN() { - AbstractTafTrend change = new BECMGTafTrend(); - String part = "TN01/0612Z"; - fSut.processGeneralChanges(change, part); - - assertThat(change.getClouds(), is(empty())); - assertThat(change.getWeatherConditions(), is(empty())); - } - - @Test - public void testProcessGeneralChangesCloudValid() { - AbstractTafTrend change = new BECMGTafTrend(); - String part = "SCT012TCU"; - fSut.processGeneralChanges(change, part); - - assertThat(change.getClouds(), hasSize(1)); - assertThat(change.getClouds().get(0).getQuantity(), is(CloudQuantity.SCT)); - assertThat(change.getClouds().get(0).getAltitude(), is(12 * 30)); - assertThat(change.getClouds().get(0).getHeight(), is(1200)); - assertThat(change.getClouds().get(0).getType(), is(CloudType.TCU)); - } - - @Test - public void testProcessGeneralChangesCloudNull() { - AbstractTafTrend change = new BECMGTafTrend(); - String part = "NSW"; - fSut.processGeneralChanges(change, part); - - assertThat(change.getClouds(), is(empty())); - } - - - @Test - public void testParseValidity() { - String validityString = "3118/0124"; - - Validity res = fSut.parseValidity(validityString); - - assertThat(res, is(not(nullValue()))); - assertEquals(Integer.valueOf(31), res.getStartDay()); - assertEquals(Integer.valueOf(18), res.getStartHour()); - assertEquals(Integer.valueOf(1), res.getEndDay()); - assertEquals(Integer.valueOf(24), res.getEndHour()); - } - - @Test - public void testParseTemperatureMax() { - String tempString = "TX15/0612Z"; - TemperatureDated res = fSut.parseTemperature(tempString); - - assertThat(res.getTemperature(), is(15)); - assertThat(res.getDay(), is(6)); - assertThat(res.getHour(), is(12)); - } - - @Test - public void testParseTemperatureMinus() { - String tempString = "TNM02/0612Z"; - TemperatureDated res = fSut.parseTemperature(tempString); - - assertThat(res.getTemperature(), is(-2)); - assertThat(res.getDay(), is(6)); - assertThat(res.getHour(), is(12)); - } - - @Test - public void testParseBeginningValidity() { - String validity = "FM061300"; - BeginningValidity res = fSut.parseBasicValidity(validity); - assertThat(res.getStartDay(), is(6)); - assertThat(res.getStartHour(), is(13)); - assertThat(res.getStartMinutes(), is(0)); - } - - @Test - public void testParseValidWithInvalidLineBreaks() throws ParseException { - String taf = "TAF LFPG 150500Z 1506/1612 17005KT 6000 SCT012 \n" - + "TEMPO 1506/1509 3000 BR BKN006 PROB40 \n" - + "TEMPO 1506/1508 0400 BCFG BKN002 PROB40 \n" - + "TEMPO 1512/1516 4000 -SHRA FEW030TCU BKN040 \n" - + "BECMG 1520/1522 CAVOK \n" - + "TEMPO 1603/1608 3000 BR BKN006 PROB40 \n" - + "TEMPO 1604/1607 0400 BCFG BKN002 TX17/1512Z TN07/1605Z"; - - TAF res = fSut.parse(taf); - - assertThat(res, is(not(nullValue()))); - assertEquals(fSut.getAirportSupplier().get("LFPG"), res.getAirport()); - // Check on time delivery. - assertEquals(Integer.valueOf(15), res.getDay()); - assertEquals(5, res.getTime().getHour()); - assertEquals(0, res.getTime().getMinute()); - // Checks on validity. - assertEquals(Integer.valueOf(15), res.getValidity().getStartDay()); - assertEquals(Integer.valueOf(6), res.getValidity().getStartHour()); - assertEquals(Integer.valueOf(16), res.getValidity().getEndDay()); - assertEquals(Integer.valueOf(12), res.getValidity().getEndHour()); - // Checks on wind. - assertThat(res.getWind().getDirection(), is(Converter.degreesToDirection("170"))); - assertThat(res.getWind().getSpeed(), is(5)); - assertThat(res.getWind().getGust(), is(0)); - assertThat(res.getWind().getUnit(), is("KT")); - // Checks on visibility. - assertThat(res.getVisibility().getMainVisibility(), is("6000m")); - //Check on clouds. - assertThat(res.getClouds(), hasSize(1)); - assertThat(res.getClouds().get(0).getQuantity(), is(CloudQuantity.SCT)); - assertThat(res.getClouds().get(0).getAltitude(), is(30 * 12)); - assertThat(res.getClouds().get(0).getType(), nullValue()); - - assertThat(res.getMaxTemperature(), notNullValue()); - assertThat(res.getMinTemperature(), notNullValue()); - assertEquals(17, res.getMaxTemperature().getTemperature().intValue()); - assertEquals(15, res.getMaxTemperature().getDay().intValue()); - assertEquals(12, res.getMaxTemperature().getHour().intValue()); - assertEquals(7, res.getMinTemperature().getTemperature().intValue()); - assertEquals(16, res.getMinTemperature().getDay().intValue()); - assertEquals(5, res.getMinTemperature().getHour().intValue()); - - // Check that no weatherCondition - assertThat(res.getWeatherConditions(), empty()); - // Checks on tempos. - assertThat(res.getTempos(), hasSize(5)); - // First tempo - assertThat(res.getTempos().get(0).getValidity().getStartDay(), is(15)); - assertThat(res.getTempos().get(0).getValidity().getStartHour(), is(6)); - assertThat(res.getTempos().get(0).getValidity().getEndDay(), is(15)); - assertThat(res.getTempos().get(0).getValidity().getEndHour(), is(9)); - assertThat(res.getTempos().get(0).getVisibility().getMainVisibility(), is("3000m")); - assertThat(res.getTempos().get(0).getWeatherConditions(), hasSize(1)); - assertThat(res.getTempos().get(0).getWeatherConditions().get(0).getIntensity(), is(nullValue())); - assertThat(res.getTempos().get(0).getWeatherConditions().get(0).getDescriptive(), is(nullValue())); - assertThat(res.getTempos().get(0).getWeatherConditions().get(0).getPhenomenons(), hasSize(1)); - assertThat(res.getTempos().get(0).getWeatherConditions().get(0).getPhenomenons().get(0), is(Phenomenon.MIST)); - assertThat(res.getTempos().get(0).getClouds(), hasSize(1)); - assertThat(res.getTempos().get(0).getClouds().get(0).getQuantity(), is(CloudQuantity.BKN)); - assertThat(res.getTempos().get(0).getClouds().get(0).getAltitude(), is(6 * 30)); - assertThat(res.getTempos().get(0).getClouds().get(0).getType(), nullValue()); - assertThat(res.getTempos().get(0).getProbability(), nullValue()); - // Second tempo - assertThat(res.getTempos().get(1).getValidity().getStartDay(), is(15)); - assertThat(res.getTempos().get(1).getValidity().getStartHour(), is(6)); - assertThat(res.getTempos().get(1).getValidity().getEndDay(), is(15)); - assertThat(res.getTempos().get(1).getValidity().getEndHour(), is(8)); - assertThat(res.getTempos().get(1).getWind(), nullValue()); - assertThat(res.getTempos().get(1).getVisibility().getMainVisibility(), is("400m")); - assertThat(res.getTempos().get(1).getWeatherConditions(), hasSize(1)); - assertThat(res.getTempos().get(1).getWeatherConditions().get(0).getIntensity(), is(nullValue())); - assertThat(res.getTempos().get(1).getWeatherConditions().get(0).getDescriptive(), is(Descriptive.PATCHES)); - assertThat(res.getTempos().get(1).getWeatherConditions().get(0).getPhenomenons(), hasSize(1)); - assertThat(res.getTempos().get(1).getWeatherConditions().get(0).getPhenomenons().get(0), is(Phenomenon.FOG)); - assertThat(res.getTempos().get(1).getClouds(), hasSize(1)); - assertThat(res.getTempos().get(1).getClouds().get(0).getQuantity(), is(CloudQuantity.BKN)); - assertThat(res.getTempos().get(1).getClouds().get(0).getAltitude(), is(30 * 2)); - assertThat(res.getTempos().get(1).getClouds().get(0).getHeight(), is(200)); - assertThat(res.getTempos().get(1).getProbability(), is(40)); - // Third tempo - assertThat(res.getTempos().get(2).getValidity().getStartDay(), is(15)); - assertThat(res.getTempos().get(2).getValidity().getStartHour(), is(12)); - assertThat(res.getTempos().get(2).getValidity().getEndDay(), is(15)); - assertThat(res.getTempos().get(2).getValidity().getEndHour(), is(16)); - assertThat(res.getTempos().get(2).getVisibility().getMainVisibility(), is("4000m")); - assertThat(res.getTempos().get(2).getWeatherConditions(), not(empty())); - assertThat(res.getTempos().get(2).getWeatherConditions(), hasSize(1)); - assertThat(res.getTempos().get(2).getWeatherConditions().get(0).getIntensity(), is(Intensity.LIGHT)); - assertThat(res.getTempos().get(2).getWeatherConditions().get(0).getDescriptive(), is(Descriptive.SHOWERS)); - assertThat(res.getTempos().get(2).getWeatherConditions().get(0).getPhenomenons(), hasSize(1)); - assertThat(res.getTempos().get(2).getWeatherConditions().get(0).getPhenomenons().get(0), is(Phenomenon.RAIN)); - assertThat(res.getTempos().get(2).getClouds(), hasSize(2)); - assertThat(res.getTempos().get(2).getClouds().get(0).getQuantity(), is(CloudQuantity.FEW)); - assertThat(res.getTempos().get(2).getClouds().get(0).getAltitude(), is(30 * 30)); - assertThat(res.getTempos().get(2).getClouds().get(0).getType(), is(CloudType.TCU)); - assertThat(res.getTempos().get(2).getClouds().get(1).getQuantity(), is(CloudQuantity.BKN)); - assertThat(res.getTempos().get(2).getClouds().get(1).getAltitude(), is(30 * 40)); - assertThat(res.getTempos().get(2).getClouds().get(1).getType(), nullValue()); - assertThat(res.getTempos().get(2).getProbability(), is(40)); - - // First BECMG - assertThat(res.getBECMGs(), hasSize(1)); - BECMGTafTrend becmg = res.getBECMGs().get(0); - assertEquals(15, becmg.getValidity().getStartDay().intValue()); - assertEquals(20, becmg.getValidity().getStartHour().intValue()); - assertEquals(15, becmg.getValidity().getEndDay().intValue()); - assertEquals(22, becmg.getValidity().getEndHour().intValue()); - - // Fourth Tempo - TEMPOTafTrend tempo4 = res.getTempos().get(3); - assertEquals(16, tempo4.getValidity().getStartDay().intValue()); - assertEquals(3, tempo4.getValidity().getStartHour().intValue()); - assertEquals(16, tempo4.getValidity().getEndDay().intValue()); - assertEquals(8, tempo4.getValidity().getEndHour().intValue()); - assertEquals("3000m", tempo4.getVisibility().getMainVisibility()); - assertThat(tempo4.getWeatherConditions(), hasSize(1)); - assertNull(tempo4.getWeatherConditions().get(0).getIntensity()); - assertNull(tempo4.getWeatherConditions().get(0).getDescriptive()); - assertThat(tempo4.getWeatherConditions().get(0).getPhenomenons(), hasSize(1)); - assertEquals(Phenomenon.MIST, tempo4.getWeatherConditions().get(0).getPhenomenons().get(0)); - assertThat(tempo4.getClouds(), hasSize(1)); - assertEquals(CloudQuantity.BKN, tempo4.getClouds().get(0).getQuantity()); - assertNull(tempo4.getClouds().get(0).getType()); - assertEquals(6 * 30, tempo4.getClouds().get(0).getAltitude()); - assertNull(tempo4.getProbability()); - - // Fifth Tempo - TEMPOTafTrend tempo5 = res.getTempos().get(4); - assertEquals(16, tempo5.getValidity().getStartDay().intValue()); - assertEquals(4, tempo5.getValidity().getStartHour().intValue()); - assertEquals(16, tempo5.getValidity().getEndDay().intValue()); - assertEquals(7, tempo5.getValidity().getEndHour().intValue()); - assertEquals("400m", tempo5.getVisibility().getMainVisibility()); - assertThat(tempo5.getWeatherConditions(), hasSize(1)); - assertNull(tempo5.getWeatherConditions().get(0).getIntensity()); - assertEquals(Descriptive.PATCHES, tempo5.getWeatherConditions().get(0).getDescriptive()); - assertThat(tempo5.getWeatherConditions().get(0).getPhenomenons(), hasSize(1)); - assertEquals(Phenomenon.FOG, tempo5.getWeatherConditions().get(0).getPhenomenons().get(0)); - assertThat(tempo5.getClouds(), hasSize(1)); - assertEquals(CloudQuantity.BKN, tempo5.getClouds().get(0).getQuantity()); - assertEquals(2 * 30, tempo5.getClouds().get(0).getAltitude()); - assertNull(tempo5.getClouds().get(0).getType()); - assertThat(tempo5.getProbability(), is(40)); - } - - @Test - public void testParseValidWithoutLineBreaks() throws ParseException { - String taf = "TAF LSZH 292025Z 2921/3103 VRB03KT 9999 FEW020 BKN080 TX20/3014Z TN06/3003Z " + - "PROB30 TEMPO 2921/2923 SHRA " + - "BECMG 3001/3004 4000 MIFG NSC " + - "PROB40 3003/3007 1500 BCFG SCT004 " + - "PROB30 3004/3007 0800 FG VV003 " + - "BECMG 3006/3009 9999 FEW030 " + - "PROB40 TEMPO 3012/3017 30008KT"; - - TAF res = fSut.parse(taf); - - assertThat(res, is(not(nullValue()))); - assertEquals(fSut.getAirportSupplier().get("LSZH"), res.getAirport()); - // Check on time delivery. - assertEquals(29, res.getDay().intValue()); - assertEquals(20, res.getTime().getHour()); - assertEquals(25, res.getTime().getMinute()); - // Checks on validity. - assertEquals(29, res.getValidity().getStartDay().intValue()); - assertEquals(21, res.getValidity().getStartHour().intValue()); - assertEquals(31, res.getValidity().getEndDay().intValue()); - assertEquals(3, res.getValidity().getEndHour().intValue()); - // Checks on wind. - assertThat(res.getWind().getDirectionDegrees(), nullValue()); - assertThat(res.getWind().getDirection(), is(Converter.degreesToDirection("VRB"))); - assertThat(res.getWind().getSpeed(), is(3)); - assertThat(res.getWind().getGust(), is(0)); - assertThat(res.getWind().getUnit(), is("KT")); - // Checks on visibility. - assertThat(res.getVisibility().getMainVisibility(), is(">10km")); - //Check on clouds. - assertThat(res.getClouds(), hasSize(2)); - assertThat(res.getClouds().get(0).getQuantity(), is(CloudQuantity.FEW)); - assertThat(res.getClouds().get(0).getHeight(), is(2000)); - assertThat(res.getClouds().get(0).getType(), nullValue()); - - assertThat(res.getClouds().get(1).getQuantity(), is(CloudQuantity.BKN)); - assertThat(res.getClouds().get(1).getHeight(), is(8000)); - assertThat(res.getClouds().get(1).getType(), nullValue()); - // Check that no weatherCondition - assertThat(res.getWeatherConditions(), empty()); - // Check max temperature - assertThat(res.getMaxTemperature().getDay(), is(30)); - assertThat(res.getMaxTemperature().getHour(), is(14)); - assertThat(res.getMaxTemperature().getTemperature(), is(20)); - // Check min temperature - assertThat(res.getMinTemperature().getDay(), is(30)); - assertThat(res.getMinTemperature().getHour(), is(3)); - assertThat(res.getMinTemperature().getTemperature(), is(6)); - - // Checks on tempos. - assertThat(res.getTempos(), hasSize(2)); - // Checks on BECOMGs. - assertThat(res.getBECMGs(), hasSize(2)); - // Checks on probs. - assertThat(res.getProbs(), hasSize(2)); - - // First TEMPO - TEMPOTafTrend tempo0 = res.getTempos().get(0); - assertThat(tempo0.getValidity().getStartDay(), is(29)); - assertThat(tempo0.getValidity().getStartHour(), is(21)); - assertThat(tempo0.getValidity().getEndDay(), is(29)); - assertThat(tempo0.getValidity().getEndHour(), is(23)); - assertThat(tempo0.getWeatherConditions(), hasSize(1)); - assertThat(tempo0.getWeatherConditions().get(0).getIntensity(), is(nullValue())); - assertThat(tempo0.getWeatherConditions().get(0).getDescriptive(), is(Descriptive.SHOWERS)); - assertThat(tempo0.getWeatherConditions().get(0).getPhenomenons(), hasSize(1)); - assertThat(tempo0.getWeatherConditions().get(0).getPhenomenons().get(0), is(Phenomenon.RAIN)); - assertThat(tempo0.getProbability(), is(30)); - - // First BECOMG - BECMGTafTrend becmg0 = res.getBECMGs().get(0); - assertThat(becmg0.getValidity().getStartDay(), is(30)); - assertThat(becmg0.getValidity().getStartHour(), is(1)); - assertThat(becmg0.getValidity().getEndDay(), is(30)); - assertThat(becmg0.getValidity().getEndHour(), is(4)); - assertThat(becmg0.getVisibility().getMainVisibility(), is("4000m")); - assertThat(becmg0.getWeatherConditions().get(0).getIntensity(), is(nullValue())); - assertThat(becmg0.getWeatherConditions().get(0).getDescriptive(), is(Descriptive.SHALLOW)); - assertThat(becmg0.getWeatherConditions().get(0).getPhenomenons(), hasSize(1)); - assertThat(becmg0.getWeatherConditions().get(0).getPhenomenons().get(0), is(Phenomenon.FOG)); - assertThat(becmg0.getClouds().get(0).getQuantity(), is(CloudQuantity.NSC)); - - // First PROB - PROBTafTrend prob0 = res.getProbs().get(0); - assertThat(prob0.getValidity().getStartDay(), is(30)); - assertThat(prob0.getValidity().getStartHour(), is(3)); - assertThat(prob0.getValidity().getEndDay(), is(30)); - assertThat(prob0.getValidity().getEndHour(), is(7)); - assertThat(prob0.getVisibility().getMainVisibility(), is("1500m")); - assertThat(prob0.getWeatherConditions().get(0).getIntensity(), is(nullValue())); - assertThat(prob0.getWeatherConditions().get(0).getDescriptive(), is(Descriptive.PATCHES)); - assertThat(prob0.getWeatherConditions().get(0).getPhenomenons(), hasSize(1)); - assertThat(prob0.getWeatherConditions().get(0).getPhenomenons().get(0), is(Phenomenon.FOG)); - assertThat(prob0.getClouds(), hasSize(1)); - assertThat(prob0.getClouds().get(0).getQuantity(), is(CloudQuantity.SCT)); - assertThat(prob0.getClouds().get(0).getHeight(), is(400)); - assertThat(prob0.getClouds().get(0).getType(), nullValue()); - assertThat(prob0.getProbability(), is(40)); - - // Second PROB - PROBTafTrend prob1 = res.getProbs().get(1); - assertThat(prob1.getValidity().getStartDay(), is(30)); - assertThat(prob1.getValidity().getStartHour(), is(4)); - assertThat(prob1.getValidity().getEndDay(), is(30)); - assertThat(prob1.getValidity().getEndHour(), is(7)); - assertThat(prob1.getVisibility().getMainVisibility(), is("800m")); - assertThat(prob1.getWeatherConditions().get(0).getIntensity(), is(nullValue())); - assertThat(prob1.getWeatherConditions().get(0).getDescriptive(), is(nullValue())); - assertThat(prob1.getWeatherConditions().get(0).getPhenomenons(), hasSize(1)); - assertThat(prob1.getWeatherConditions().get(0).getPhenomenons().get(0), is(Phenomenon.FOG)); - assertThat(prob1.getVerticalVisibility(), is(300)); - assertThat(prob1.getClouds(), hasSize(0)); - assertThat(prob1.getProbability(), is(30)); - - // Second BECOMG - BECMGTafTrend becmg1 = res.getBECMGs().get(1); - assertThat(becmg1.getValidity().getStartDay(), is(30)); - assertThat(becmg1.getValidity().getStartHour(), is(6)); - assertThat(becmg1.getValidity().getEndDay(), is(30)); - assertThat(becmg1.getValidity().getEndHour(), is(9)); - assertThat(becmg1.getVisibility().getMainVisibility(), is(">10km")); - assertThat(becmg1.getWeatherConditions(), hasSize(0)); - assertThat(becmg1.getClouds(), hasSize(1)); - assertThat(becmg1.getClouds().get(0).getQuantity(), is(CloudQuantity.FEW)); - assertThat(becmg1.getClouds().get(0).getHeight(), is(3000)); - assertThat(becmg1.getClouds().get(0).getType(), nullValue()); - - // Second TEMPO - TEMPOTafTrend tempo1 = res.getTempos().get(1); - assertThat(tempo1.getValidity().getStartDay(), is(30)); - assertThat(tempo1.getValidity().getStartHour(), is(12)); - assertThat(tempo1.getValidity().getEndDay(), is(30)); - assertThat(tempo1.getValidity().getEndHour(), is(17)); - assertThat(tempo1.getWeatherConditions(), hasSize(0)); - assertThat(tempo1.getWind().getDirectionDegrees(), is(300)); - assertThat(tempo1.getWind().getDirection(), is(Converter.degreesToDirection("300.0"))); - assertThat(tempo1.getWind().getSpeed(), is(8)); - assertThat(tempo1.getWind().getGust(), is(0)); - assertThat(tempo1.getWind().getUnit(), is("KT")); - assertThat(tempo1.getProbability(), is(40)); - } - - @Test - public void testParseValidWithoutLineBreaksAndEndingTemperature() throws ParseException { - String taf = "TAF KLSV 120700Z 1207/1313 VRB06KT 9999 SCT250 QNH2992INS BECMG 1217/1218 10010G15KT 9999 SCT250 QNH2980INS BECMG 1303/1304 VRB06KT 9999 FEW250 QNH2979INS TX42/1223Z TN24/1213Z"; - - TAF res = fSut.parse(taf); - - assertThat(res, is(not(nullValue()))); - assertEquals(fSut.getAirportSupplier().get("KLSV"), res.getAirport()); - // Check on time delivery. - assertEquals(12, res.getDay().intValue()); - assertEquals(7, res.getTime().getHour()); - assertEquals(0, res.getTime().getMinute()); - // Checks on validity. - assertEquals(12, res.getValidity().getStartDay().intValue()); - assertEquals(7, res.getValidity().getStartHour().intValue()); - assertEquals(13, res.getValidity().getEndDay().intValue()); - assertEquals(13, res.getValidity().getEndHour().intValue()); - // Checks on wind. - assertThat(res.getWind().getDirectionDegrees(), nullValue()); - assertThat(res.getWind().getDirection(), is(Converter.degreesToDirection("VRB"))); - assertThat(res.getWind().getSpeed(), is(6)); - assertThat(res.getWind().getGust(), is(0)); - assertThat(res.getWind().getUnit(), is("KT")); - // Checks on visibility. - assertThat(res.getVisibility().getMainVisibility(), is(">10km")); - //Check on clouds. - assertThat(res.getClouds(), hasSize(1)); - assertThat(res.getClouds().get(0).getQuantity(), is(CloudQuantity.SCT)); - assertThat(res.getClouds().get(0).getHeight(), is(25000)); - assertThat(res.getClouds().get(0).getType(), nullValue()); - - // Check that no weatherCondition - assertThat(res.getWeatherConditions(), empty()); - // Check max temperature - assertThat(res.getMaxTemperature().getDay(), is(12)); - assertThat(res.getMaxTemperature().getHour(), is(23)); - assertThat(res.getMaxTemperature().getTemperature(), is(42)); - // Check min temperature - assertThat(res.getMinTemperature().getDay(), is(12)); - assertThat(res.getMinTemperature().getHour(), is(13)); - assertThat(res.getMinTemperature().getTemperature(), is(24)); - - // Checks on BECOMGs. - assertThat(res.getBECMGs(), hasSize(2)); - - // First BECOMG - BECMGTafTrend becmg0 = res.getBECMGs().get(0); - assertThat(becmg0.getValidity().getStartDay(), is(12)); - assertThat(becmg0.getValidity().getStartHour(), is(17)); - assertThat(becmg0.getValidity().getEndDay(), is(12)); - assertThat(becmg0.getValidity().getEndHour(), is(18)); - assertThat(becmg0.getVisibility().getMainVisibility(), is(">10km")); - assertThat(becmg0.getWeatherConditions(), hasSize(0)); - assertThat(becmg0.getClouds().get(0).getQuantity(), is(CloudQuantity.SCT)); - assertThat(becmg0.getClouds().get(0).getHeight(), is(25000)); - assertThat(becmg0.getWind().getDirectionDegrees(), is(100)); - assertThat(becmg0.getWind().getDirection(), is(Converter.degreesToDirection("100.0"))); - assertThat(becmg0.getWind().getSpeed(), is(10)); - assertThat(becmg0.getWind().getGust(), is(15)); - assertThat(becmg0.getWind().getUnit(), is("KT")); - - // Second BECOMG - BECMGTafTrend becmg1 = res.getBECMGs().get(1); - assertThat(becmg1.getValidity().getStartDay(), is(13)); - assertThat(becmg1.getValidity().getStartHour(), is(3)); - assertThat(becmg1.getValidity().getEndDay(), is(13)); - assertThat(becmg1.getValidity().getEndHour(), is(4)); - assertThat(becmg1.getVisibility().getMainVisibility(), is(">10km")); - assertThat(becmg1.getWind().getDirectionDegrees(), nullValue()); - assertThat(becmg1.getWind().getDirection(), is(Converter.degreesToDirection("VRB"))); - assertThat(becmg1.getWind().getSpeed(), is(6)); - assertThat(becmg1.getWind().getGust(), is(0)); - assertThat(becmg1.getWind().getUnit(), is("KT")); - assertThat(becmg1.getWeatherConditions(), hasSize(0)); - assertThat(becmg1.getClouds(), hasSize(1)); - assertThat(becmg1.getClouds().get(0).getQuantity(), is(CloudQuantity.FEW)); - assertThat(becmg1.getClouds().get(0).getHeight(), is(25000)); - assertThat(becmg1.getClouds().get(0).getType(), nullValue()); - } - - @Test - public void testParseWithFM() throws ParseException { - String message = "TAF KLWT 211120Z 2112/2212 20008KT 9999 SKC \n" + "TEMPO 2112/2116 VRB06KT \n" - + "FM212300 30012G22KT 9999 FEW050 SCT250 \n" + "FM220700 27008KT 9999 FEW030 FEW250"; - - TAF res = fSut.parse(message); - assertNotNull(res); - - assertThat(res, is(not(nullValue()))); - assertThat(res.getAirport(), is(fSut.getAirportSupplier().get("KLWT"))); - assertThat(res.getDay(), is(21)); - assertThat(res.getTime().getHour(), is(11)); - assertThat(res.getTime().getMinute(), is(20)); - assertThat(res.getValidity().getStartDay(), is(21)); - assertThat(res.getValidity().getStartHour(), is(12)); - assertThat(res.getValidity().getEndDay(), is(22)); - assertThat(res.getValidity().getEndHour(), is(12)); - - // Wind - assertThat(res.getWind(), is(not(nullValue()))); - assertThat(res.getWind().getDirection(), is(Converter.degreesToDirection("200"))); - assertThat(res.getWind().getSpeed(), is(8)); - assertThat(res.getWind().getGust(), is(0)); - assertThat(res.getWind().getUnit(), is("KT")); - - // Visibility - assertThat(res.getVisibility(), is(not(nullValue()))); - assertThat(res.getVisibility().getMainVisibility(), is(">10km")); - assertThat(res.getVisibility().getMinDirection(), is(nullValue())); - //Clouds - assertThat(res.getClouds(), hasSize(1)); - assertThat(res.getClouds().get(0).getQuantity(), is(CloudQuantity.SKC)); - - assertThat(res.getFMs(), hasSize(2)); - FMTafTrend fm1 = res.getFMs().get(0); - assertEquals(21, fm1.getValidity().getStartDay().intValue()); - assertEquals(23, fm1.getValidity().getStartHour().intValue()); - assertEquals(0, fm1.getValidity().getStartMinutes().intValue()); - assertEquals(300, fm1.getWind().getDirectionDegrees().intValue()); - assertEquals(12, fm1.getWind().getSpeed()); - assertEquals(22, fm1.getWind().getGust()); - assertThat(fm1.getClouds(), hasSize(2)); - assertEquals(CloudQuantity.FEW, fm1.getClouds().get(0).getQuantity()); - assertEquals(50 * 30, fm1.getClouds().get(0).getAltitude()); - assertNull(fm1.getClouds().get(0).getType()); - assertEquals(CloudQuantity.SCT, fm1.getClouds().get(1).getQuantity()); - assertEquals(250 * 30, fm1.getClouds().get(1).getAltitude()); - assertNull(fm1.getClouds().get(1).getType()); - // Tempos - assertThat(res.getTempos(), hasSize(1)); - assertThat(res.getTempos().get(0).getValidity().getStartDay(), is(21)); - assertThat(res.getTempos().get(0).getValidity().getStartHour(), is(12)); - assertThat(res.getTempos().get(0).getValidity().getEndDay(), is(21)); - assertThat(res.getTempos().get(0).getValidity().getEndHour(), is(16)); - assertEquals(Messages.getInstance().getString("Converter.VRB"), res.getTempos().get(0).getWind().getDirection()); - assertThat(res.getTempos().get(0).getWind().getSpeed(), is(6)); - - FMTafTrend fm2 = res.getFMs().get(1); - assertEquals(22, fm2.getValidity().getStartDay().intValue()); - assertEquals(7, fm2.getValidity().getStartHour().intValue()); - assertEquals(0, fm2.getValidity().getStartMinutes().intValue()); - assertThat(fm2.getClouds(), hasSize(2)); - - } - - @Test - public void testParseWith2Taf() throws ParseException { - String message = "TAF TAF LFPG 191100Z 1912/2018 02010KT 9999 FEW040 PROB30 "; - - TAF result = fSut.parse(message); - - assertNotNull(result); - assertThat(result.getProbs(), hasSize(1)); - assertThat(result.getProbs().get(0).getProbability(), is(30)); - } - - @Test - public void testParseInvalidMessage() throws ParseException { - String message = "LFPG 191100Z 1912/2018 02010KT 9999 FEW040 PROB30 "; - thrown.expect(ParseException.class); - thrown.expect(hasProperty("errorCode", is(ErrorCodes.ERROR_CODE_INVALID_MESSAGE))); - fSut.parse(message); - } - - @Test - public void testParseWithWindShear() throws ParseException { - // GIVEN a TAF message with windshear in principal part and from part. - String message = "TAF KMKE 011530 0116/0218 WS020/24045KT\n" + "FM010200 17005KT P6SM SKC WS020/23055KT "; - // WHEN parsing the message. - TAF result = fSut.parse(message); - - assertEquals(message, result.getMessage()); - // THEN the windshear of the principle part is decoded - assertNotNull(result); - assertNotNull(result.getWindShear()); - assertEquals(2000, result.getWindShear().getHeight()); - assertEquals(240, result.getWindShear().getDirectionDegrees().intValue()); - assertEquals(45, result.getWindShear().getSpeed()); - - // Checks on the from part. - FMTafTrend fm = result.getFMs().get(0); - assertNotNull(fm); - // Checks on the wind of the FM - assertNotNull(fm.getWind()); - assertEquals(170, fm.getWind().getDirectionDegrees().intValue()); - assertEquals(5, fm.getWind().getSpeed()); - // Checks on the wind shear of the fm - assertNotNull(fm.getWindShear()); - assertEquals(2000, fm.getWindShear().getHeight()); - assertEquals(230, fm.getWindShear().getDirectionDegrees().intValue()); - assertEquals(55, fm.getWindShear().getSpeed()); - } - - @Test - public void testParseInvalidAirport() throws ParseException { - String message = "TAF AAAA 191100Z 1912/2018 02010KT 9999 FEW040 PROB30"; - TAF res = fSut.parse(message); - assertNull(res.getAirport()); - assertEquals("AAAA", res.getStation()); - } - - @Test - public void testParseWithNauticalMilesVisibility() throws ParseException { - //GIVEN a TAF message with nautical miles visibility; - String message = "TAF CZBF 300939Z 3010/3022 VRB03KT 6SM -SN OVC015 \r\n" + - "TEMPO 3010/3012 11/2SM -SN OVC009 \nFM301200 10008KT 2SM -SN OVC010 \r\n" + - "TEMPO 3012/3022 3/4SM -SN VV007 RMK FCST BASED ON AUTO OBS. NXT FCST BY 301400Z"; - - //WHEN parsing the message. - TAF result = fSut.parse(message); - //THEN the visibility of the main event is 6 SM - assertNotNull(result); - assertNotNull(result.getVisibility()); - assertEquals("6SM", result.getVisibility().getMainVisibility()); - //THEN the visibility of the first tempo is 11/2 SM - assertNotNull(result.getTempos().get(0).getVisibility()); - assertEquals("11/2SM", result.getTempos().get(0).getVisibility().getMainVisibility()); - //THEN the visibility of the second tempo is 3/4 SM - assertNotNull(result.getTempos().get(1).getVisibility()); - assertEquals("3/4SM", result.getTempos().get(1).getVisibility().getMainVisibility()); - // Then the visibility of the FROM part is 2SN - assertNotNull(result.getFMs().get(0).getVisibility()); - assertEquals("2SM", result.getFMs().get(0).getVisibility().getMainVisibility()); - assertFalse(result.isAmendment()); - } - - @Test - public void testParseWithAMDTAF() throws ParseException { - //GIVEN an amended TAF - String message = "TAF AMD LFPO 100742Z 1007/1112 21018G35KT 9999 BKN025 \r\n" + - " TEMPO 1007/1009 4000 RA BKN014 SCT020CB PROB40 \r\n" + - " TEMPO 1007/1009 22020G45KT \r\n" + - " TEMPO 1010/1017 24022G45KT SHRA SCT030CB PROB30 \r\n" + - " TEMPO 1012/1016 -TSRA \r\n" + - " BECMG 1020/1023 24013KT SCT023 \r\n" + - " TEMPO 1104/1112 4000 -SHRA BKN012 BKN020TCU"; - //WHEN parsing the message - TAF result = fSut.parse(message); - //Then the taf is correctly parsed and the amendment attribute is true. - assertTrue(result.isAmendment()); - } - - @Test - public void testParseWithCavok() throws ParseException { - // GIVEN a TAF with CAVOK in the main part and in a BECMG part. - String message = "TAF LFPG 211700Z 2118/2224 VRB03KT CAVOK TX15/2215Z TN02/2205Z \n" + - "BECMG 2122/2124 3000 BR \n" + - "TEMPO 2202/2209 0800 BCFG PROB30 \n" + - "TEMPO 2203/2209 0500 FG \n" + - "BECMG 2211/2213 09006KT CAVOK"; - - // WHEN parsing the event. - TAF result = fSut.parse(message); - // THEN the result is CAVOK and the second BECMG is also cavok. - assertNotNull(result); - assertTrue(result.isCavok()); - assertEquals(">10km", result.getVisibility().getMainVisibility()); - assertTrue(result.getBECMGs().get(1).isCavok()); - assertEquals(">10km", result.getBECMGs().get(1).getVisibility().getMainVisibility()); - } - - @Test - public void testParseWithRMKInTempo() throws ParseException { - // GIVEN a TAF with remark in second tempo. - String message = "TAF CZBF 300939Z 3010/3022 VRB03KT 6SM -SN OVC015\n" + "TEMPO 3010/3012 11/2SM -SN OVC009 FM301200 10008KT 2SM -SN OVC010 \n" - + "TEMPO 3012/3022 3/4SM -SN VV007 RMK FCST BASED ON AUTO OBS. NXT FCST BY 301400Z"; - // WHEN parsing the event. - TAF result = fSut.parse(message); - // THEN the second tempo contains the remark. - assertNotNull(result); - assertNotNull(result.getTempos().get(1)); - assertNotNull(result.getTempos().get(1).getRemark()); - String rmk = Messages.getInstance().getString("Remark.FCST") + " " + Messages.getInstance().getString("Remark.BASED") + " " + Messages.getInstance().getString("Remark.ON") + " AUTO OBS. " - + Messages.getInstance().getString("Remark.NXT") + " " + Messages.getInstance().getString("Remark.FCST") + " BY 301400Z"; - assertThat(result.getTempos().get(1).getRemark(), containsString(rmk)); - } - - @Test - public void testParseWithRMK() throws ParseException { - // GIVEN a TAF with remark. - String message = "TAF CZBF 300939Z 3010/3022 VRB03KT 6SM -SN OVC015 RMK FCST BASED ON AUTO OBS. NXT FCST BY 301400Z\n" + "TEMPO 3010/3012 11/2SM -SN OVC009 FM301200 10008KT 2SM -SN OVC010 \n" - + "TEMPO 3012/3022 3/4SM -SN VV007"; - // WHEN parsing the event. - TAF result = fSut.parse(message); - // THEN the second tempo contains the remark. - assertNotNull(result); - String rmk = Messages.getInstance().getString("Remark.FCST") + " " + Messages.getInstance().getString("Remark.BASED") + " " + Messages.getInstance().getString("Remark.ON") + " AUTO OBS. " - + Messages.getInstance().getString("Remark.NXT") + " " + Messages.getInstance().getString("Remark.FCST") + " BY 301400Z"; - assertThat(result.getRemark(), containsString(rmk)); - String description = result.toString(); - assertThat(description, containsString(Messages.getInstance().getString("ToString.start.day.month") + "=30")); - assertThat(description, containsString(Messages.getInstance().getString("ToString.start.hour.day") + "=10")); - assertThat(description, containsString(Messages.getInstance().getString("ToString.end.day.month") + "=30")); - assertThat(description, containsString(Messages.getInstance().getString("ToString.end.hour.day") + "=12")); - } - -} +package io.github.mivek.parser; + +import io.github.mivek.enums.CloudQuantity; +import io.github.mivek.enums.CloudType; +import io.github.mivek.enums.Descriptive; +import io.github.mivek.enums.Intensity; +import io.github.mivek.enums.Phenomenon; +import io.github.mivek.exception.ErrorCodes; +import io.github.mivek.exception.ParseException; +import io.github.mivek.internationalization.Messages; +import io.github.mivek.model.TAF; +import io.github.mivek.model.TemperatureDated; +import io.github.mivek.model.trend.AbstractTafTrend; +import io.github.mivek.model.trend.BECMGTafTrend; +import io.github.mivek.model.trend.FMTafTrend; +import io.github.mivek.model.trend.PROBTafTrend; +import io.github.mivek.model.trend.TEMPOTafTrend; +import io.github.mivek.model.trend.validity.BeginningValidity; +import io.github.mivek.model.trend.validity.Validity; +import io.github.mivek.utils.Converter; +import org.junit.Before; +import org.junit.Test; + +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.*; +import static org.junit.Assert.*; + +/** + * Test class for {@link TAFParser} + * + * @author mivek + */ +public class TAFParserTest extends AbstractParserTest { + + public static final String TEN_KM = ">10km"; + public static final String REMARK_FCST = "Remark.FCST"; + public static final String REMARK_NXT = "Remark.NXT"; + private TAFParser fSut; + + @Override + protected TAFParser getSut() { + return fSut; + } + + @Before + public void setUp() { + fSut = TAFParser.getInstance(); + } + + @Test + public void testProcessGeneralChangesWithTX() { + AbstractTafTrend change = new BECMGTafTrend(); + String part = "TX15/0612Z"; + fSut.processGeneralChanges(change, part); + + assertThat(change.getClouds(), is(empty())); + assertThat(change.getWeatherConditions(), is(empty())); + } + + @Test + public void testProcessGeneralChangesWithTN() { + AbstractTafTrend change = new BECMGTafTrend(); + String part = "TN01/0612Z"; + fSut.processGeneralChanges(change, part); + + assertThat(change.getClouds(), is(empty())); + assertThat(change.getWeatherConditions(), is(empty())); + } + + @Test + public void testProcessGeneralChangesCloudValid() { + AbstractTafTrend change = new BECMGTafTrend(); + String part = "SCT012TCU"; + fSut.processGeneralChanges(change, part); + + assertThat(change.getClouds(), hasSize(1)); + assertThat(change.getClouds().get(0).getQuantity(), is(CloudQuantity.SCT)); + assertThat(change.getClouds().get(0).getHeight(), is(1200)); + assertThat(change.getClouds().get(0).getType(), is(CloudType.TCU)); + } + + @Test + public void testProcessGeneralChangesCloudNull() { + AbstractTafTrend change = new BECMGTafTrend(); + String part = "NSW"; + fSut.processGeneralChanges(change, part); + + assertThat(change.getClouds(), is(empty())); + } + + @Test + public void testParseValidity() { + String validityString = "3118/0124"; + + Validity res = fSut.parseValidity(validityString); + + assertThat(res, is(not(nullValue()))); + assertEquals(Integer.valueOf(31), res.getStartDay()); + assertEquals(Integer.valueOf(18), res.getStartHour()); + assertEquals(Integer.valueOf(1), res.getEndDay()); + assertEquals(Integer.valueOf(24), res.getEndHour()); + } + + @Test + public void testParseTemperatureMax() { + String tempString = "TX15/0612Z"; + TemperatureDated res = fSut.parseTemperature(tempString); + + assertThat(res.getTemperature(), is(15)); + assertThat(res.getDay(), is(6)); + assertThat(res.getHour(), is(12)); + } + + @Test + public void testParseTemperatureMinus() { + String tempString = "TNM02/0612Z"; + TemperatureDated res = fSut.parseTemperature(tempString); + + assertThat(res.getTemperature(), is(-2)); + assertThat(res.getDay(), is(6)); + assertThat(res.getHour(), is(12)); + } + + @Test + public void testParseBeginningValidity() { + String validity = "FM061300"; + BeginningValidity res = fSut.parseBasicValidity(validity); + assertThat(res.getStartDay(), is(6)); + assertThat(res.getStartHour(), is(13)); + assertThat(res.getStartMinutes(), is(0)); + } + + @Test + public void testParseValidWithInvalidLineBreaks() throws ParseException { + String taf = "TAF LFPG 150500Z 1506/1612 17005KT 6000 SCT012 \n" + "TEMPO 1506/1509 3000 BR BKN006 PROB40 \n" + "TEMPO 1506/1508 0400 BCFG BKN002 PROB40 \n" + + "TEMPO 1512/1516 4000 -SHRA FEW030TCU BKN040 \n" + "BECMG 1520/1522 CAVOK \n" + "TEMPO 1603/1608 3000 BR BKN006 PROB40 \n" + "TEMPO 1604/1607 0400 BCFG BKN002 TX17/1512Z TN07/1605Z"; + + TAF res = fSut.parse(taf); + + assertThat(res, is(not(nullValue()))); + assertEquals(fSut.getAirportSupplier().get("LFPG"), res.getAirport()); + // Check on time delivery. + assertEquals(Integer.valueOf(15), res.getDay()); + assertEquals(5, res.getTime().getHour()); + assertEquals(0, res.getTime().getMinute()); + // Checks on validity. + assertEquals(Integer.valueOf(15), res.getValidity().getStartDay()); + assertEquals(Integer.valueOf(6), res.getValidity().getStartHour()); + assertEquals(Integer.valueOf(16), res.getValidity().getEndDay()); + assertEquals(Integer.valueOf(12), res.getValidity().getEndHour()); + // Checks on wind. + assertThat(res.getWind().getDirection(), is(Converter.degreesToDirection("170"))); + assertThat(res.getWind().getSpeed(), is(5)); + assertThat(res.getWind().getGust(), is(0)); + assertThat(res.getWind().getUnit(), is("KT")); + // Checks on visibility. + assertThat(res.getVisibility().getMainVisibility(), is("6000m")); + //Check on clouds. + assertThat(res.getClouds(), hasSize(1)); + assertThat(res.getClouds().get(0).getQuantity(), is(CloudQuantity.SCT)); + assertThat(res.getClouds().get(0).getType(), nullValue()); + + assertThat(res.getMaxTemperature(), notNullValue()); + assertThat(res.getMinTemperature(), notNullValue()); + assertEquals(17, res.getMaxTemperature().getTemperature().intValue()); + assertEquals(15, res.getMaxTemperature().getDay().intValue()); + assertEquals(12, res.getMaxTemperature().getHour().intValue()); + assertEquals(7, res.getMinTemperature().getTemperature().intValue()); + assertEquals(16, res.getMinTemperature().getDay().intValue()); + assertEquals(5, res.getMinTemperature().getHour().intValue()); + + // Check that no weatherCondition + assertThat(res.getWeatherConditions(), empty()); + // Checks on tempos. + assertThat(res.getTempos(), hasSize(5)); + // First tempo + assertThat(res.getTempos().get(0).getValidity().getStartDay(), is(15)); + assertThat(res.getTempos().get(0).getValidity().getStartHour(), is(6)); + assertThat(res.getTempos().get(0).getValidity().getEndDay(), is(15)); + assertThat(res.getTempos().get(0).getValidity().getEndHour(), is(9)); + assertThat(res.getTempos().get(0).getVisibility().getMainVisibility(), is("3000m")); + assertThat(res.getTempos().get(0).getWeatherConditions(), hasSize(1)); + assertThat(res.getTempos().get(0).getWeatherConditions().get(0).getIntensity(), is(nullValue())); + assertThat(res.getTempos().get(0).getWeatherConditions().get(0).getDescriptive(), is(nullValue())); + assertThat(res.getTempos().get(0).getWeatherConditions().get(0).getPhenomenons(), hasSize(1)); + assertThat(res.getTempos().get(0).getWeatherConditions().get(0).getPhenomenons().get(0), is(Phenomenon.MIST)); + assertThat(res.getTempos().get(0).getClouds(), hasSize(1)); + assertThat(res.getTempos().get(0).getClouds().get(0).getQuantity(), is(CloudQuantity.BKN)); + assertThat(res.getTempos().get(0).getClouds().get(0).getType(), nullValue()); + assertThat(res.getTempos().get(0).getProbability(), nullValue()); + // Second tempo + assertThat(res.getTempos().get(1).getValidity().getStartDay(), is(15)); + assertThat(res.getTempos().get(1).getValidity().getStartHour(), is(6)); + assertThat(res.getTempos().get(1).getValidity().getEndDay(), is(15)); + assertThat(res.getTempos().get(1).getValidity().getEndHour(), is(8)); + assertThat(res.getTempos().get(1).getWind(), nullValue()); + assertThat(res.getTempos().get(1).getVisibility().getMainVisibility(), is("400m")); + assertThat(res.getTempos().get(1).getWeatherConditions(), hasSize(1)); + assertThat(res.getTempos().get(1).getWeatherConditions().get(0).getIntensity(), is(nullValue())); + assertThat(res.getTempos().get(1).getWeatherConditions().get(0).getDescriptive(), is(Descriptive.PATCHES)); + assertThat(res.getTempos().get(1).getWeatherConditions().get(0).getPhenomenons(), hasSize(1)); + assertThat(res.getTempos().get(1).getWeatherConditions().get(0).getPhenomenons().get(0), is(Phenomenon.FOG)); + assertThat(res.getTempos().get(1).getClouds(), hasSize(1)); + assertThat(res.getTempos().get(1).getClouds().get(0).getQuantity(), is(CloudQuantity.BKN)); + assertThat(res.getTempos().get(1).getClouds().get(0).getHeight(), is(200)); + assertThat(res.getTempos().get(1).getProbability(), is(40)); + // Third tempo + assertThat(res.getTempos().get(2).getValidity().getStartDay(), is(15)); + assertThat(res.getTempos().get(2).getValidity().getStartHour(), is(12)); + assertThat(res.getTempos().get(2).getValidity().getEndDay(), is(15)); + assertThat(res.getTempos().get(2).getValidity().getEndHour(), is(16)); + assertThat(res.getTempos().get(2).getVisibility().getMainVisibility(), is("4000m")); + assertThat(res.getTempos().get(2).getWeatherConditions(), not(empty())); + assertThat(res.getTempos().get(2).getWeatherConditions(), hasSize(1)); + assertThat(res.getTempos().get(2).getWeatherConditions().get(0).getIntensity(), is(Intensity.LIGHT)); + assertThat(res.getTempos().get(2).getWeatherConditions().get(0).getDescriptive(), is(Descriptive.SHOWERS)); + assertThat(res.getTempos().get(2).getWeatherConditions().get(0).getPhenomenons(), hasSize(1)); + assertThat(res.getTempos().get(2).getWeatherConditions().get(0).getPhenomenons().get(0), is(Phenomenon.RAIN)); + assertThat(res.getTempos().get(2).getClouds(), hasSize(2)); + assertThat(res.getTempos().get(2).getClouds().get(0).getQuantity(), is(CloudQuantity.FEW)); + assertThat(res.getTempos().get(2).getClouds().get(0).getType(), is(CloudType.TCU)); + assertThat(res.getTempos().get(2).getClouds().get(1).getQuantity(), is(CloudQuantity.BKN)); + assertThat(res.getTempos().get(2).getClouds().get(1).getType(), nullValue()); + assertThat(res.getTempos().get(2).getProbability(), is(40)); + + // First BECMG + assertThat(res.getBECMGs(), hasSize(1)); + BECMGTafTrend becmg = res.getBECMGs().get(0); + assertEquals(15, becmg.getValidity().getStartDay().intValue()); + assertEquals(20, becmg.getValidity().getStartHour().intValue()); + assertEquals(15, becmg.getValidity().getEndDay().intValue()); + assertEquals(22, becmg.getValidity().getEndHour().intValue()); + + // Fourth Tempo + TEMPOTafTrend tempo4 = res.getTempos().get(3); + assertEquals(16, tempo4.getValidity().getStartDay().intValue()); + assertEquals(3, tempo4.getValidity().getStartHour().intValue()); + assertEquals(16, tempo4.getValidity().getEndDay().intValue()); + assertEquals(8, tempo4.getValidity().getEndHour().intValue()); + assertEquals("3000m", tempo4.getVisibility().getMainVisibility()); + assertThat(tempo4.getWeatherConditions(), hasSize(1)); + assertNull(tempo4.getWeatherConditions().get(0).getIntensity()); + assertNull(tempo4.getWeatherConditions().get(0).getDescriptive()); + assertThat(tempo4.getWeatherConditions().get(0).getPhenomenons(), hasSize(1)); + assertEquals(Phenomenon.MIST, tempo4.getWeatherConditions().get(0).getPhenomenons().get(0)); + assertThat(tempo4.getClouds(), hasSize(1)); + assertEquals(CloudQuantity.BKN, tempo4.getClouds().get(0).getQuantity()); + assertNull(tempo4.getClouds().get(0).getType()); + assertNull(tempo4.getProbability()); + + // Fifth Tempo + TEMPOTafTrend tempo5 = res.getTempos().get(4); + assertEquals(16, tempo5.getValidity().getStartDay().intValue()); + assertEquals(4, tempo5.getValidity().getStartHour().intValue()); + assertEquals(16, tempo5.getValidity().getEndDay().intValue()); + assertEquals(7, tempo5.getValidity().getEndHour().intValue()); + assertEquals("400m", tempo5.getVisibility().getMainVisibility()); + assertThat(tempo5.getWeatherConditions(), hasSize(1)); + assertNull(tempo5.getWeatherConditions().get(0).getIntensity()); + assertEquals(Descriptive.PATCHES, tempo5.getWeatherConditions().get(0).getDescriptive()); + assertThat(tempo5.getWeatherConditions().get(0).getPhenomenons(), hasSize(1)); + assertEquals(Phenomenon.FOG, tempo5.getWeatherConditions().get(0).getPhenomenons().get(0)); + assertThat(tempo5.getClouds(), hasSize(1)); + assertEquals(CloudQuantity.BKN, tempo5.getClouds().get(0).getQuantity()); + assertNull(tempo5.getClouds().get(0).getType()); + assertThat(tempo5.getProbability(), is(40)); + } + + @Test + public void testParseValidWithoutLineBreaks() throws ParseException { + String taf = "TAF LSZH 292025Z 2921/3103 VRB03KT 9999 FEW020 BKN080 TX20/3014Z TN06/3003Z " + "PROB30 TEMPO 2921/2923 SHRA " + "BECMG 3001/3004 4000 MIFG NSC " + + "PROB40 3003/3007 1500 BCFG SCT004 " + "PROB30 3004/3007 0800 FG VV003 " + "BECMG 3006/3009 9999 FEW030 " + "PROB40 TEMPO 3012/3017 30008KT"; + + TAF res = fSut.parse(taf); + + assertThat(res, is(not(nullValue()))); + assertEquals(fSut.getAirportSupplier().get("LSZH"), res.getAirport()); + // Check on time delivery. + assertEquals(29, res.getDay().intValue()); + assertEquals(20, res.getTime().getHour()); + assertEquals(25, res.getTime().getMinute()); + // Checks on validity. + assertEquals(29, res.getValidity().getStartDay().intValue()); + assertEquals(21, res.getValidity().getStartHour().intValue()); + assertEquals(31, res.getValidity().getEndDay().intValue()); + assertEquals(3, res.getValidity().getEndHour().intValue()); + // Checks on wind. + assertThat(res.getWind().getDirectionDegrees(), nullValue()); + assertThat(res.getWind().getDirection(), is(Converter.degreesToDirection("VRB"))); + assertThat(res.getWind().getSpeed(), is(3)); + assertThat(res.getWind().getGust(), is(0)); + assertThat(res.getWind().getUnit(), is("KT")); + // Checks on visibility. + assertThat(res.getVisibility().getMainVisibility(), is(TEN_KM)); + //Check on clouds. + assertThat(res.getClouds(), hasSize(2)); + assertThat(res.getClouds().get(0).getQuantity(), is(CloudQuantity.FEW)); + assertThat(res.getClouds().get(0).getHeight(), is(2000)); + assertThat(res.getClouds().get(0).getType(), nullValue()); + + assertThat(res.getClouds().get(1).getQuantity(), is(CloudQuantity.BKN)); + assertThat(res.getClouds().get(1).getHeight(), is(8000)); + assertThat(res.getClouds().get(1).getType(), nullValue()); + // Check that no weatherCondition + assertThat(res.getWeatherConditions(), empty()); + // Check max temperature + assertThat(res.getMaxTemperature().getDay(), is(30)); + assertThat(res.getMaxTemperature().getHour(), is(14)); + assertThat(res.getMaxTemperature().getTemperature(), is(20)); + // Check min temperature + assertThat(res.getMinTemperature().getDay(), is(30)); + assertThat(res.getMinTemperature().getHour(), is(3)); + assertThat(res.getMinTemperature().getTemperature(), is(6)); + + // Checks on tempos. + assertThat(res.getTempos(), hasSize(2)); + // Checks on BECOMGs. + assertThat(res.getBECMGs(), hasSize(2)); + // Checks on probs. + assertThat(res.getProbs(), hasSize(2)); + + // First TEMPO + TEMPOTafTrend tempo0 = res.getTempos().get(0); + assertThat(tempo0.getValidity().getStartDay(), is(29)); + assertThat(tempo0.getValidity().getStartHour(), is(21)); + assertThat(tempo0.getValidity().getEndDay(), is(29)); + assertThat(tempo0.getValidity().getEndHour(), is(23)); + assertThat(tempo0.getWeatherConditions(), hasSize(1)); + assertThat(tempo0.getWeatherConditions().get(0).getIntensity(), is(nullValue())); + assertThat(tempo0.getWeatherConditions().get(0).getDescriptive(), is(Descriptive.SHOWERS)); + assertThat(tempo0.getWeatherConditions().get(0).getPhenomenons(), hasSize(1)); + assertThat(tempo0.getWeatherConditions().get(0).getPhenomenons().get(0), is(Phenomenon.RAIN)); + assertThat(tempo0.getProbability(), is(30)); + + // First BECOMG + BECMGTafTrend becmg0 = res.getBECMGs().get(0); + assertThat(becmg0.getValidity().getStartDay(), is(30)); + assertThat(becmg0.getValidity().getStartHour(), is(1)); + assertThat(becmg0.getValidity().getEndDay(), is(30)); + assertThat(becmg0.getValidity().getEndHour(), is(4)); + assertThat(becmg0.getVisibility().getMainVisibility(), is("4000m")); + assertThat(becmg0.getWeatherConditions().get(0).getIntensity(), is(nullValue())); + assertThat(becmg0.getWeatherConditions().get(0).getDescriptive(), is(Descriptive.SHALLOW)); + assertThat(becmg0.getWeatherConditions().get(0).getPhenomenons(), hasSize(1)); + assertThat(becmg0.getWeatherConditions().get(0).getPhenomenons().get(0), is(Phenomenon.FOG)); + assertThat(becmg0.getClouds().get(0).getQuantity(), is(CloudQuantity.NSC)); + + // First PROB + PROBTafTrend prob0 = res.getProbs().get(0); + assertThat(prob0.getValidity().getStartDay(), is(30)); + assertThat(prob0.getValidity().getStartHour(), is(3)); + assertThat(prob0.getValidity().getEndDay(), is(30)); + assertThat(prob0.getValidity().getEndHour(), is(7)); + assertThat(prob0.getVisibility().getMainVisibility(), is("1500m")); + assertThat(prob0.getWeatherConditions().get(0).getIntensity(), is(nullValue())); + assertThat(prob0.getWeatherConditions().get(0).getDescriptive(), is(Descriptive.PATCHES)); + assertThat(prob0.getWeatherConditions().get(0).getPhenomenons(), hasSize(1)); + assertThat(prob0.getWeatherConditions().get(0).getPhenomenons().get(0), is(Phenomenon.FOG)); + assertThat(prob0.getClouds(), hasSize(1)); + assertThat(prob0.getClouds().get(0).getQuantity(), is(CloudQuantity.SCT)); + assertThat(prob0.getClouds().get(0).getHeight(), is(400)); + assertThat(prob0.getClouds().get(0).getType(), nullValue()); + assertThat(prob0.getProbability(), is(40)); + + // Second PROB + PROBTafTrend prob1 = res.getProbs().get(1); + assertThat(prob1.getValidity().getStartDay(), is(30)); + assertThat(prob1.getValidity().getStartHour(), is(4)); + assertThat(prob1.getValidity().getEndDay(), is(30)); + assertThat(prob1.getValidity().getEndHour(), is(7)); + assertThat(prob1.getVisibility().getMainVisibility(), is("800m")); + assertThat(prob1.getWeatherConditions().get(0).getIntensity(), is(nullValue())); + assertThat(prob1.getWeatherConditions().get(0).getDescriptive(), is(nullValue())); + assertThat(prob1.getWeatherConditions().get(0).getPhenomenons(), hasSize(1)); + assertThat(prob1.getWeatherConditions().get(0).getPhenomenons().get(0), is(Phenomenon.FOG)); + assertThat(prob1.getVerticalVisibility(), is(300)); + assertThat(prob1.getClouds(), hasSize(0)); + assertThat(prob1.getProbability(), is(30)); + + // Second BECOMG + BECMGTafTrend becmg1 = res.getBECMGs().get(1); + assertThat(becmg1.getValidity().getStartDay(), is(30)); + assertThat(becmg1.getValidity().getStartHour(), is(6)); + assertThat(becmg1.getValidity().getEndDay(), is(30)); + assertThat(becmg1.getValidity().getEndHour(), is(9)); + assertThat(becmg1.getVisibility().getMainVisibility(), is(TEN_KM)); + assertThat(becmg1.getWeatherConditions(), hasSize(0)); + assertThat(becmg1.getClouds(), hasSize(1)); + assertThat(becmg1.getClouds().get(0).getQuantity(), is(CloudQuantity.FEW)); + assertThat(becmg1.getClouds().get(0).getHeight(), is(3000)); + assertThat(becmg1.getClouds().get(0).getType(), nullValue()); + + // Second TEMPO + TEMPOTafTrend tempo1 = res.getTempos().get(1); + assertThat(tempo1.getValidity().getStartDay(), is(30)); + assertThat(tempo1.getValidity().getStartHour(), is(12)); + assertThat(tempo1.getValidity().getEndDay(), is(30)); + assertThat(tempo1.getValidity().getEndHour(), is(17)); + assertThat(tempo1.getWeatherConditions(), hasSize(0)); + assertThat(tempo1.getWind().getDirectionDegrees(), is(300)); + assertThat(tempo1.getWind().getDirection(), is(Converter.degreesToDirection("300.0"))); + assertThat(tempo1.getWind().getSpeed(), is(8)); + assertThat(tempo1.getWind().getGust(), is(0)); + assertThat(tempo1.getWind().getUnit(), is("KT")); + assertThat(tempo1.getProbability(), is(40)); + } + + @Test + public void testParseValidWithoutLineBreaksAndEndingTemperature() throws ParseException { + String taf = "TAF KLSV 120700Z 1207/1313 VRB06KT 9999 SCT250 QNH2992INS BECMG 1217/1218 10010G15KT 9999 SCT250 QNH2980INS BECMG 1303/1304 VRB06KT 9999 FEW250 QNH2979INS TX42/1223Z TN24/1213Z"; + + TAF res = fSut.parse(taf); + + assertThat(res, is(not(nullValue()))); + assertEquals(fSut.getAirportSupplier().get("KLSV"), res.getAirport()); + // Check on time delivery. + assertEquals(12, res.getDay().intValue()); + assertEquals(7, res.getTime().getHour()); + assertEquals(0, res.getTime().getMinute()); + // Checks on validity. + assertEquals(12, res.getValidity().getStartDay().intValue()); + assertEquals(7, res.getValidity().getStartHour().intValue()); + assertEquals(13, res.getValidity().getEndDay().intValue()); + assertEquals(13, res.getValidity().getEndHour().intValue()); + // Checks on wind. + assertThat(res.getWind().getDirectionDegrees(), nullValue()); + assertThat(res.getWind().getDirection(), is(Converter.degreesToDirection("VRB"))); + assertThat(res.getWind().getSpeed(), is(6)); + assertThat(res.getWind().getGust(), is(0)); + assertThat(res.getWind().getUnit(), is("KT")); + // Checks on visibility. + assertThat(res.getVisibility().getMainVisibility(), is(TEN_KM)); + //Check on clouds. + assertThat(res.getClouds(), hasSize(1)); + assertThat(res.getClouds().get(0).getQuantity(), is(CloudQuantity.SCT)); + assertThat(res.getClouds().get(0).getHeight(), is(25000)); + assertThat(res.getClouds().get(0).getType(), nullValue()); + + // Check that no weatherCondition + assertThat(res.getWeatherConditions(), empty()); + // Check max temperature + assertThat(res.getMaxTemperature().getDay(), is(12)); + assertThat(res.getMaxTemperature().getHour(), is(23)); + assertThat(res.getMaxTemperature().getTemperature(), is(42)); + // Check min temperature + assertThat(res.getMinTemperature().getDay(), is(12)); + assertThat(res.getMinTemperature().getHour(), is(13)); + assertThat(res.getMinTemperature().getTemperature(), is(24)); + + // Checks on BECOMGs. + assertThat(res.getBECMGs(), hasSize(2)); + + // First BECOMG + BECMGTafTrend becmg0 = res.getBECMGs().get(0); + assertThat(becmg0.getValidity().getStartDay(), is(12)); + assertThat(becmg0.getValidity().getStartHour(), is(17)); + assertThat(becmg0.getValidity().getEndDay(), is(12)); + assertThat(becmg0.getValidity().getEndHour(), is(18)); + assertThat(becmg0.getVisibility().getMainVisibility(), is(TEN_KM)); + assertThat(becmg0.getWeatherConditions(), hasSize(0)); + assertThat(becmg0.getClouds().get(0).getQuantity(), is(CloudQuantity.SCT)); + assertThat(becmg0.getClouds().get(0).getHeight(), is(25000)); + assertThat(becmg0.getWind().getDirectionDegrees(), is(100)); + assertThat(becmg0.getWind().getDirection(), is(Converter.degreesToDirection("100.0"))); + assertThat(becmg0.getWind().getSpeed(), is(10)); + assertThat(becmg0.getWind().getGust(), is(15)); + assertThat(becmg0.getWind().getUnit(), is("KT")); + + // Second BECOMG + BECMGTafTrend becmg1 = res.getBECMGs().get(1); + assertThat(becmg1.getValidity().getStartDay(), is(13)); + assertThat(becmg1.getValidity().getStartHour(), is(3)); + assertThat(becmg1.getValidity().getEndDay(), is(13)); + assertThat(becmg1.getValidity().getEndHour(), is(4)); + assertThat(becmg1.getVisibility().getMainVisibility(), is(TEN_KM)); + assertThat(becmg1.getWind().getDirectionDegrees(), nullValue()); + assertThat(becmg1.getWind().getDirection(), is(Converter.degreesToDirection("VRB"))); + assertThat(becmg1.getWind().getSpeed(), is(6)); + assertThat(becmg1.getWind().getGust(), is(0)); + assertThat(becmg1.getWind().getUnit(), is("KT")); + assertThat(becmg1.getWeatherConditions(), hasSize(0)); + assertThat(becmg1.getClouds(), hasSize(1)); + assertThat(becmg1.getClouds().get(0).getQuantity(), is(CloudQuantity.FEW)); + assertThat(becmg1.getClouds().get(0).getHeight(), is(25000)); + assertThat(becmg1.getClouds().get(0).getType(), nullValue()); + } + + @Test + public void testParseWithFM() throws ParseException { + String message = "TAF KLWT 211120Z 2112/2212 20008KT 9999 SKC \n" + "TEMPO 2112/2116 VRB06KT \n" + "FM212300 30012G22KT 9999 FEW050 SCT250 \n" + "FM220700 27008KT 9999 FEW030 FEW250"; + + TAF res = fSut.parse(message); + assertNotNull(res); + + assertThat(res, is(not(nullValue()))); + assertThat(res.getAirport(), is(fSut.getAirportSupplier().get("KLWT"))); + assertThat(res.getDay(), is(21)); + assertThat(res.getTime().getHour(), is(11)); + assertThat(res.getTime().getMinute(), is(20)); + assertThat(res.getValidity().getStartDay(), is(21)); + assertThat(res.getValidity().getStartHour(), is(12)); + assertThat(res.getValidity().getEndDay(), is(22)); + assertThat(res.getValidity().getEndHour(), is(12)); + + // Wind + assertThat(res.getWind(), is(not(nullValue()))); + assertThat(res.getWind().getDirection(), is(Converter.degreesToDirection("200"))); + assertThat(res.getWind().getSpeed(), is(8)); + assertThat(res.getWind().getGust(), is(0)); + assertThat(res.getWind().getUnit(), is("KT")); + + // Visibility + assertThat(res.getVisibility(), is(not(nullValue()))); + assertThat(res.getVisibility().getMainVisibility(), is(TEN_KM)); + assertThat(res.getVisibility().getMinDirection(), is(nullValue())); + //Clouds + assertThat(res.getClouds(), hasSize(1)); + assertThat(res.getClouds().get(0).getQuantity(), is(CloudQuantity.SKC)); + + assertThat(res.getFMs(), hasSize(2)); + FMTafTrend fm1 = res.getFMs().get(0); + assertEquals(21, fm1.getValidity().getStartDay().intValue()); + assertEquals(23, fm1.getValidity().getStartHour().intValue()); + assertEquals(0, fm1.getValidity().getStartMinutes().intValue()); + assertEquals(300, fm1.getWind().getDirectionDegrees().intValue()); + assertEquals(12, fm1.getWind().getSpeed()); + assertEquals(22, fm1.getWind().getGust()); + assertThat(fm1.getClouds(), hasSize(2)); + assertEquals(CloudQuantity.FEW, fm1.getClouds().get(0).getQuantity()); + assertNull(fm1.getClouds().get(0).getType()); + assertEquals(CloudQuantity.SCT, fm1.getClouds().get(1).getQuantity()); + assertNull(fm1.getClouds().get(1).getType()); + // Tempos + assertThat(res.getTempos(), hasSize(1)); + assertThat(res.getTempos().get(0).getValidity().getStartDay(), is(21)); + assertThat(res.getTempos().get(0).getValidity().getStartHour(), is(12)); + assertThat(res.getTempos().get(0).getValidity().getEndDay(), is(21)); + assertThat(res.getTempos().get(0).getValidity().getEndHour(), is(16)); + assertEquals(Messages.getInstance().getString("Converter.VRB"), res.getTempos().get(0).getWind().getDirection()); + assertThat(res.getTempos().get(0).getWind().getSpeed(), is(6)); + + FMTafTrend fm2 = res.getFMs().get(1); + assertEquals(22, fm2.getValidity().getStartDay().intValue()); + assertEquals(7, fm2.getValidity().getStartHour().intValue()); + assertEquals(0, fm2.getValidity().getStartMinutes().intValue()); + assertThat(fm2.getClouds(), hasSize(2)); + + } + + @Test + public void testParseWith2Taf() throws ParseException { + String message = "TAF TAF LFPG 191100Z 1912/2018 02010KT 9999 FEW040 PROB30 "; + + TAF result = fSut.parse(message); + + assertNotNull(result); + assertThat(result.getProbs(), hasSize(1)); + assertThat(result.getProbs().get(0).getProbability(), is(30)); + } + + @Test + public void testParseInvalidMessage() { + String message = "LFPG 191100Z 1912/2018 02010KT 9999 FEW040 PROB30 "; + ParseException e = assertThrows(ParseException.class, () -> fSut.parse(message)); + assertEquals(ErrorCodes.ERROR_CODE_INVALID_MESSAGE, e.getErrorCode()); + } + + @Test + public void testParseWithWindShear() throws ParseException { + // GIVEN a TAF message with windshear in principal part and from part. + String message = "TAF KMKE 011530 0116/0218 WS020/24045KT\n" + "FM010200 17005KT P6SM SKC WS020/23055KT "; + // WHEN parsing the message. + TAF result = fSut.parse(message); + + assertEquals(message, result.getMessage()); + // THEN the windshear of the principle part is decoded + assertNotNull(result); + assertNotNull(result.getWindShear()); + assertEquals(2000, result.getWindShear().getHeight()); + assertEquals(240, result.getWindShear().getDirectionDegrees().intValue()); + assertEquals(45, result.getWindShear().getSpeed()); + + // Checks on the from part. + FMTafTrend fm = result.getFMs().get(0); + assertNotNull(fm); + // Checks on the wind of the FM + assertNotNull(fm.getWind()); + assertEquals(170, fm.getWind().getDirectionDegrees().intValue()); + assertEquals(5, fm.getWind().getSpeed()); + // Checks on the wind shear of the fm + assertNotNull(fm.getWindShear()); + assertEquals(2000, fm.getWindShear().getHeight()); + assertEquals(230, fm.getWindShear().getDirectionDegrees().intValue()); + assertEquals(55, fm.getWindShear().getSpeed()); + } + + @Test + public void testParseInvalidAirport() throws ParseException { + String message = "TAF AAAA 191100Z 1912/2018 02010KT 9999 FEW040 PROB30"; + TAF res = fSut.parse(message); + assertNull(res.getAirport()); + assertEquals("AAAA", res.getStation()); + } + + @Test + public void testParseWithNauticalMilesVisibility() throws ParseException { + // GIVEN a TAF message with nautical miles visibility + String message = "TAF CZBF 300939Z 3010/3022 VRB03KT 6SM -SN OVC015 \r\n" + "TEMPO 3010/3012 11/2SM -SN OVC009 \nFM301200 10008KT 2SM -SN OVC010 \r\n" + + "TEMPO 3012/3022 3/4SM -SN VV007 RMK FCST BASED ON AUTO OBS. NXT FCST BY 301400Z"; + + //WHEN parsing the message. + TAF result = fSut.parse(message); + //THEN the visibility of the main event is 6 SM + assertNotNull(result); + assertNotNull(result.getVisibility()); + assertEquals("6SM", result.getVisibility().getMainVisibility()); + //THEN the visibility of the first tempo is 11/2 SM + assertNotNull(result.getTempos().get(0).getVisibility()); + assertEquals("11/2SM", result.getTempos().get(0).getVisibility().getMainVisibility()); + //THEN the visibility of the second tempo is 3/4 SM + assertNotNull(result.getTempos().get(1).getVisibility()); + assertEquals("3/4SM", result.getTempos().get(1).getVisibility().getMainVisibility()); + // Then the visibility of the FROM part is 2SN + assertNotNull(result.getFMs().get(0).getVisibility()); + assertEquals("2SM", result.getFMs().get(0).getVisibility().getMainVisibility()); + assertFalse(result.isAmendment()); + } + + @Test + public void testParseWithAMDTAF() throws ParseException { + //GIVEN an amended TAF + String message = "TAF AMD LFPO 100742Z 1007/1112 21018G35KT 9999 BKN025 \r\n" + " TEMPO 1007/1009 4000 RA BKN014 SCT020CB PROB40 \r\n" + " TEMPO 1007/1009 22020G45KT \r\n" + + " TEMPO 1010/1017 24022G45KT SHRA SCT030CB PROB30 \r\n" + " TEMPO 1012/1016 -TSRA \r\n" + " BECMG 1020/1023 24013KT SCT023 \r\n" + + " TEMPO 1104/1112 4000 -SHRA BKN012 BKN020TCU"; + //WHEN parsing the message + TAF result = fSut.parse(message); + //Then the taf is correctly parsed and the amendment attribute is true. + assertTrue(result.isAmendment()); + } + + @Test + public void testParseWithCavok() throws ParseException { + // GIVEN a TAF with CAVOK in the main part and in a BECMG part. + String message = "TAF LFPG 211700Z 2118/2224 VRB03KT CAVOK TX15/2215Z TN02/2205Z \n" + "BECMG 2122/2124 3000 BR \n" + "TEMPO 2202/2209 0800 BCFG PROB30 \n" + "TEMPO 2203/2209 0500 FG \n" + + "BECMG 2211/2213 09006KT CAVOK"; + + // WHEN parsing the event. + TAF result = fSut.parse(message); + // THEN the result is CAVOK and the second BECMG is also cavok. + assertNotNull(result); + assertTrue(result.isCavok()); + assertEquals(TEN_KM, result.getVisibility().getMainVisibility()); + assertTrue(result.getBECMGs().get(1).isCavok()); + assertEquals(TEN_KM, result.getBECMGs().get(1).getVisibility().getMainVisibility()); + } + + @Test + public void testParseWithRMKInTempo() throws ParseException { + // GIVEN a TAF with remark in second tempo. + String message = "TAF CZBF 300939Z 3010/3022 VRB03KT 6SM -SN OVC015\n" + "TEMPO 3010/3012 11/2SM -SN OVC009 FM301200 10008KT 2SM -SN OVC010 \n" + + "TEMPO 3012/3022 3/4SM -SN VV007 RMK FCST BASED ON AUTO OBS. NXT FCST BY 301400Z"; + // WHEN parsing the event. + TAF result = fSut.parse(message); + // THEN the second tempo contains the remark. + assertNotNull(result); + assertNotNull(result.getTempos().get(1)); + assertNotNull(result.getTempos().get(1).getRemark()); + String rmk = + Messages.getInstance().getString(REMARK_FCST) + " " + Messages.getInstance().getString("Remark.BASED") + " " + Messages.getInstance().getString("Remark.ON") + " AUTO OBS. " + Messages + .getInstance().getString(REMARK_NXT) + " " + Messages.getInstance().getString(REMARK_FCST) + " BY 301400Z"; + assertThat(result.getTempos().get(1).getRemark(), containsString(rmk)); + } + + @Test + public void testParseWithRMK() throws ParseException { + // GIVEN a TAF with remark. + String message = "TAF CZBF 300939Z 3010/3022 VRB03KT 6SM -SN OVC015 RMK FCST BASED ON AUTO OBS. NXT FCST BY 301400Z\n" + "TEMPO 3010/3012 11/2SM -SN OVC009 FM301200 10008KT 2SM -SN OVC010 \n" + + "TEMPO 3012/3022 3/4SM -SN VV007"; + // WHEN parsing the event. + TAF result = fSut.parse(message); + // THEN the second tempo contains the remark. + assertNotNull(result); + String rmk = + Messages.getInstance().getString(REMARK_FCST) + " " + Messages.getInstance().getString("Remark.BASED") + " " + Messages.getInstance().getString("Remark.ON") + " AUTO OBS. " + Messages + .getInstance().getString(REMARK_NXT) + " " + Messages.getInstance().getString(REMARK_FCST) + " BY 301400Z"; + assertThat(result.getRemark(), containsString(rmk)); + String description = result.toString(); + assertThat(description, containsString(Messages.getInstance().getString("ToString.start.day.month") + "=30")); + assertThat(description, containsString(Messages.getInstance().getString("ToString.start.hour.day") + "=10")); + assertThat(description, containsString(Messages.getInstance().getString("ToString.end.day.month") + "=30")); + assertThat(description, containsString(Messages.getInstance().getString("ToString.end.hour.day") + "=12")); + } + +} diff --git a/metarParser-parsers/src/test/resources/META-INF/services/io.github.mivek.provider.airport.AirportProvider b/metarParser-parsers/src/test/resources/META-INF/services/io.github.mivek.provider.airport.AirportProvider new file mode 100644 index 00000000..0e5e53e6 --- /dev/null +++ b/metarParser-parsers/src/test/resources/META-INF/services/io.github.mivek.provider.airport.AirportProvider @@ -0,0 +1 @@ +io.github.mivek.provider.airport.impl.DefaultAirportProvider diff --git a/metarParser-services/README.md b/metarParser-services/README.md new file mode 100644 index 00000000..17a8e6d8 --- /dev/null +++ b/metarParser-services/README.md @@ -0,0 +1,3 @@ +# MetarParser-services + +This module allows the user to either parse messages or retrieve messages given an airport ICAO. diff --git a/metarParser-services/pom.xml b/metarParser-services/pom.xml new file mode 100644 index 00000000..7e1c6583 --- /dev/null +++ b/metarParser-services/pom.xml @@ -0,0 +1,28 @@ + + + + metarParser + io.github.mivek + 1.10.5 + + 4.0.0 + + metarParser-services + + + 0.95 + 0.90 + 0.99 + + + + + io.github.mivek + metarParser-parsers + ${project.version} + + + + diff --git a/src/main/java/io/github/mivek/facade/AbstractWeatherCodeFacade.java b/metarParser-services/src/main/java/io/github/mivek/service/AbstractWeatherCodeService.java similarity index 55% rename from src/main/java/io/github/mivek/facade/AbstractWeatherCodeFacade.java rename to metarParser-services/src/main/java/io/github/mivek/service/AbstractWeatherCodeService.java index 4319f287..3530cde4 100644 --- a/src/main/java/io/github/mivek/facade/AbstractWeatherCodeFacade.java +++ b/metarParser-services/src/main/java/io/github/mivek/service/AbstractWeatherCodeService.java @@ -1,38 +1,40 @@ -package io.github.mivek.facade; - -import io.github.mivek.model.AbstractWeatherCode; -import io.github.mivek.parser.AbstractParser; - -/** - * Abstract facade. - * @author mivek - * Abstract class for facade. - * @param a concrete sub-class of {@link AbstractWeatherCode}. - */ -public abstract class AbstractWeatherCodeFacade implements IWeatherCodeFacade { - /** - * Const for icao length. - */ - public static final int ICAO = 4; - - /** - * The parser. - */ - private AbstractParser fParser; - - /** - * Protected constructor to be used by sub-classes. - * @param pParser the parser to set. - */ - protected AbstractWeatherCodeFacade(final AbstractParser pParser) { - fParser = pParser; +package io.github.mivek.service; + +import io.github.mivek.model.AbstractWeatherCode; +import io.github.mivek.parser.AbstractParser; + +/** + * Abstract service. + * + * @param a concrete sub-class of {@link AbstractWeatherCode}. + * @author mivek + * Abstract class for the service. + */ +public abstract class AbstractWeatherCodeService implements IWeatherCodeFacade { + /** + * Const for icao length. + */ + public static final int ICAO = 4; + + /** + * The parser. + */ + private final AbstractParser fParser; + + /** + * Protected constructor to be used by sub-classes. + * + * @param parser the parser to set. + */ + protected AbstractWeatherCodeService(final AbstractParser parser) { + fParser = parser; } - - /** - * @return the parser. - */ - protected AbstractParser getParser() { - return fParser; - } - -} + + /** + * @return the parser. + */ + protected AbstractParser getParser() { + return fParser; + } + +} diff --git a/src/main/java/io/github/mivek/facade/IWeatherCodeFacade.java b/metarParser-services/src/main/java/io/github/mivek/service/IWeatherCodeFacade.java similarity index 60% rename from src/main/java/io/github/mivek/facade/IWeatherCodeFacade.java rename to metarParser-services/src/main/java/io/github/mivek/service/IWeatherCodeFacade.java index 463dd691..4ea53a9c 100644 --- a/src/main/java/io/github/mivek/facade/IWeatherCodeFacade.java +++ b/metarParser-services/src/main/java/io/github/mivek/service/IWeatherCodeFacade.java @@ -1,32 +1,35 @@ -package io.github.mivek.facade; - -import java.io.IOException; -import java.net.URISyntaxException; - -import io.github.mivek.exception.ParseException; -import io.github.mivek.model.AbstractWeatherCode; - -/** - * Interface for facade. +package io.github.mivek.service; + +import java.io.IOException; +import java.net.URISyntaxException; + +import io.github.mivek.exception.ParseException; +import io.github.mivek.model.AbstractWeatherCode; + +/** + * Interface for service. + * + * @param a concrete sub-class of {@link AbstractWeatherCode} * @author mivek - * @param a concrete sub-class of {@link AbstractWeatherCode} - */ -public interface IWeatherCodeFacade { - /** - * Decode method. - * @param pCode the code to decode. - * @return the decoded object corresponding to the message. - * @throws ParseException when an error occurs during the parsing. - */ - T decode(String pCode) throws ParseException; - - /** - * Retrieve code and decoded object from airport with icao. - * @param pIcao the icao of the airport - * @return the decoded object - * @throws IOException When an error occurs - * @throws URISyntaxException When an error occurs. - * @throws ParseException when an error occurs during the parsing. - */ - T retrieveFromAirport(String pIcao) throws ParseException, IOException, URISyntaxException; -} + */ +public interface IWeatherCodeFacade { + /** + * Decode method. + * + * @param code the code to decode. + * @return the decoded object corresponding to the message. + * @throws ParseException when an error occurs during the parsing. + */ + T decode(String code) throws ParseException; + + /** + * Retrieve code and decoded object from airport with icao. + * + * @param icao the icao of the airport + * @return the decoded object + * @throws IOException When an error occurs + * @throws URISyntaxException When an error occurs. + * @throws ParseException when an error occurs during the parsing. + */ + T retrieveFromAirport(String icao) throws ParseException, IOException, URISyntaxException; +} diff --git a/src/main/java/io/github/mivek/facade/MetarFacade.java b/metarParser-services/src/main/java/io/github/mivek/service/MetarService.java similarity index 63% rename from src/main/java/io/github/mivek/facade/MetarFacade.java rename to metarParser-services/src/main/java/io/github/mivek/service/MetarService.java index 38027330..2370ae2b 100644 --- a/src/main/java/io/github/mivek/facade/MetarFacade.java +++ b/metarParser-services/src/main/java/io/github/mivek/service/MetarService.java @@ -1,61 +1,63 @@ -package io.github.mivek.facade; - -import java.io.BufferedReader; -import java.io.IOException; -import java.io.InputStreamReader; -import java.net.URL; -import java.net.URLConnection; -import java.nio.charset.StandardCharsets; - -import io.github.mivek.exception.ErrorCodes; -import io.github.mivek.exception.ParseException; -import io.github.mivek.model.Metar; -import io.github.mivek.parser.MetarParser; - -/** - * Class representing the facade for metars. - * @author mivek - */ -public final class MetarFacade extends AbstractWeatherCodeFacade { - /** URL to retrieve the metar from. */ - private static final String NOAA_METAR_URL = "https://tgftp.nws.noaa.gov/data/observations/metar/stations/"; - /** - * Instance. - */ - private static final MetarFacade INSTANCE = new MetarFacade(); - - /** - * Private constructor. - */ - private MetarFacade() { - super(MetarParser.getInstance()); - } - - @Override - public Metar decode(final String pCode) throws ParseException { - return getParser().parse(pCode); - } - - @Override - public Metar retrieveFromAirport(final String pIcao) throws ParseException, IOException { - if (pIcao.length() != AbstractWeatherCodeFacade.ICAO) { - throw new ParseException(ErrorCodes.ERROR_CODE_INVALID_ICAO); // $NON-NLS-1$ - } - String website = NOAA_METAR_URL + pIcao.toUpperCase() // $NON-NLS-1$ - + ".TXT"; //$NON-NLS-1$ - URL url = new URL(website); - URLConnection urlCo = url.openConnection(); - try (BufferedReader br = new BufferedReader(new InputStreamReader(urlCo.getInputStream(), StandardCharsets.UTF_8))) { - String line = br.lines().toArray(String[]::new)[1]; - return getParser().parse(line); - } - } - - /** - * Returns a instance of the class. - * @return the instance of the class. - */ - public static MetarFacade getInstance() { - return INSTANCE; - } -} +package io.github.mivek.service; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.net.URL; +import java.net.URLConnection; +import java.nio.charset.StandardCharsets; + +import io.github.mivek.exception.ErrorCodes; +import io.github.mivek.exception.ParseException; +import io.github.mivek.model.Metar; +import io.github.mivek.parser.MetarParser; + +/** + * Class representing the service for metar. + * + * @author mivek + */ +public final class MetarService extends AbstractWeatherCodeService { + /** URL to retrieve the metar from. */ + private static final String NOAA_METAR_URL = "https://tgftp.nws.noaa.gov/data/observations/metar/stations/"; + /** + * Instance. + */ + private static final MetarService INSTANCE = new MetarService(); + + /** + * Private constructor. + */ + private MetarService() { + super(MetarParser.getInstance()); + } + + @Override + public Metar decode(final String code) throws ParseException { + return getParser().parse(code); + } + + @Override + public Metar retrieveFromAirport(final String icao) throws ParseException, IOException { + if (icao.length() != AbstractWeatherCodeService.ICAO) { + throw new ParseException(ErrorCodes.ERROR_CODE_INVALID_ICAO); // $NON-NLS-1$ + } + String website = NOAA_METAR_URL + icao.toUpperCase() // $NON-NLS-1$ + + ".TXT"; //$NON-NLS-1$ + URL url = new URL(website); + URLConnection urlCo = url.openConnection(); + try (BufferedReader br = new BufferedReader(new InputStreamReader(urlCo.getInputStream(), StandardCharsets.UTF_8))) { + String line = br.lines().toArray(String[]::new)[1]; + return getParser().parse(line); + } + } + + /** + * Returns a instance of the class. + * + * @return the instance of the class. + */ + public static MetarService getInstance() { + return INSTANCE; + } +} diff --git a/src/main/java/io/github/mivek/facade/TAFFacade.java b/metarParser-services/src/main/java/io/github/mivek/service/TAFService.java similarity index 62% rename from src/main/java/io/github/mivek/facade/TAFFacade.java rename to metarParser-services/src/main/java/io/github/mivek/service/TAFService.java index ee6c945d..82c27305 100644 --- a/src/main/java/io/github/mivek/facade/TAFFacade.java +++ b/metarParser-services/src/main/java/io/github/mivek/service/TAFService.java @@ -1,85 +1,86 @@ -package io.github.mivek.facade; - -import java.io.BufferedReader; -import java.io.IOException; -import java.io.InputStreamReader; -import java.net.URISyntaxException; -import java.net.URL; -import java.nio.charset.StandardCharsets; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; - -import io.github.mivek.exception.ErrorCodes; -import io.github.mivek.exception.ParseException; -import io.github.mivek.model.TAF; -import io.github.mivek.parser.TAFParser; - -/** - * Facade for TAF. - * @author mivek - */ -public final class TAFFacade extends AbstractWeatherCodeFacade { - /** URL to retrieve the TAF from. */ - private static final String NOAA_TAF_URL = "https://tgftp.nws.noaa.gov/data/forecasts/taf/stations/"; - /** - * The instance of the facade. - */ - private static final TAFFacade INSTANCE = new TAFFacade(); - - /** - * Constructor. - */ - private TAFFacade() { - super(TAFParser.getInstance()); - } - - @Override - public TAF decode(final String pCode) throws ParseException { - return getParser().parse(pCode); - } - - @Override - public TAF retrieveFromAirport(final String pIcao) throws IOException, URISyntaxException, ParseException { - if (pIcao.length() != AbstractWeatherCodeFacade.ICAO) { - throw new ParseException(ErrorCodes.ERROR_CODE_INVALID_ICAO); - } - String website = NOAA_TAF_URL + pIcao.toUpperCase() // $NON-NLS-1$ - + ".TXT"; //$NON-NLS-1$ - URL url = new URL(website); - try (BufferedReader br = new BufferedReader(new InputStreamReader(url.openStream(), StandardCharsets.UTF_8))) { - StringBuilder sb = new StringBuilder(); - // Throw the first line since it is not part of the TAF event. - br.readLine(); - br.lines().forEach(currentLine -> sb.append(currentLine.replaceAll("\\s{2,}", "")).append("\n")); - return getParser().parse(format(sb.toString())); - } - } - - /** - * Reformat the first line of the code. - * @param pCode the first line of the TAF event. - * @return the formated taf code. - * @throws ParseException when an error occurs. - */ - protected String format(final String pCode) throws ParseException { - String[] lines = pCode.split("\n"); - if (!TAFParser.TAF.equals(lines[0].trim())) { - return pCode; - } - if ("AMD TAF".equals(lines[1].trim())) { - List list = new ArrayList<>(Arrays.asList(lines)); - list.remove(1); - lines = list.toArray(new String[0]); - } - // Case of TAF AMD, the 2 first lines must be merged. - return Arrays.stream(lines).reduce((x, y) -> x + y + "\n").orElseThrow(() -> new ParseException(ErrorCodes.ERROR_CODE_INVALID_MESSAGE)); - } - - /** - * @return the instance of the facade. - */ - public static TAFFacade getInstance() { - return INSTANCE; - } -} +package io.github.mivek.service; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.net.URISyntaxException; +import java.net.URL; +import java.nio.charset.StandardCharsets; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +import io.github.mivek.exception.ErrorCodes; +import io.github.mivek.exception.ParseException; +import io.github.mivek.model.TAF; +import io.github.mivek.parser.TAFParser; + +/** + * Facade for TAF. + * + * @author mivek + */ +public final class TAFService extends AbstractWeatherCodeService { + /** URL to retrieve the TAF from. */ + private static final String NOAA_TAF_URL = "https://tgftp.nws.noaa.gov/data/forecasts/taf/stations/"; + /** + * The instance of the service. + */ + private static final TAFService INSTANCE = new TAFService(); + + /** + * Constructor. + */ + private TAFService() { + super(TAFParser.getInstance()); + } + + @Override + public TAF decode(final String code) throws ParseException { + return getParser().parse(code); + } + + @Override + public TAF retrieveFromAirport(final String icao) throws IOException, URISyntaxException, ParseException { + if (icao.length() != AbstractWeatherCodeService.ICAO) { + throw new ParseException(ErrorCodes.ERROR_CODE_INVALID_ICAO); + } + String website = NOAA_TAF_URL + icao.toUpperCase() // $NON-NLS-1$ + + ".TXT"; //$NON-NLS-1$ + URL url = new URL(website); + try (BufferedReader br = new BufferedReader(new InputStreamReader(url.openStream(), StandardCharsets.UTF_8))) { + StringBuilder sb = new StringBuilder(); + // Throw the first line since it is not part of the TAF event. + br.lines().skip(1).forEach(currentLine -> sb.append(currentLine.replaceAll("\\s{2,}", "")).append("\n")); + return getParser().parse(format(sb.toString())); + } + } + + /** + * Reformat the first line of the code. + * + * @param code the first line of the TAF event. + * @return the formated taf code. + * @throws ParseException when an error occurs. + */ + protected String format(final String code) throws ParseException { + String[] lines = code.split("\n"); + if (!TAFParser.TAF.equals(lines[0].trim())) { + return code; + } + if ("AMD TAF".equals(lines[1].trim())) { + List list = new ArrayList<>(Arrays.asList(lines)); + list.remove(1); + lines = list.toArray(new String[0]); + } + // Case of TAF AMD, the 2 first lines must be merged. + return Arrays.stream(lines).reduce((x, y) -> x + y + "\n").orElseThrow(() -> new ParseException(ErrorCodes.ERROR_CODE_INVALID_MESSAGE)); + } + + /** + * @return the instance of the service. + */ + public static TAFService getInstance() { + return INSTANCE; + } +} diff --git a/metarParser-services/src/main/java/io/github/mivek/service/package-info.java b/metarParser-services/src/main/java/io/github/mivek/service/package-info.java new file mode 100644 index 00000000..a7434a62 --- /dev/null +++ b/metarParser-services/src/main/java/io/github/mivek/service/package-info.java @@ -0,0 +1,6 @@ +/** + * Contains the services of the application. + * + * @author mivek + */ +package io.github.mivek.service; diff --git a/metarParser-services/src/test/java/io/github/mivek/service/AbstractWeatherCodeServiceTest.java b/metarParser-services/src/test/java/io/github/mivek/service/AbstractWeatherCodeServiceTest.java new file mode 100644 index 00000000..7daa7ad9 --- /dev/null +++ b/metarParser-services/src/test/java/io/github/mivek/service/AbstractWeatherCodeServiceTest.java @@ -0,0 +1,35 @@ +package io.github.mivek.service; + +import io.github.mivek.exception.ErrorCodes; +import io.github.mivek.exception.ParseException; +import io.github.mivek.model.AbstractWeatherCode; +import org.junit.Ignore; +import org.junit.Test; + +import java.io.IOException; +import java.net.URISyntaxException; + +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.is; +import static org.hamcrest.Matchers.notNullValue; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertThrows; + +@Ignore +public abstract class AbstractWeatherCodeServiceTest { + protected abstract AbstractWeatherCodeService getSut(); + + @Test + public void testRetrieveFromAirportInvalid() { + ParseException e = assertThrows(ParseException.class, () -> getSut().retrieveFromAirport("RandomIcao")); + assertEquals(ErrorCodes.ERROR_CODE_INVALID_ICAO, e.getErrorCode()); + } + + @Test + public void testRetrieveFromAirport() throws IOException, ParseException, URISyntaxException { + T res = getSut().retrieveFromAirport("LFPG"); + assertThat(res, notNullValue()); + assertThat(res.getAirport().getIcao(), is("LFPG")); + } + +} diff --git a/src/test/java/io/github/mivek/facade/MetarFacadeTest.java b/metarParser-services/src/test/java/io/github/mivek/service/MetarServiceTest.java similarity index 67% rename from src/test/java/io/github/mivek/facade/MetarFacadeTest.java rename to metarParser-services/src/test/java/io/github/mivek/service/MetarServiceTest.java index 3f145faa..dc133858 100644 --- a/src/test/java/io/github/mivek/facade/MetarFacadeTest.java +++ b/metarParser-services/src/test/java/io/github/mivek/service/MetarServiceTest.java @@ -1,53 +1,48 @@ -package io.github.mivek.facade; - -import static org.hamcrest.Matchers.empty; -import static org.hamcrest.Matchers.is; -import static org.hamcrest.Matchers.not; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertThat; -import static org.junit.Assert.assertTrue; - -import org.junit.Test; - -import io.github.mivek.exception.ParseException; -import io.github.mivek.internationalization.Messages; -import io.github.mivek.model.Metar; - -public class MetarFacadeTest extends AbstractWeatherCodeFacadeTest { - @Test - public void testDecodeValidMetar() throws ParseException { - String code = "LFPG 251830Z 17013KT 9999 OVC006 04/03 Q1012 NOSIG"; - - Metar res = MetarFacade.getInstance().decode(code); - - assertNotNull(res); - assertEquals("LFPG", res.getAirport().getIcao()); - assertEquals(25, res.getDay().intValue()); - // Time - assertNotNull(res.getTime()); - assertEquals(18, res.getTime().getHour()); - assertEquals(30, res.getTime().getMinute()); - // Wind - assertNotNull(res.getWind()); - assertEquals(Messages.getInstance().getString("Converter.S"), res.getWind().getDirection()); - assertEquals(13, res.getWind().getSpeed()); - assertEquals("KT", res.getWind().getUnit()); - // Visibility - assertEquals(">10km", res.getVisibility().getMainVisibility()); - // Temperatures - assertEquals(4, res.getTemperature().intValue()); - assertEquals(3, res.getDewPoint().intValue()); - // Altimeter - assertEquals(1012, res.getAltimeter().intValue()); - assertTrue(res.isNosig()); - // Clouds. - assertThat(res.getClouds(), is(not(empty()))); - - } - - @Override - protected AbstractWeatherCodeFacade getSut() { - return MetarFacade.getInstance(); - } -} +package io.github.mivek.service; + +import io.github.mivek.exception.ParseException; +import io.github.mivek.internationalization.Messages; +import io.github.mivek.model.Metar; +import org.junit.Test; + +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.*; +import static org.junit.Assert.*; + +public class MetarServiceTest extends AbstractWeatherCodeServiceTest { + @Test + public void testDecodeValidMetar() throws ParseException { + String code = "LFPG 251830Z 17013KT 9999 OVC006 04/03 Q1012 NOSIG"; + + Metar res = MetarService.getInstance().decode(code); + + assertNotNull(res); + assertEquals("LFPG", res.getAirport().getIcao()); + assertEquals(25, res.getDay().intValue()); + // Time + assertNotNull(res.getTime()); + assertEquals(18, res.getTime().getHour()); + assertEquals(30, res.getTime().getMinute()); + // Wind + assertNotNull(res.getWind()); + assertEquals(Messages.getInstance().getString("Converter.S"), res.getWind().getDirection()); + assertEquals(13, res.getWind().getSpeed()); + assertEquals("KT", res.getWind().getUnit()); + // Visibility + assertEquals(">10km", res.getVisibility().getMainVisibility()); + // Temperatures + assertEquals(4, res.getTemperature().intValue()); + assertEquals(3, res.getDewPoint().intValue()); + // Altimeter + assertEquals(1012, res.getAltimeter().intValue()); + assertTrue(res.isNosig()); + // Clouds. + assertThat(res.getClouds(), is(not(empty()))); + + } + + @Override + protected AbstractWeatherCodeService getSut() { + return MetarService.getInstance(); + } +} diff --git a/metarParser-services/src/test/java/io/github/mivek/service/TAFServiceTest.java b/metarParser-services/src/test/java/io/github/mivek/service/TAFServiceTest.java new file mode 100644 index 00000000..1f84fb2f --- /dev/null +++ b/metarParser-services/src/test/java/io/github/mivek/service/TAFServiceTest.java @@ -0,0 +1,61 @@ +package io.github.mivek.service; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; + +import org.junit.Test; + +import io.github.mivek.exception.ParseException; +import io.github.mivek.model.TAF; + +public class TAFServiceTest extends AbstractWeatherCodeServiceTest { + + private final TAFService sut = TAFService.getInstance(); + + @Override + protected AbstractWeatherCodeService getSut() { + return sut; + } + + @Test + public void testFormatWithAMD() throws ParseException { + // Given a taf message with AMD on second line. + String message = + "TAF \n" + "AMD LFPG 100910Z 1009/1112 20015G25KT 9999 BKN035 \n" + "TEMPO 1011/1019 26020G35KT 4000 SHRA BKN012TCU PROB30 \n" + "TEMPO 1015/1019 27025G45KT 2500 TSRAGS SCT012CB \n" + + "BECMG 1021/1024 27010KT PROB30 \n" + "TEMPO 1105/1107 BKN014 \n" + "BECMG 1109/1111 34010KT"; + + String formatedString = + "TAF AMD LFPG 100910Z 1009/1112 20015G25KT 9999 BKN035 \n" + "TEMPO 1011/1019 26020G35KT 4000 SHRA BKN012TCU PROB30 \n" + "TEMPO 1015/1019 27025G45KT 2500 TSRAGS SCT012CB \n" + + "BECMG 1021/1024 27010KT PROB30 \n" + "TEMPO 1105/1107 BKN014 \n" + "BECMG 1109/1111 34010KT\n"; + + // When formating the message + String result = sut.format(message); + // Then the 2 first lines are merged. + assertNotNull(result); + assertEquals(formatedString, result); + } + + @Test + public void testFormatWithoutReformat() throws ParseException { + // GIVEN a taf with a full first line ie the first line is not only work "TAF" + String message = "TAF LFPG 121700Z 1218/1324 13003KT CAVOK TX09/1315Z TN00/1306Z \n" + "TEMPO 1303/1308 4000 BR"; + // WHEN formating the message + String result = sut.format(message); + // THEN the message is not edited. + assertEquals(message, result); + } + + @Test + public void testFormat() throws ParseException { + String tafMessage = "TAF \n" + "AMD TAF \n" + "AMD LFPG 241332Z 2413/2518 01008KT 7000 BKN015 TX13/2414Z TN03/2505Z \n" + "BECMG 2413/2415 BKN040 \n" + "BECMG 2415/2417 CAVOK \n" + + "BECMG 2509/2511 BKN030 \n" + "TEMPO 2514/2516 36015G25KT \n" + "BECMG 2516/2518 CAVOK"; + + String formatted = "TAF AMD LFPG 241332Z 2413/2518 01008KT 7000 BKN015 TX13/2414Z TN03/2505Z \n" + "BECMG 2413/2415 BKN040 \n" + "BECMG 2415/2417 CAVOK \n" + "BECMG 2509/2511 BKN030 \n" + + "TEMPO 2514/2516 36015G25KT \n" + "BECMG 2516/2518 CAVOK\n"; + // When formating the message + String result = sut.format(tafMessage); + // Then the 2 first lines are merged. + assertNotNull(result); + assertEquals(formatted, result); + } +} diff --git a/metarParser-spi/README.md b/metarParser-spi/README.md new file mode 100644 index 00000000..77f4d51c --- /dev/null +++ b/metarParser-spi/README.md @@ -0,0 +1,32 @@ +# SPI Module + +This module contains interfaces and implementations for the SPI pattern. + +## Airport source + +The interface `AirportProvider` defines the contract needed for the implementation. +Implementations should return a map of airport. The key should be the ICAO of the station and the value the `Airport` object. + +### Default implementations + +The project provides 2 default implementations: + +- `DefaultAirportProvider` : The implementation uses a file contained in the project `airport.dat` for [openflights](https://openflights.org/). +- `OurAirportsAirportProvider`: This implementation is based on [ourairports](https://ourairports.com) onlines csv of countries and airport. To use this implementation make sure you have internet access. + +### Specify the implementation + +It is possible to set the implementation to use according to the [SPI pattern](https://docs.oracle.com/javase/tutorial/sound/SPI-intro.html). +Create a file named `io.github.mivek.provider.airport.AirportProvider` in the folder `META-INF/services` of your application. +In this file write the fully qualified name of the implementation you want to use. + +Example + +```(java) +io.github.mivek.provider.airport.impl.OurAirportsAirportProvider +``` + +### Add your own implementation + +You can use your own implementation of `AirportProvider`. +Create a class extending the interface `AirportProvider`, and follow the steps written [above](#specify-the-implementation). diff --git a/metarParser-spi/pom.xml b/metarParser-spi/pom.xml new file mode 100644 index 00000000..e66f9e7b --- /dev/null +++ b/metarParser-spi/pom.xml @@ -0,0 +1,35 @@ + + + + metarParser + io.github.mivek + 1.10.5 + + 4.0.0 + + metarParser-spi + + + 0.96 + 0.99 + 0.99 + + + + + org.apache.commons + commons-lang3 + + + io.github.mivek + metarParser-entities + ${project.version} + + + com.opencsv + opencsv + + + diff --git a/metarParser-spi/src/main/java/io/github/mivek/provider/airport/AirportProvider.java b/metarParser-spi/src/main/java/io/github/mivek/provider/airport/AirportProvider.java new file mode 100644 index 00000000..02a1c5b6 --- /dev/null +++ b/metarParser-spi/src/main/java/io/github/mivek/provider/airport/AirportProvider.java @@ -0,0 +1,19 @@ +package io.github.mivek.provider.airport; + +import io.github.mivek.model.Airport; + +import java.util.Map; + +/** + * Service providing {@link Airport}. + * + * @author mivek + */ +public interface AirportProvider { + + /** + * @return a map of airports with the ICAO code as key. + */ + Map getAirports(); +} + diff --git a/src/main/java/io/github/mivek/command/AirportSupplier.java b/metarParser-spi/src/main/java/io/github/mivek/provider/airport/impl/DefaultAirportProvider.java similarity index 63% rename from src/main/java/io/github/mivek/command/AirportSupplier.java rename to metarParser-spi/src/main/java/io/github/mivek/provider/airport/impl/DefaultAirportProvider.java index 411ced44..3947eb16 100644 --- a/src/main/java/io/github/mivek/command/AirportSupplier.java +++ b/metarParser-spi/src/main/java/io/github/mivek/provider/airport/impl/DefaultAirportProvider.java @@ -1,10 +1,12 @@ -package io.github.mivek.command; +package io.github.mivek.provider.airport.impl; +import com.opencsv.CSVParser; import com.opencsv.CSVReader; +import com.opencsv.CSVReaderBuilder; import com.opencsv.exceptions.CsvValidationException; import io.github.mivek.model.Airport; import io.github.mivek.model.Country; -import io.github.mivek.parser.AbstractParser; +import io.github.mivek.provider.airport.AirportProvider; import java.io.IOException; import java.io.InputStream; @@ -12,35 +14,57 @@ import java.nio.charset.StandardCharsets; import java.util.HashMap; import java.util.Map; +import java.util.Objects; /** + * Default implementation of the AiportProvider using local files to build the airport map. + * * @author mivek */ -public final class AirportSupplier implements Supplier { +public final class DefaultAirportProvider implements AirportProvider { /** Path of airport file. */ - private final InputStream airportsFile = AbstractParser.class.getClassLoader().getResourceAsStream("data/airports.dat"); + private final InputStream airportsFile = DefaultAirportProvider.class.getClassLoader().getResourceAsStream("data/airports.dat"); /** Path of countries file. */ - private final InputStream countriesFile = AbstractParser.class.getClassLoader().getResourceAsStream("data/countries.dat"); + private final InputStream countriesFile = DefaultAirportProvider.class.getClassLoader().getResourceAsStream("data/countries.dat"); /** Map of countries. */ private Map countries; /** Map of airports. */ private Map airports; /** - * Constructor. + * Default constructor. */ - public AirportSupplier() { + public DefaultAirportProvider() { initCountries(); initAirports(); } + /** + * Initiate countries map. + */ + private void initCountries() { + Objects.requireNonNull(countriesFile); + countries = new HashMap<>(); + String[] line; + try (CSVReader reader = new CSVReaderBuilder(new InputStreamReader(countriesFile, StandardCharsets.UTF_8)).withCSVParser(new CSVParser()).withSkipLines(0).build()) { + while ((line = reader.readNext()) != null) { + Country country = new Country(); + country.setName(line[0]); + countries.put(country.getName(), country); + } + } catch (IOException | CsvValidationException exception) { + throw new IllegalStateException(exception.getMessage()); + } + } + /** * Initiate airports map. */ private void initAirports() { + Objects.requireNonNull(airportsFile); airports = new HashMap<>(); String[] line; - try (CSVReader reader = new CSVReader(new InputStreamReader(airportsFile, StandardCharsets.UTF_8))) { + try (CSVReader reader = new CSVReaderBuilder(new InputStreamReader(airportsFile, StandardCharsets.UTF_8)).withCSVParser(new CSVParser()).withSkipLines(0).build()) { while ((line = reader.readNext()) != null) { Airport airport = new Airport(); airport.setName(line[1]); @@ -60,25 +84,9 @@ private void initAirports() { } } - /** - * Initiate countries map. - */ - private void initCountries() { - countries = new HashMap<>(); - String[] line; - try (CSVReader reader = new CSVReader(new InputStreamReader(countriesFile, StandardCharsets.UTF_8))) { - while ((line = reader.readNext()) != null) { - Country country = new Country(); - country.setName(line[0]); - countries.put(country.getName(), country); - } - } catch (IOException | CsvValidationException exception) { - throw new IllegalStateException(exception.getMessage()); - } - } - - @Override public Airport get(final String pIcao) { - return airports.get(pIcao); + @Override + public Map getAirports() { + return airports; } } diff --git a/metarParser-spi/src/main/java/io/github/mivek/provider/airport/impl/OurAirportsAirportProvider.java b/metarParser-spi/src/main/java/io/github/mivek/provider/airport/impl/OurAirportsAirportProvider.java new file mode 100644 index 00000000..7de2b8ba --- /dev/null +++ b/metarParser-spi/src/main/java/io/github/mivek/provider/airport/impl/OurAirportsAirportProvider.java @@ -0,0 +1,106 @@ +package io.github.mivek.provider.airport.impl; + +import com.opencsv.CSVParser; +import com.opencsv.CSVReader; +import com.opencsv.CSVReaderBuilder; +import com.opencsv.exceptions.CsvValidationException; +import io.github.mivek.model.Airport; +import io.github.mivek.model.Country; +import io.github.mivek.provider.airport.AirportProvider; +import org.apache.commons.lang3.math.NumberUtils; + +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.net.URI; +import java.net.URISyntaxException; +import java.nio.charset.StandardCharsets; +import java.util.HashMap; +import java.util.Map; + +/** + * Implementation of the AirportProvider based on ourAirports. + * To use this provider make sure you are connected to internet. + * + * @author mivek + */ +public final class OurAirportsAirportProvider implements AirportProvider { + /** URI to retrieve the list of countries. */ + private static final String COUNTRIES_URI = "https://ourairports.com/data/countries.csv"; + /** URI to retrieve the list of airports. */ + private static final String AIRPORT_URI = "https://ourairports.com/data/airports.csv"; + /** Map of countries. */ + private Map countries; + /** Map of airports. */ + private Map airports; + + /** + * Default constructor. + * + * @throws CsvValidationException when the parsing of the file fails + * @throws IOException when network error + * @throws URISyntaxException when the URI is invalid + */ + public OurAirportsAirportProvider() throws CsvValidationException, IOException, URISyntaxException { + countries = new HashMap<>(); + airports = new HashMap<>(); + buildCountries(); + buildAirport(); + } + + /** + * Connects to the countries list and build a map of {@link Country} with the name as key. + * + * @throws CsvValidationException when the parsing of the file fails + * @throws IOException when network error + * @throws URISyntaxException when the URI is invalid + */ + public void buildCountries() throws URISyntaxException, IOException, CsvValidationException { + countries = new HashMap<>(); + URI countriesUri = new URI(COUNTRIES_URI); + try (InputStream countriesStream = countriesUri.toURL().openStream(); + CSVReader reader = new CSVReaderBuilder(new InputStreamReader(countriesStream, StandardCharsets.UTF_8)).withCSVParser(new CSVParser()).withSkipLines(1).build()) { + String[] line; + while ((line = reader.readNext()) != null) { + Country c = new Country(); + c.setName(line[2]); + countries.put(line[1], c); + } + } + } + + /** + * Connects to the airports list and build a map of {@link Airport} with the name as key. + * + * @throws CsvValidationException when the parsing of the file fails + * @throws IOException when network error + * @throws URISyntaxException when the URI is invalid + */ + public void buildAirport() throws URISyntaxException, IOException, CsvValidationException { + URI airportsURI = new URI(AIRPORT_URI); + airports = new HashMap<>(); + try (InputStream airportStream = airportsURI.toURL().openStream(); + CSVReader reader = new CSVReaderBuilder(new InputStreamReader(airportStream, StandardCharsets.UTF_8)).withCSVParser(new CSVParser()).withSkipLines(1).build()) { + String[] line; + + while ((line = reader.readNext()) != null) { + Airport airport = new Airport(); + airport.setIcao(line[1]); + airport.setName(line[3]); + airport.setLatitude(NumberUtils.toDouble(line[4], 0)); + airport.setLongitude(NumberUtils.toDouble(line[5], 0)); + airport.setAltitude(NumberUtils.toInt(line[6], 0)); + airport.setCountry(countries.get(line[8])); + airport.setCity(line[10]); + airport.setIata(line[13]); + airports.put(airport.getIcao(), airport); + } + } + } + + @Override + public Map getAirports() { + return airports; + } +} + diff --git a/metarParser-spi/src/main/java/io/github/mivek/provider/airport/impl/package-info.java b/metarParser-spi/src/main/java/io/github/mivek/provider/airport/impl/package-info.java new file mode 100644 index 00000000..cd858dd6 --- /dev/null +++ b/metarParser-spi/src/main/java/io/github/mivek/provider/airport/impl/package-info.java @@ -0,0 +1,6 @@ +/** + * Package containing implementation of the {@link io.github.mivek.provider.airport.AirportProvider}. + * + * @author mivek + */ +package io.github.mivek.provider.airport.impl; diff --git a/metarParser-spi/src/main/java/io/github/mivek/provider/airport/package-info.java b/metarParser-spi/src/main/java/io/github/mivek/provider/airport/package-info.java new file mode 100644 index 00000000..58df84e8 --- /dev/null +++ b/metarParser-spi/src/main/java/io/github/mivek/provider/airport/package-info.java @@ -0,0 +1,6 @@ +/** + * Contains The AirportProvider service. + * + * @author mivek + */ +package io.github.mivek.provider.airport; diff --git a/src/main/resources/data/airports.dat b/metarParser-spi/src/main/resources/data/airports.dat similarity index 100% rename from src/main/resources/data/airports.dat rename to metarParser-spi/src/main/resources/data/airports.dat diff --git a/src/main/resources/data/countries.dat b/metarParser-spi/src/main/resources/data/countries.dat similarity index 100% rename from src/main/resources/data/countries.dat rename to metarParser-spi/src/main/resources/data/countries.dat diff --git a/metarParser-spi/src/test/java/io/github/mivek/provider/airport/impl/AirportProviderArchitectureTest.java b/metarParser-spi/src/test/java/io/github/mivek/provider/airport/impl/AirportProviderArchitectureTest.java new file mode 100644 index 00000000..fd88b6cc --- /dev/null +++ b/metarParser-spi/src/test/java/io/github/mivek/provider/airport/impl/AirportProviderArchitectureTest.java @@ -0,0 +1,23 @@ +package io.github.mivek.provider.airport.impl; + +import com.tngtech.archunit.core.importer.ImportOption; +import com.tngtech.archunit.junit.AnalyzeClasses; +import com.tngtech.archunit.junit.ArchTest; +import com.tngtech.archunit.junit.ArchUnitRunner; +import com.tngtech.archunit.lang.ArchRule; +import io.github.mivek.provider.airport.AirportProvider; +import org.junit.runner.RunWith; + +import static com.tngtech.archunit.lang.syntax.ArchRuleDefinition.classes; + +/** + * @author mivek + */ +@RunWith(ArchUnitRunner.class) +@AnalyzeClasses(packages = { "io.github.mivek.provider.airport.impl" }, importOptions = { ImportOption.DoNotIncludeTests.class }) +public class AirportProviderArchitectureTest { + + @ArchTest + public static final ArchRule implRule = classes().should().implement(AirportProvider.class); +} + diff --git a/metarParser-spi/src/test/java/io/github/mivek/provider/airport/impl/DefaultAirportProviderTest.java b/metarParser-spi/src/test/java/io/github/mivek/provider/airport/impl/DefaultAirportProviderTest.java new file mode 100644 index 00000000..eec0d161 --- /dev/null +++ b/metarParser-spi/src/test/java/io/github/mivek/provider/airport/impl/DefaultAirportProviderTest.java @@ -0,0 +1,28 @@ +package io.github.mivek.provider.airport.impl; + +import io.github.mivek.model.Airport; +import io.github.mivek.provider.airport.AirportProvider; +import org.junit.Test; + +import java.util.Map; + +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.*; +import static org.junit.Assert.assertNotNull; + +/** + * @author mivek + */ +public class DefaultAirportProviderTest { + + @Test + public void testGetAirport() { + AirportProvider provider = new DefaultAirportProvider(); + + Map airports = provider.getAirports(); + + assertThat(airports, not(anEmptyMap())); + assertThat(airports, hasKey("LFPG")); + assertNotNull(airports.get("LFPG")); + } +} diff --git a/metarParser-spi/src/test/java/io/github/mivek/provider/airport/impl/OurAirportsAirportProviderTest.java b/metarParser-spi/src/test/java/io/github/mivek/provider/airport/impl/OurAirportsAirportProviderTest.java new file mode 100644 index 00000000..41953a00 --- /dev/null +++ b/metarParser-spi/src/test/java/io/github/mivek/provider/airport/impl/OurAirportsAirportProviderTest.java @@ -0,0 +1,31 @@ +package io.github.mivek.provider.airport.impl; + +import com.opencsv.exceptions.CsvValidationException; +import io.github.mivek.model.Airport; +import io.github.mivek.provider.airport.AirportProvider; +import org.junit.Test; + +import java.io.IOException; +import java.net.URISyntaxException; +import java.util.Map; + +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.*; +import static org.junit.Assert.*; + +/** + * @author mivek + */ +public class OurAirportsAirportProviderTest { + + @Test + public void testGetAirport() throws CsvValidationException, IOException, URISyntaxException { + AirportProvider provider = new OurAirportsAirportProvider(); + + Map airports = provider.getAirports(); + + assertThat(airports, not(anEmptyMap())); + assertThat(airports, hasKey("LFPG")); + assertNotNull(airports.get("LFPG")); + } +} diff --git a/model.ucls b/model.ucls deleted file mode 100644 index 2f0680e2..00000000 --- a/model.ucls +++ /dev/null @@ -1,412 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/pom.xml b/pom.xml index f3037d42..d824a3aa 100644 --- a/pom.xml +++ b/pom.xml @@ -4,10 +4,21 @@ io.github.mivek metarParser 1.10.5 + pom metarParser This project is a metar parser. Use the MetarFacade and its method "parse()" to parse a metar string and retrieve a Metar Object. + + + metarParser-commons + metarParser-entities + metarParser-spi + metarParser-parsers + metarParser-services + + + https://github.com/mivek/MetarParser https://github.com/mivek/MetarParser/tree/master @@ -39,7 +50,17 @@ 1.6 UTF-8 4.13 - 1.5.1 + 2.2 + 0.7.6 + 3.8.1 + 4.0.0 + 3.9 + 5.1 + 1.3.7 + 0.98 + 0.96 + 0.97 + 0.13.1 @@ -50,23 +71,33 @@ - - - jcenter - http://jcenter.bintray.com/ - - + + + + com.opencsv + opencsv + ${opencsv.version} + + + org.apache.commons + commons-lang3 + ${commons-lang3.version} + + + pl.pojo + pojo-tester + ${pojo-tester.version} + test + + + + - - com.opencsv - opencsv - 5.1 - org.hamcrest - hamcrest-all - 1.3 + hamcrest + ${hamcrest.version} test @@ -76,13 +107,12 @@ test - pl.pojo - pojo-tester - 0.7.6 + com.tngtech.archunit + archunit-junit4 + ${archunit-junit4.version} test - src/main/java install @@ -92,12 +122,12 @@ org.apache.maven.plugins maven-compiler-plugin - 3.8.1 + ${maven-compiler-plugin.version} com.github.spotbugs spotbugs-maven-plugin - 4.0.0 + ${spotbugs-maven-plugin.version} @@ -113,19 +143,30 @@ 3.0.0-M4 - org.pitest - pitest-maven - ${pitest-maven.version} + eu.stamp-project + pitmp-maven-plugin + ${pitmp-maven-plugin.version} - mutationCoverage + run + 3 + + metarParser-parsers + 98 99 + + io.github.mivek.model.* + io.github.mivek.provider.* + io.github.mivek.enums.* + io.github.mivek.internationalization.* + io.github.mivek.parser.* + io.github.mivek.command.* @@ -161,17 +202,17 @@ INSTRUCTION COVEREDRATIO - 0.98 + ${jacoco.coverage.instruction.minimum} BRANCH COVEREDRATIO - 0.96 + ${jacoco.coverage.branch.minimum} COMPLEXITY COVEREDRATIO - 0.97 + ${jacoco.coverage.complexity.minimum} @@ -180,9 +221,32 @@ + + org.apache.maven.plugins + maven-checkstyle-plugin + 3.1.1 + + *Test.java + checkstyle.xml + UTF-8 + true + true + false + + + + validate + validate + + check + + + + + release diff --git a/src/main/java/io/github/mivek/command/common/BaseWindCommand.java b/src/main/java/io/github/mivek/command/common/BaseWindCommand.java deleted file mode 100644 index 017a650a..00000000 --- a/src/main/java/io/github/mivek/command/common/BaseWindCommand.java +++ /dev/null @@ -1,37 +0,0 @@ -package io.github.mivek.command.common; - -import io.github.mivek.internationalization.Messages; -import io.github.mivek.model.Wind; -import io.github.mivek.utils.Converter; - -/** - * @author mivek - */ -public interface BaseWindCommand extends Command { - - /** - * Sets the elements of the wind. - * - * @param pWind the wind element. - * @param pDirection the direction of the wind in degrees. - * @param pSpeed the speed of the wind - * @param pGust the speed of the gust if any - * @param pUnit the unit. - */ - default void setWindElements(final Wind pWind, final String pDirection, final String pSpeed, final String pGust, final String pUnit) { - String direction = Converter.degreesToDirection(pDirection); - pWind.setDirection(direction); - if (!direction.equals(Messages.getInstance().getString("Converter.VRB"))) { - pWind.setDirectionDegrees(Integer.parseInt(pDirection)); - } - pWind.setSpeed(Integer.parseInt(pSpeed)); - if (pGust != null) { - pWind.setGust(Integer.parseInt(pGust)); - } - if (pUnit == null) { - pWind.setUnit("KT"); - } else { - pWind.setUnit(pUnit); - } - } -} diff --git a/src/main/java/io/github/mivek/command/common/WindExtremeCommand.java b/src/main/java/io/github/mivek/command/common/WindExtremeCommand.java deleted file mode 100644 index 5ca2cd7e..00000000 --- a/src/main/java/io/github/mivek/command/common/WindExtremeCommand.java +++ /dev/null @@ -1,36 +0,0 @@ -package io.github.mivek.command.common; - -import io.github.mivek.model.AbstractWeatherContainer; -import io.github.mivek.model.Wind; -import io.github.mivek.utils.Regex; - -import java.util.regex.Pattern; - -/** - * @author mivek - */ -public final class WindExtremeCommand implements Command { - /** Pattern regex for extreme winds. */ - private static final Pattern WIND_EXTREME_REGEX = Pattern.compile("^(\\d{3})V(\\d{3})"); - - @Override public boolean execute(final AbstractWeatherContainer pContainer, final String pPart) { - parseExtremeWind(pContainer.getWind(), pPart); - return getReturnValue(); - } - - /** - * Parses the wind. - * - * @param pWind the wind to update - * @param pExtremeWind String with extreme wind information - */ - protected void parseExtremeWind(final Wind pWind, final String pExtremeWind) { - String[] matches = Regex.pregMatch(WIND_EXTREME_REGEX, pExtremeWind); - pWind.setExtreme1(Integer.parseInt(matches[1])); - pWind.setExtreme2(Integer.parseInt(matches[2])); - } - - @Override public boolean canParse(final String pInput) { - return Regex.find(WIND_EXTREME_REGEX, pInput); - } -} diff --git a/src/main/java/io/github/mivek/command/metar/AltimeterCommand.java b/src/main/java/io/github/mivek/command/metar/AltimeterCommand.java deleted file mode 100644 index 0cd30f23..00000000 --- a/src/main/java/io/github/mivek/command/metar/AltimeterCommand.java +++ /dev/null @@ -1,24 +0,0 @@ -package io.github.mivek.command.metar; - -import io.github.mivek.model.Metar; -import io.github.mivek.utils.Regex; - -import java.util.regex.Pattern; - -/** - * @author mivek - */ -public final class AltimeterCommand implements Command { - - /** Pattern of the altimeter (Pascals). */ - private static final Pattern ALTIMETER_REGEX = Pattern.compile("^Q(\\d{4})$"); - - @Override public void execute(final Metar pMetar, final String pPart) { - String[] matches = Regex.pregMatch(ALTIMETER_REGEX, pPart); - pMetar.setAltimeter(Integer.parseInt(matches[1])); - } - - @Override public boolean canParse(final String pInput) { - return Regex.find(ALTIMETER_REGEX, pInput); - } -} diff --git a/src/main/java/io/github/mivek/command/metar/TemperatureCommand.java b/src/main/java/io/github/mivek/command/metar/TemperatureCommand.java deleted file mode 100644 index 0522e887..00000000 --- a/src/main/java/io/github/mivek/command/metar/TemperatureCommand.java +++ /dev/null @@ -1,25 +0,0 @@ -package io.github.mivek.command.metar; - -import io.github.mivek.model.Metar; -import io.github.mivek.utils.Converter; -import io.github.mivek.utils.Regex; - -import java.util.regex.Pattern; - -/** - * @author mivek - */ -public final class TemperatureCommand implements Command { - /** Pattern of the temperature block. */ - private static final Pattern TEMPERATURE_REGEX = Pattern.compile("^(M?\\d{2})/(M?\\d{2})$"); - - @Override public void execute(final Metar pMetar, final String pPart) { - String[] matches = Regex.pregMatch(TEMPERATURE_REGEX, pPart); - pMetar.setTemperature(Converter.convertTemperature(matches[1])); - pMetar.setDewPoint(Converter.convertTemperature(matches[2])); - } - - @Override public boolean canParse(final String pInput) { - return Regex.find(TEMPERATURE_REGEX, pInput); - } -} diff --git a/src/main/java/io/github/mivek/command/remark/Command.java b/src/main/java/io/github/mivek/command/remark/Command.java deleted file mode 100644 index ce74de54..00000000 --- a/src/main/java/io/github/mivek/command/remark/Command.java +++ /dev/null @@ -1,33 +0,0 @@ -package io.github.mivek.command.remark; - -/** - * @author mivek - */ -public interface Command { - - /** - * @param pRemark the remark to parse. - * @param pStringBuilder the string builder containing the decoded remark - * @return the remark without the parsed part - */ - String execute(String pRemark, StringBuilder pStringBuilder); - - /** - * Checks if the string is null. - * - * @param pString the string to test - * @return empty string if null pString otherwise. - */ - default String verifyString(final String pString) { - if (pString == null) { - return ""; - } - return pString; - } - - /** - * @param pInput the input string to test. - * @return true if the input can be handled by the command. - */ - boolean canParse(String pInput); -} diff --git a/src/main/java/io/github/mivek/command/remark/HailSizeCommand.java b/src/main/java/io/github/mivek/command/remark/HailSizeCommand.java deleted file mode 100644 index 0f68ab12..00000000 --- a/src/main/java/io/github/mivek/command/remark/HailSizeCommand.java +++ /dev/null @@ -1,34 +0,0 @@ -package io.github.mivek.command.remark; - -import io.github.mivek.internationalization.Messages; -import io.github.mivek.utils.Regex; - -import java.util.regex.Pattern; - -/** - * @author mivek - */ -public final class HailSizeCommand implements Command { - /** Hail size. */ - private static final Pattern HAIL_SIZE = Pattern.compile("^GR ((\\d/\\d)|((\\d) ?(\\d/\\d)?))"); - - /** The message instance. */ - private final Messages fMessages; - - /** - * Default constructor. - */ - HailSizeCommand() { - fMessages = Messages.getInstance(); - } - - @Override public String execute(final String pRemark, final StringBuilder pStringBuilder) { - String[] hailParts = Regex.pregMatch(HAIL_SIZE, pRemark); - pStringBuilder.append(fMessages.getString("Remark.Hail", hailParts[1])).append(" "); - return pRemark.replaceFirst(HAIL_SIZE.pattern(), "").trim(); - } - - @Override public boolean canParse(final String pInput) { - return Regex.find(HAIL_SIZE, pInput); - } -} diff --git a/src/main/java/io/github/mivek/command/remark/ObscurationCommand.java b/src/main/java/io/github/mivek/command/remark/ObscurationCommand.java deleted file mode 100644 index 3b9778ed..00000000 --- a/src/main/java/io/github/mivek/command/remark/ObscurationCommand.java +++ /dev/null @@ -1,37 +0,0 @@ -package io.github.mivek.command.remark; - -import io.github.mivek.internationalization.Messages; -import io.github.mivek.utils.Regex; - -import java.util.regex.Pattern; - -/** - * @author mivek - */ -public final class ObscurationCommand implements Command { - /** Obscuration pattern. */ - private static final Pattern OBSCURATION = Pattern.compile("^([A-Z]{2}) ([A-Z]{3})(\\d{3})"); - - /** The message instance. */ - private final Messages fMessages; - - /** - * Default constructor. - */ - ObscurationCommand() { - fMessages = Messages.getInstance(); - } - - @Override public String execute(final String pRemark, final StringBuilder pStringBuilder) { - String[] obscuration = Regex.pregMatch(OBSCURATION, pRemark); - String layer = fMessages.getString("CloudQuantity." + obscuration[2]); - int height = Integer.parseInt(obscuration[3]) * 100; - String obscDetail = fMessages.getString("Phenomenon." + obscuration[1]); - pStringBuilder.append(fMessages.getString("Remark.Obscuration", layer, height, obscDetail)).append(" "); - return pRemark.replaceFirst(OBSCURATION.pattern(), "").trim(); - } - - @Override public boolean canParse(final String pInput) { - return Regex.find(OBSCURATION, pInput); - } -} diff --git a/src/main/java/io/github/mivek/command/remark/PrecipitationBegEndCommand.java b/src/main/java/io/github/mivek/command/remark/PrecipitationBegEndCommand.java deleted file mode 100644 index d4af3179..00000000 --- a/src/main/java/io/github/mivek/command/remark/PrecipitationBegEndCommand.java +++ /dev/null @@ -1,36 +0,0 @@ -package io.github.mivek.command.remark; - -import io.github.mivek.internationalization.Messages; -import io.github.mivek.utils.Regex; - -import java.util.regex.Pattern; - -/** - * @author mivek - */ -public final class PrecipitationBegEndCommand implements Command { - /** Beginning and ending of precipitation. */ - private static final Pattern PRECIPITATION_BEG_END = Pattern.compile("^(([A-Z]{2})?([A-Z]{2})B(\\d{2})?(\\d{2})E(\\d{2})?(\\d{2}))"); - - /** The message instance. */ - private final Messages fMessages; - - /** - * Default constructor. - */ - PrecipitationBegEndCommand() { - fMessages = Messages.getInstance(); - } - - @Override public String execute(final String pRemark, final StringBuilder pStringBuilder) { - String[] precipitationBegEnd = Regex.pregMatch(PRECIPITATION_BEG_END, pRemark); - pStringBuilder.append(fMessages.getString("Remark.Precipitation.Beg.End", precipitationBegEnd[2] == null ? "" : fMessages.getString("Descriptive." + precipitationBegEnd[2]), - fMessages.getString("Phenomenon." + precipitationBegEnd[3]), verifyString(precipitationBegEnd[4]), precipitationBegEnd[5], verifyString(precipitationBegEnd[6]), - precipitationBegEnd[7])).append(" "); - return pRemark.replaceFirst(PRECIPITATION_BEG_END.pattern(), "").trim(); - } - - @Override public boolean canParse(final String pInput) { - return Regex.find(PRECIPITATION_BEG_END, pInput); - } -} diff --git a/src/main/java/io/github/mivek/command/remark/TornadicActivityBegEndCommand.java b/src/main/java/io/github/mivek/command/remark/TornadicActivityBegEndCommand.java deleted file mode 100644 index 8bf45f60..00000000 --- a/src/main/java/io/github/mivek/command/remark/TornadicActivityBegEndCommand.java +++ /dev/null @@ -1,36 +0,0 @@ -package io.github.mivek.command.remark; - -import io.github.mivek.internationalization.Messages; -import io.github.mivek.utils.Regex; - -import java.util.regex.Pattern; - -/** - * @author mivek - */ -public final class TornadicActivityBegEndCommand implements Command { - /** Tornadic activity with beginning and ending time. */ - private static final Pattern TORNADIC_ACTIVITY_BEG_END = Pattern.compile("^(TORNADO|FUNNEL CLOUD|WATERSPOUT) (B(\\d{2})?(\\d{2}))(E(\\d{2})?(\\d{2}))( (\\d+)? ([A-Z]{1,2})?)?"); - - /** The message instance. */ - private final Messages fMessages; - - /** - * Default constructor. - */ - TornadicActivityBegEndCommand() { - fMessages = Messages.getInstance(); - } - - @Override public String execute(final String pRemark, final StringBuilder pStringBuilder) { - String[] tornadicParts = Regex.pregMatch(TORNADIC_ACTIVITY_BEG_END, pRemark); - pStringBuilder.append(fMessages - .getString("Remark.Tornadic.Activity.BegEnd", fMessages.getString("Remark." + tornadicParts[1].replace(" ", "")), verifyString(tornadicParts[3]), tornadicParts[4], - verifyString(tornadicParts[6]), tornadicParts[7], tornadicParts[9], fMessages.getString("Converter." + tornadicParts[10]))).append(" "); - return pRemark.replaceFirst(TORNADIC_ACTIVITY_BEG_END.pattern(), "").trim(); - } - - @Override public boolean canParse(final String pInput) { - return Regex.find(TORNADIC_ACTIVITY_BEG_END, pInput); - } -} diff --git a/src/main/java/io/github/mivek/command/remark/TornadicActivityEndCommand.java b/src/main/java/io/github/mivek/command/remark/TornadicActivityEndCommand.java deleted file mode 100644 index 7d988442..00000000 --- a/src/main/java/io/github/mivek/command/remark/TornadicActivityEndCommand.java +++ /dev/null @@ -1,36 +0,0 @@ -package io.github.mivek.command.remark; - -import io.github.mivek.internationalization.Messages; -import io.github.mivek.utils.Regex; - -import java.util.regex.Pattern; - -/** - * @author mivek - */ -public final class TornadicActivityEndCommand implements Command { - /** Tornadic activity with ending time. */ - private static final Pattern TORNADIC_ACTIVITY_ENDING = Pattern.compile("^(TORNADO|FUNNEL CLOUD|WATERSPOUT) (E(\\d{2})?(\\d{2}))( (\\d+)? ([A-Z]{1,2})?)?"); - - /** The message instance. */ - private final Messages fMessages; - - /** - * Default constructor. - */ - TornadicActivityEndCommand() { - fMessages = Messages.getInstance(); - } - - @Override public String execute(final String pRemark, final StringBuilder pStringBuilder) { - String[] tornadicParts = Regex.pregMatch(TORNADIC_ACTIVITY_ENDING, pRemark); - pStringBuilder.append(fMessages - .getString("Remark.Tornadic.Activity.Ending", fMessages.getString("Remark." + tornadicParts[1].replace(" ", "")), verifyString(tornadicParts[3]), tornadicParts[4], tornadicParts[6], - fMessages.getString("Converter." + tornadicParts[7]))).append(" "); - return pRemark.replaceFirst(TORNADIC_ACTIVITY_ENDING.pattern(), "").trim(); - } - - @Override public boolean canParse(final String pInput) { - return Regex.find(TORNADIC_ACTIVITY_ENDING, pInput); - } -} diff --git a/src/main/java/io/github/mivek/command/remark/VariableSkyCommand.java b/src/main/java/io/github/mivek/command/remark/VariableSkyCommand.java deleted file mode 100644 index c67c391a..00000000 --- a/src/main/java/io/github/mivek/command/remark/VariableSkyCommand.java +++ /dev/null @@ -1,37 +0,0 @@ -package io.github.mivek.command.remark; - -import io.github.mivek.internationalization.Messages; -import io.github.mivek.utils.Regex; - -import java.util.regex.Pattern; - -/** - * @author mivek - */ -public final class VariableSkyCommand implements Command { - /** Variable sky condition. */ - private static final Pattern VARIABLE_SKY = Pattern.compile("^([A-Z]{3}) V ([A-Z]{3})"); - - /** The messages instance. */ - private Messages fMessages; - - /** - * Default constructor. - */ - VariableSkyCommand() { - fMessages = Messages.getInstance(); - } - - @Override public String execute(final String pRemark, final StringBuilder pStringBuilder) { - String[] variableSky = Regex.pregMatch(VARIABLE_SKY, pRemark); - String layer1 = fMessages.getString("CloudQuantity." + variableSky[1]); - String layer2 = fMessages.getString("CloudQuantity." + variableSky[2]); - pStringBuilder.append(fMessages.getString("Remark.Variable.Sky.Condition", layer1, layer2)).append(" "); - return pRemark.replaceFirst(VARIABLE_SKY.pattern(), "").trim(); - } - - @Override public boolean canParse(final String pInput) { - return Regex.find(VARIABLE_SKY, pInput); - } -} - diff --git a/src/main/java/io/github/mivek/command/remark/VariableSkyHeightCommand.java b/src/main/java/io/github/mivek/command/remark/VariableSkyHeightCommand.java deleted file mode 100644 index 641fde8a..00000000 --- a/src/main/java/io/github/mivek/command/remark/VariableSkyHeightCommand.java +++ /dev/null @@ -1,37 +0,0 @@ -package io.github.mivek.command.remark; - -import io.github.mivek.internationalization.Messages; -import io.github.mivek.utils.Regex; - -import java.util.regex.Pattern; - -/** - * @author mivek - */ -public final class VariableSkyHeightCommand implements Command { - /** Variable sky condition with height. */ - private static final Pattern VARIABLE_SKY_HEIGHT = Pattern.compile("^([A-Z]{3})(\\d{3}) V ([A-Z]{3})"); - - /** The message instance. */ - private final Messages fMessages; - - /** - * Default constructor. - */ - VariableSkyHeightCommand() { - fMessages = Messages.getInstance(); - } - - @Override public String execute(final String pRemark, final StringBuilder pStringBuilder) { - String[] variableSky = Regex.pregMatch(VARIABLE_SKY_HEIGHT, pRemark); - String layer1 = fMessages.getString("CloudQuantity." + variableSky[1]); - int height = Integer.parseInt(variableSky[2]) * 100; - String layer2 = fMessages.getString("CloudQuantity." + variableSky[3]); - pStringBuilder.append(fMessages.getString("Remark.Variable.Sky.Condition.Height", height, layer1, layer2)).append(" "); - return pRemark.replaceFirst(VARIABLE_SKY_HEIGHT.pattern(), "").trim(); - } - - @Override public boolean canParse(final String pInput) { - return Regex.find(VARIABLE_SKY_HEIGHT, pInput); - } -} diff --git a/src/main/java/io/github/mivek/command/remark/WindPeakCommand.java b/src/main/java/io/github/mivek/command/remark/WindPeakCommand.java deleted file mode 100644 index 8f9b4b23..00000000 --- a/src/main/java/io/github/mivek/command/remark/WindPeakCommand.java +++ /dev/null @@ -1,36 +0,0 @@ -package io.github.mivek.command.remark; - -import io.github.mivek.internationalization.Messages; -import io.github.mivek.utils.Regex; - -import java.util.regex.Pattern; - -/** - * @author mivek - */ -public final class WindPeakCommand implements Command { - - /** Wind peak pattern. */ - private static final Pattern WIND_PEAK = Pattern.compile("^PK WND (\\d{3})(\\d{2,3})/(\\d{2})?(\\d{2})"); - - /** The messages instance. */ - private final Messages fMessages; - - /** - * Default constructor. - */ - WindPeakCommand() { - fMessages = Messages.getInstance(); - } - - @Override public String execute(final String pRemark, final StringBuilder pStringBuilder) { - String[] windPeakParts = Regex.pregMatch(WIND_PEAK, pRemark); - pStringBuilder.append(fMessages.getString("Remark.PeakWind", windPeakParts[1], windPeakParts[2], verifyString(windPeakParts[3]), windPeakParts[4])); - pStringBuilder.append(" "); - return pRemark.replaceFirst(WIND_PEAK.pattern(), "").trim(); - } - - @Override public boolean canParse(final String pInput) { - return Regex.find(WIND_PEAK, pInput); - } -} diff --git a/src/main/java/io/github/mivek/command/remark/WindShiftCommand.java b/src/main/java/io/github/mivek/command/remark/WindShiftCommand.java deleted file mode 100644 index 6b2503c8..00000000 --- a/src/main/java/io/github/mivek/command/remark/WindShiftCommand.java +++ /dev/null @@ -1,36 +0,0 @@ -package io.github.mivek.command.remark; - -import io.github.mivek.internationalization.Messages; -import io.github.mivek.utils.Regex; - -import java.util.regex.Pattern; - -/** - * @author mivek - */ -public final class WindShiftCommand implements Command { - - /** Wind shift pattern. */ - private static final Pattern WIND_SHIFT = Pattern.compile("^WSHFT (\\d{2})?(\\d{2})"); - - /** The messages instance. */ - private final Messages fMessages; - - /** - * Default constructor. - */ - WindShiftCommand() { - fMessages = Messages.getInstance(); - } - - @Override public String execute(final String pRemark, final StringBuilder pStringBuilder) { - String[] windShiftParts = Regex.pregMatch(WIND_SHIFT, pRemark); - pStringBuilder.append(fMessages.getString("Remark.WindShift", verifyString(windShiftParts[1]), windShiftParts[2])); - pStringBuilder.append(" "); - return pRemark.replaceFirst(WIND_SHIFT.pattern(), "").trim(); - } - - @Override public boolean canParse(final String pInput) { - return Regex.find(WIND_SHIFT, pInput); - } -} diff --git a/src/main/java/io/github/mivek/facade/package-info.java b/src/main/java/io/github/mivek/facade/package-info.java deleted file mode 100644 index 96f53120..00000000 --- a/src/main/java/io/github/mivek/facade/package-info.java +++ /dev/null @@ -1,6 +0,0 @@ -/** - * Contains the facades of the application. - * - * @author mivek - */ -package io.github.mivek.facade; diff --git a/src/test/java/io/github/mivek/facade/AbstractWeatherCodeFacadeTest.java b/src/test/java/io/github/mivek/facade/AbstractWeatherCodeFacadeTest.java deleted file mode 100644 index 5cf34486..00000000 --- a/src/test/java/io/github/mivek/facade/AbstractWeatherCodeFacadeTest.java +++ /dev/null @@ -1,42 +0,0 @@ -package io.github.mivek.facade; - -import static org.hamcrest.Matchers.hasProperty; -import static org.hamcrest.Matchers.is; -import static org.hamcrest.Matchers.notNullValue; -import static org.junit.Assert.assertThat; - -import java.io.IOException; -import java.net.URISyntaxException; - -import org.junit.Ignore; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.ExpectedException; - -import io.github.mivek.exception.ErrorCodes; -import io.github.mivek.exception.ParseException; -import io.github.mivek.model.AbstractWeatherCode; - -@Ignore -public abstract class AbstractWeatherCodeFacadeTest { - @Rule - public ExpectedException thrown = ExpectedException.none(); - - protected abstract AbstractWeatherCodeFacade getSut(); - - - @Test - public void testRetrieveFromAirportInvalid() throws Exception { - thrown.expect(ParseException.class); - thrown.expect(hasProperty("errorCode", is(ErrorCodes.ERROR_CODE_INVALID_ICAO))); - getSut().retrieveFromAirport("RAndomeString"); - } - - @Test - public void testRetrieveFromAirport() throws IOException, ParseException, URISyntaxException { - T res = getSut().retrieveFromAirport("LFPG"); - assertThat(res, notNullValue()); - assertThat(res.getAirport().getIcao(), is("LFPG")); - } - -} diff --git a/src/test/java/io/github/mivek/facade/TAFFacadeTest.java b/src/test/java/io/github/mivek/facade/TAFFacadeTest.java deleted file mode 100644 index 3ffa93ce..00000000 --- a/src/test/java/io/github/mivek/facade/TAFFacadeTest.java +++ /dev/null @@ -1,74 +0,0 @@ -package io.github.mivek.facade; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; - -import org.junit.Test; - -import io.github.mivek.exception.ParseException; -import io.github.mivek.model.TAF; - -public class TAFFacadeTest extends AbstractWeatherCodeFacadeTest { - - private TAFFacade sut = TAFFacade.getInstance(); - - @Override - protected AbstractWeatherCodeFacade getSut() { - return sut; - } - - @Test - public void testFormatWithAMD() throws ParseException { - // Given a taf message with AMD on second line. - String message = "TAF \n" + - "AMD LFPG 100910Z 1009/1112 20015G25KT 9999 BKN035 \n" + - "TEMPO 1011/1019 26020G35KT 4000 SHRA BKN012TCU PROB30 \n" + - "TEMPO 1015/1019 27025G45KT 2500 TSRAGS SCT012CB \n" + - "BECMG 1021/1024 27010KT PROB30 \n" + - "TEMPO 1105/1107 BKN014 \n" + - "BECMG 1109/1111 34010KT"; - - String formatedString = "TAF AMD LFPG 100910Z 1009/1112 20015G25KT 9999 BKN035 \n" + "TEMPO 1011/1019 26020G35KT 4000 SHRA BKN012TCU PROB30 \n" - + "TEMPO 1015/1019 27025G45KT 2500 TSRAGS SCT012CB \n" + "BECMG 1021/1024 27010KT PROB30 \n" + "TEMPO 1105/1107 BKN014 \n" + "BECMG 1109/1111 34010KT\n"; - - // When formating the message - String result = sut.format(message); - // Then the 2 first lines are merged. - assertNotNull(result); - assertEquals(formatedString, result); - } - - @Test - public void testFormatWithoutReformat() throws ParseException { - // GIVEN a taf with a full first line ie the first line is not only work "TAF" - String message = "TAF LFPG 121700Z 1218/1324 13003KT CAVOK TX09/1315Z TN00/1306Z \n" + "TEMPO 1303/1308 4000 BR"; - // WHEN formating the message - String result = sut.format(message); - // THEN the message is not edited. - assertEquals(message, result); - } - - @Test - public void testFormat() throws ParseException { - String tafMessage = "TAF \n" + - "AMD TAF \n" + - "AMD LFPG 241332Z 2413/2518 01008KT 7000 BKN015 TX13/2414Z TN03/2505Z \n" + - "BECMG 2413/2415 BKN040 \n" + - "BECMG 2415/2417 CAVOK \n" + - "BECMG 2509/2511 BKN030 \n" + - "TEMPO 2514/2516 36015G25KT \n" + - "BECMG 2516/2518 CAVOK"; - - String formatted = "TAF AMD LFPG 241332Z 2413/2518 01008KT 7000 BKN015 TX13/2414Z TN03/2505Z \n" + - "BECMG 2413/2415 BKN040 \n" + - "BECMG 2415/2417 CAVOK \n" + - "BECMG 2509/2511 BKN030 \n" + - "TEMPO 2514/2516 36015G25KT \n" + - "BECMG 2516/2518 CAVOK\n"; - // When formating the message - String result = sut.format(tafMessage); - // Then the 2 first lines are merged. - assertNotNull(result); - assertEquals(formatted, result); - } -} diff --git a/src/test/java/io/github/mivek/model/AbstractWeatherContainerTest.java b/src/test/java/io/github/mivek/model/AbstractWeatherContainerTest.java deleted file mode 100644 index 7db74aa0..00000000 --- a/src/test/java/io/github/mivek/model/AbstractWeatherContainerTest.java +++ /dev/null @@ -1,41 +0,0 @@ -/** - * - */ -package io.github.mivek.model; - -import org.junit.Test; - -import static org.hamcrest.Matchers.empty; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertThat; - -/** - * Test class for {@link AbstractWeatherContainer}. - * @author mivek - */ -public class AbstractWeatherContainerTest { - - @Test - public void testAddWeatherConditionWithNull() { - Metar m = new Metar(); - m.addWeatherCondition(null); - assertThat(m.getWeatherConditions(), empty()); - } - - @Test - public void testAddCloudWithNull() { - Metar m = new Metar(); - m.addCloud(null); - assertThat(m.getClouds(), empty()); - } - - @Test - public void testGetVerticalVisibility() { - //GIVEN a metar object with a null vertical visibility - Metar m = new Metar(); - //WHEN retrieving the vertical visibility - Integer result = m.getVerticalVisibility(); - //THEN the result is null, not a null pointer expection - assertNull(result); - } -} diff --git a/src/test/java/io/github/mivek/model/CloudTest.java b/src/test/java/io/github/mivek/model/CloudTest.java deleted file mode 100644 index bd024098..00000000 --- a/src/test/java/io/github/mivek/model/CloudTest.java +++ /dev/null @@ -1,61 +0,0 @@ -package io.github.mivek.model; - -import io.github.mivek.enums.CloudQuantity; -import io.github.mivek.enums.CloudType; -import io.github.mivek.internationalization.Messages; -import org.hamcrest.Matchers; -import org.junit.Test; -import pl.pojo.tester.api.assertion.Method; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertThat; -import static pl.pojo.tester.api.assertion.Assertions.assertPojoMethodsFor; - -public class CloudTest { - @Test - public void testSetAltitudeGetAltitude() { - Cloud c = new Cloud(); - c.setAltitude(90); - assertEquals(90, c.getAltitude()); - } - - @Test - public void testSetAltitudeGetHeight() { - Cloud c = new Cloud(); - c.setAltitude(90); - assertEquals(300, c.getHeight()); - } - - @Test - public void testSetHeightGetAltitude() { - Cloud c = new Cloud(); - c.setHeight(300); - assertEquals(90, c.getAltitude()); - } - - @Test - public void testSetHeightGetHeight() { - Cloud c = new Cloud(); - c.setHeight(300); - assertEquals(300, c.getHeight()); - } - - @Test - public void testToString() { - Cloud c = new Cloud(); - c.setAltitude(90); - c.setQuantity(CloudQuantity.BKN); - c.setType(CloudType.CB); - assertThat(c.toString(), Matchers.containsString(Messages.getInstance().getString("ToString.type") + "=" + CloudType.CB.toString())); - assertThat(c.toString(), Matchers.containsString(Messages.getInstance().getString("ToString.quantity") + "=" + CloudQuantity.BKN.toString())); - assertThat(c.toString(), Matchers.containsString(Messages.getInstance().getString("ToString.height.feet") + "=300")); - assertThat(c.toString(), Matchers.containsString(Messages.getInstance().getString("ToString.height.meter") + "=90")); - } - - @Test public void testPojo() { - // given - final Class classUnderTest = Cloud.class; - // then - assertPojoMethodsFor(classUnderTest).testing(Method.GETTER, Method.SETTER).areWellImplemented(); - } -} diff --git a/trend.ucls b/trend.ucls deleted file mode 100644 index 2682fb51..00000000 --- a/trend.ucls +++ /dev/null @@ -1,186 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file