Skip to content

Commit

Permalink
Merge pull request #189 from mivek/feature/NullableAirport
Browse files Browse the repository at this point in the history
Feature/nullable airport
  • Loading branch information
mivek authored Feb 20, 2020
2 parents 16ef49d + a31f877 commit ccb01f9
Show file tree
Hide file tree
Showing 11 changed files with 388 additions and 226 deletions.
6 changes: 4 additions & 2 deletions checkstyle.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ Checkstyle configuration that checks the sun coding conventions.
<module name="MethodName"/>
<module name="PackageName"/>
<module name="ParameterName">
<property name="format" value="^p[A-Z][a-zA-Z0-9]*$"/>
<property name="accessModifiers" value="public"/>
</module>
<module name="StaticVariableName"/>
Expand Down Expand Up @@ -55,7 +54,10 @@ Checkstyle configuration that checks the sun coding conventions.
</module>
<module name="EmptyStatement"/>
<module name="EqualsHashCode"/>
<module name="HiddenField"/>
<module name="HiddenField">
<property name="ignoreSetter" value="true"/>
<property name="ignoreConstructorParameter" value="true"/>
</module>
<module name="IllegalInstantiation"/>
<module name="InnerAssignment"/>
<module name="MissingSwitchDefault"/>
Expand Down
8 changes: 5 additions & 3 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,12 @@
<properties>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<maven.source.plugin.version>3.2.0</maven.source.plugin.version>
<maven.source.plugin.version>3.2.1</maven.source.plugin.version>
<maven.javadoc.plugin.version>3.1.1</maven.javadoc.plugin.version>
<maven.gpg.plugin.version>1.6</maven.gpg.plugin.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<junit.version>4.13</junit.version>
<pitest-maven.version>1.4.11</pitest-maven.version>
</properties>

<developers>
Expand Down Expand Up @@ -70,7 +72,7 @@
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<version>${junit.version}</version>
<scope>test</scope>
</dependency>
<dependency>
Expand Down Expand Up @@ -113,7 +115,7 @@
<plugin>
<groupId>org.pitest</groupId>
<artifactId>pitest-maven</artifactId>
<version>1.4.10</version>
<version>${pitest-maven.version}</version>
<executions>
<execution>
<goals>
Expand Down
32 changes: 14 additions & 18 deletions src/main/java/io/github/mivek/command/AirportSupplier.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,19 @@
import java.nio.charset.StandardCharsets;
import java.util.HashMap;
import java.util.Map;
import java.util.Optional;

