initial commit

This commit is contained in:
Greg Gauthier 2015-11-16 13:17:19 +01:00
commit bb2a1c6223
10 changed files with 82209 additions and 0 deletions

103
.gitignore vendored Normal file
View File

@ -0,0 +1,103 @@
### Eclipse template
*.pydevproject
.metadata
.gradle
bin/
tmp/
*.tmp
*.bak
*.swp
*~.nib
local.properties
.settings/
.loadpath
# Eclipse Core
.project
# External tool builders
.externalToolBuilders/
# Locally stored "Eclipse launch configurations"
*.launch
# CDT-specific
.cproject
# JDT-specific (Eclipse Java Development Tools)
.classpath
# Java annotation processor (APT)
.factorypath
# PDT-specific
.buildpath
# sbteclipse plugin
.target
# TeXlipse plugin
.texlipse
### Java template
*.class
# Mobile Tools for Java (J2ME)
.mtj.tmp/
# Package Files #
*.jar
*.war
*.ear
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
hs_err_pid*
### JetBrains template
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio
*.iml
## Directory-based project format:
.idea/
# if you remove the above rule, at least ignore the following:
# User-specific stuff:
# .idea/workspace.xml
# .idea/tasks.xml
# .idea/dictionaries
# Sensitive or high-churn files:
# .idea/dataSources.ids
# .idea/dataSources.xml
# .idea/sqlDataSources.xml
# .idea/dynamic.xml
# .idea/uiDesigner.xml
# Gradle:
# .idea/gradle.xml
# .idea/libraries
# Mongo Explorer plugin:
# .idea/mongoSettings.xml
## File-based project format:
*.ipr
*.iws
## Plugin-specific files:
# IntelliJ
/out/
# mpeltonen/sbt-idea plugin
.idea_modules/
# JIRA plugin
atlassian-ide-plugin.xml
# Crashlytics plugin (for Android Studio and IntelliJ)
com_crashlytics_export_strings.xml
crashlytics.properties
crashlytics-build.properties
# Created by .ignore support plugin (hsz.mobi)
.DS_Store

6048
data/airlines.dat Normal file

File diff suppressed because it is too large Load Diff

8107
data/airports.dat Normal file

File diff suppressed because it is too large Load Diff

67663
data/routes.dat Normal file

File diff suppressed because it is too large Load Diff

5
src/AirlineData.java Normal file
View File

@ -0,0 +1,5 @@
/**
* Created by gmgauthier on 2015.11.06.
*/
public class AirlineData {
}

150
src/Airport.java Normal file
View File