/**
* @author mivek
*/
public final class AirportSupplier implements Supplier<Optional<Airport>> {
public final class AirportSupplier implements Supplier<Airport> {
/** Path of airport file. */
private final InputStream fAirportsFile = AbstractParser.class.getClassLoader().getResourceAsStream("data/airports.dat");
private final InputStream airportsFile = AbstractParser.class.getClassLoader().getResourceAsStream("data/airports.dat");
/** Path of countries file. */
private final InputStream fCountriesFile = AbstractParser.class.getClassLoader().getResourceAsStream("data/countries.dat");
private final InputStream countriesFile = AbstractParser.class.getClassLoader().getResourceAsStream("data/countries.dat");
/** Map of countries. */
private Map<String, Country> fCountries;
private Map<String, Country> countries;
/** Map of airports. */
private Map<String, Airport> fAirports;
private Map<String, Airport> airports;

/**
* Constructor.
Expand All @@ -39,22 +38,22 @@ public AirportSupplier() {
* Initiate airports map.
*/
private void initAirports() {
fAirports = new HashMap<>();
airports = new HashMap<>();
String[] line;
try (CSVReader reader = new CSVReader(new InputStreamReader(fAirportsFile, StandardCharsets.UTF_8))) {
try (CSVReader reader = new CSVReader(new InputStreamReader(airportsFile, StandardCharsets.UTF_8))) {
while ((line = reader.readNext()) != null) {
Airport airport = new Airport();
airport.setName(line[1]);
airport.setCity(line[2]);
airport.setCountry(fCountries.get(line[3]));
airport.setCountry(countries.get(line[3]));
airport.setIata(line[4]);
airport.setIcao(line[5]);
airport.setLatitude(Double.parseDouble(line[6]));
airport.setLongitude(Double.parseDouble(line[7]));
airport.setAltitude(Integer.parseInt(line[8]));
airport.setTimezone(line[9]);
airport.setDst(line[10]);
fAirports.put(airport.getIcao(), airport);
airports.put(airport.getIcao(), airport);
}
} catch (IOException | CsvValidationException exception) {
throw new IllegalStateException(exception.getMessage());
Expand All @@ -65,24 +64,21 @@ private void initAirports() {
* Initiate countries map.
*/
private void initCountries() {
fCountries = new HashMap<>();
countries = new HashMap<>();
String[] line;
try (CSVReader reader = new CSVReader(new InputStreamReader(fCountriesFile, StandardCharsets.UTF_8))) {
try (CSVReader reader = new CSVReader(new InputStreamReader(countriesFile, StandardCharsets.UTF_8))) {
while ((line = reader.readNext()) != null) {
Country country = new Country();
country.setName(line[0]);
fCountries.put(country.getName(), country);
countries.put(country.getName(), country);
}
} catch (IOException | CsvValidationException exception) {
throw new IllegalStateException(exception.getMessage());
}
}

@Override public Optional<Airport> get(final String pIcao) {
if (fAirports.containsKey(pIcao)) {
return Optional.of(fAirports.get(pIcao));
}
return Optional.empty();
@Override public Airport get(final String pIcao) {
return airports.get(pIcao);
}
}

16 changes: 16 additions & 0 deletions src/main/java/io/github/mivek/model/AbstractWeatherCode.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ public abstract class AbstractWeatherCode extends AbstractWeatherContainer {
private Airport airport;
/** Original message of the metar. */
private String message;
/** The identifier of the station. */
private String station;


/**
Expand Down Expand Up @@ -77,6 +79,20 @@ 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.
*/
Expand Down
8 changes: 3 additions & 5 deletions src/main/java/io/github/mivek/parser/MetarParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
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.exception.ErrorCodes;
import io.github.mivek.exception.ParseException;
import io.github.mivek.model.Airport;
import io.github.mivek.model.Metar;
import io.github.mivek.model.trend.AbstractMetarTrend;
Expand Down Expand Up @@ -68,12 +66,12 @@ public static MetarParser getInstance() {
*
* @param pMetarCode String representing the metar.
* @return a decoded metar object.
* @throws ParseException when an error occurs.
*/
@Override public Metar parse(final String pMetarCode) throws ParseException {
@Override public Metar parse(final String pMetarCode) {
Metar m = new Metar();
String[] metarTab = tokenize(pMetarCode);
Airport airport = getAirportSupplier().get(metarTab[0]).orElseThrow(() -> new ParseException(ErrorCodes.ERROR_CODE_AIRPORT_NOT_FOUND));
Airport airport = getAirportSupplier().get(metarTab[0]);
m.setStation(metarTab[0]);
m.setAirport(airport);
m.setMessage(pMetarCode);
parseDeliveryTime(m, metarTab[1]);
Expand Down
5 changes: 3 additions & 2 deletions src/main/java/io/github/mivek/parser/TAFParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,8 @@ public TAF parse(final String pTAFCode) throws ParseException {
i++;
}
// Airport
Airport airport = getAirportSupplier().get(line1parts[i]).orElseThrow(() -> new ParseException(ErrorCodes.ERROR_CODE_AIRPORT_NOT_FOUND));
Airport airport = getAirportSupplier().get(line1parts[i]);
taf.setStation(line1parts[i]);
i++;
taf.setAirport(airport);
taf.setMessage(pTAFCode);
Expand Down Expand Up @@ -277,4 +278,4 @@ protected TemperatureDated parseTemperature(final String pTempPart) {
return temperature;
}

}
}
Loading

0 comments on commit ccb01f9

Please sign in to comment.