@ -0,0 +1,150 @@
public class Airport implements Comparable<Airport> {
private int ofid;
private String name;
private String city;
private String country;
private String iata;
private String icao;
private double lat;
private double lon;
private int alt;
private float tzoffset; //half zones are expressed as decimals
private char dst; // One of E (Europe), A (US/Canada), S (South America), O (Australia), Z (New Zealand), N (None) or U (Unknown)
private String tzolsen;
public Airport(int ofid, String name, String city, String country, String iata, String icao, double lat, double lon, int alt,
float tzoffset, char dst, String tzolsen) {
this.ofid = ofid;
this.name = name;
this.city = city;
this.country = country;
this.iata = iata;
this.icao = icao;
this.lat = lat;
this.lon = lon;
this.alt = alt;
this.tzoffset = tzoffset;
this.dst = dst;
this.tzolsen = tzolsen;
}
public int getOfid() {
return ofid;
}
public void setOfid(int ofid) {
this.ofid = ofid;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getCity() {
return city;
}
public void setCity(String city) {
this.city = city;
}
public String getCountry() {
return country;
}
public void setCountry(String country) {
this.country = country;
}
public String getIata() {
return iata;
}
public void setIata(String iata) {
this.iata = iata;
}
public String getIcao() {
return icao;
}
public void setIcao(String icao) {
this.icao = icao;
}
public double getLat() {
return lat;
}
public void setLat(Double lat) {
this.lat = lat;
}
public double getLon() {
return lon;
}
public void setLon(Double lon) {
this.lon = lon;
}
public int getAlt() {
return alt;
}
public void setAlt(int alt) {
this.alt = alt;
}
public float getTzoffset() {
return tzoffset;
}
public void setTzoffset(float tzoffset) {
this.tzoffset = tzoffset;
}
public char getDst() {
return dst;
}
public void setDst(char dst) {
this.dst = dst;
}
public String getTzolsen() {
return tzolsen;
}
public void setTzolsen(String tzolsen) {
this.tzolsen = tzolsen;
}
@Override
public String toString() {
return "Airport{" +
"ofid=" + ofid +
", name='" + name + '\'' +
", city='" + city + '\'' +
", iata='" + iata + '\'' +
", icao='" + icao + '\'' +
", lat=" + lat +
", lon=" + lon +
", alt=" + alt +
", tzoffset=" + tzoffset +
", dst=" + dst +
", tzolsen='" + tzolsen + '\'' +
'}';
}
@Override
public int compareTo(Airport o) {
return (this.getCity().compareTo(o.getCity()));
}
}

80
src/AirportData.java Normal file
View File

@ -0,0 +1,80 @@
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;
public class AirportData {
private ArrayList<Airport> airports = new ArrayList<>();
// Constructors
public AirportData() {
this("data/airports.dat");
}
public AirportData(String dataFile){
List<String[]> csvData = DataReader.readCSVFile(dataFile);
for (String[] row : csvData){
Airport airport = createAirport(row);
airports.add(airport);
}
// Collections.sort(airports);
}
//Accessors
public ArrayList<Airport> getAirports() {
return airports;
}
// Public methods
public Airport findAirportByName(String name){
return null;
}
public Airport findAirportByIATA(String iata){
//TODO: Searching by IATA identifier
return null;
}
public Airport findAirportByICAO(String icao){
//TODO: Searching by ICAO identifier
return null;
}
public ArrayList<Airport> findAirportsByCity(String city) {
ArrayList<Airport> searchResults = airports.stream().filter(airport -> city.equals(airport.getCity())).
collect(Collectors.toCollection(ArrayList::new));
return searchResults;
}
public Airport findAirportsByCountry(String country){
//TODO: Searching by country name
return null;
}
public void sortAirports(){
Collections.sort(this.airports);
}
// Private methods
private Airport createAirport(String[] row){
int ofid = Integer.parseInt(row[0]);
String name = row[1];
String city = row[2];
String country = row[3];
String iata = row[4];
String icao = row[5];
double lat = Double.parseDouble(row[6]);
double lon = Double.parseDouble(row[7]);
int alt = Integer.parseInt(row[8]);
float tzoffset = Float.parseFloat(row[9]);
char dst = row[10].charAt(0);
String tzolsen = row[11];
return new Airport(ofid, name, city, country, iata, icao, lat, lon, alt, tzoffset, dst, tzolsen);
}
}

27
src/DataReader.java Normal file
View File

@ -0,0 +1,27 @@
import com.opencsv.CSVReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.List;
public class DataReader {
static List<String[]> readCSVFile(String fname){
CSVReader reader = null;
List<String[]> entries = null;
try {
reader = new CSVReader(new FileReader(fname));
} catch (FileNotFoundException e) {
e.printStackTrace();
}
try {
if (reader != null) entries = reader.readAll();
} catch (IOException e) {
e.printStackTrace();
}
return entries;
}
}

5
src/RouteData.java Normal file
View File

@ -0,0 +1,5 @@
/**
* Created by gmgauthier on 2015.11.06.
*/
public class RouteData {
}

21
src/SearchTests.java Normal file
View File

@ -0,0 +1,21 @@
import java.util.ArrayList;
public class SearchTests {
public static void main(String[] args) {
AirportData airportData = new AirportData();
ArrayList<Airport> chicagoAirports = airportData.findAirportsByCity("Chicago");
for (Airport airport: chicagoAirports){
System.out.printf("%-4s %-27s %-4.7f / %-4.7f \n", airport.getIata(),
airport.getName(), airport.getLat(), airport.getLon());
}
System.out.println(chicagoAirports);
}
}