Parsers, Core Files and Dataset Controllers
This commit is contained in:
@@ -19,6 +19,11 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/ma
|
|||||||
<artifactId>gson</artifactId>
|
<artifactId>gson</artifactId>
|
||||||
<version>2.5</version>
|
<version>2.5</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.xerial</groupId>
|
||||||
|
<artifactId>sqlite-jdbc</artifactId>
|
||||||
|
<version>3.8.11.2</version>
|
||||||
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
<build>
|
<build>
|
||||||
<plugins>
|
<plugins>
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,31 @@
|
|||||||
|
APT,NZCH,0,-43.48664019,172.53368221
|
||||||
|
VOR,CH,400,-43.50411111,172.51463889000001
|
||||||
|
FIX,VANDA,34000,-42.421806,169.34450000000004
|
||||||
|
FIX,UKLAK,34000,-41.4245,166.71119399999998
|
||||||
|
FIX,SULON,34000,-39.858528,163
|
||||||
|
FIX,PLUGA,34000,-35.6075,154.68888900000002
|
||||||
|
FIX,CAWLY,34000,-34.326111,151.95777799999996
|
||||||
|
VOR,SY,34000,-33.94277778,151.18055556000002
|
||||||
|
NDB,KAT,34000,-33.710806,150.299622
|
||||||
|
VOR,PKS,34000,-33.131111,148.23722199999997
|
||||||
|
FIX,VIMAB,34000,-31.515277999999995,145.358611
|
||||||
|
FIX,APOMA,34000,-29.898055999999997,142.681667
|
||||||
|
FIX,POLEV,34000,-26.920277999999996,138.16916700000002
|
||||||
|
FIX,KALUG,34000,-25.900000000000006,136.72500000000002
|
||||||
|
VOR,AS,34000,-23.792889000000002,133.87820299999998
|
||||||
|
FIX,TIMMI,34000,-21.922483,130.65954399999998
|
||||||
|
FIX,TATUK,34000,-19.429444000000004,126.646389
|
||||||
|
VOR,CIN,34000,-17.588888889999993,123.85194444000001
|
||||||
|
FIX,ATMAP,34000,-12,118.255
|
||||||
|
FIX,ILDAM,34000,-10.592113999999995,116.88456400000001
|
||||||
|
VOR,BLI,34000,-8.750583329999998,115.16330556000003
|
||||||
|
FIX,SIPUT,34000,-6.283332999999999,112.58333299999998
|
||||||
|
FIX,SUMBU,34000,-4.7549999999999955,110.82333299999999
|
||||||
|
FIX,SABIL,34000,-4.019069000000002,109.93852800000002
|
||||||
|
FIX,AKULA,34000,-3.119878,108.95092499999998
|
||||||
|
FIX,APAGA,34000,-2.7826749999999976,108.580897
|
||||||
|
FIX,APARI,34000,-2.043471999999994,107.84038299999997
|
||||||
|
FIX,SANOS,34000,-0.7000000000000028,106.316667
|
||||||
|
FIX,AKTOD,34300,-0.4133329999999944,105.99305600000002
|
||||||
|
NDB,TI,8800,0.9197280000000063,104.52616899999998
|
||||||
|
APT,WSSS,0,1.3519171399999976,103.99560303999999
|
||||||
|
+67663
File diff suppressed because it is too large
Load Diff
Binary file not shown.
@@ -0,0 +1,127 @@
|
|||||||
|
package seng202.group9.Controller;
|
||||||
|
|
||||||
|
import seng202.group9.Core.Airline;
|
||||||
|
|
||||||
|
import java.io.*;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
|
||||||
|
public class AirlineParser extends Parser {
|
||||||
|
String filePath = "";
|
||||||
|
ArrayList<Airline> parsedAirline;
|
||||||
|
|
||||||
|
public AirlineParser(String filePath){
|
||||||
|
this.filePath = filePath;
|
||||||
|
parsedAirline = new ArrayList<Airline>();
|
||||||
|
}
|
||||||
|
|
||||||
|
public String parse() throws DataException{
|
||||||
|
int successful = 0;
|
||||||
|
int error = 0;
|
||||||
|
int duplicate = 0;
|
||||||
|
|
||||||
|
File file = new File(filePath);
|
||||||
|
BufferedReader reader = null;
|
||||||
|
|
||||||
|
try {
|
||||||
|
reader = new BufferedReader(new FileReader(file));
|
||||||
|
String line = null;
|
||||||
|
|
||||||
|
while ((line = reader.readLine()) != null) {
|
||||||
|
//read file here
|
||||||
|
//id, name, alias, city, iata, icao, callsign, country, active
|
||||||
|
//sample line: 2,"135 Airways",\N,"","GNL","GENERAL","United States","N"
|
||||||
|
String airlName = "";
|
||||||
|
String airlAlias = "";
|
||||||
|
String airlIATA = "";
|
||||||
|
String airlICAO = "";
|
||||||
|
String airlCallsign = "";
|
||||||
|
String airlCountry = "";
|
||||||
|
String airlActive = "";
|
||||||
|
String parts[] = {"", "", "", "", "", "", "", ""};
|
||||||
|
int part = 0;
|
||||||
|
boolean inQuotes = false;
|
||||||
|
for (int i = 0; i < line.length(); i ++){
|
||||||
|
if (line.charAt(i) == ','){
|
||||||
|
if (inQuotes == true){
|
||||||
|
parts[part] += line.charAt(i);
|
||||||
|
}else{
|
||||||
|
part++;
|
||||||
|
}
|
||||||
|
}else if (line.charAt(i) == '\"'){
|
||||||
|
inQuotes = !inQuotes;
|
||||||
|
}else {
|
||||||
|
parts[part] += line.charAt(i);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//check length
|
||||||
|
if (parts.length != 8){
|
||||||
|
System.out.println(parts[1] + " does not have 8 entries.");
|
||||||
|
error++;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
//types do not need to be checked as they are all strings
|
||||||
|
boolean errorBreak = false;
|
||||||
|
//cehck sizes of [][] eg {3,0} will check if length == 3 or == 0. if -1 the size is ignored
|
||||||
|
int partSizes[][] = {{-1}, {-1}, {-1}, {2,0}, {3,0}, {-1}, {-1}, {1}};
|
||||||
|
for (int i = 1; i < partSizes.length; i ++){
|
||||||
|
boolean passable = false;
|
||||||
|
for (int j = 0; j < partSizes[i].length; j++){
|
||||||
|
if (partSizes[i][j] != -1) {
|
||||||
|
if (parts[i].equals("\\N")){
|
||||||
|
parts[i] = "";
|
||||||
|
}
|
||||||
|
if (parts[i].length() == partSizes[i][j] || parts[i].equals("-") ||
|
||||||
|
parts[i].equals("N/A")) {
|
||||||
|
passable = true;
|
||||||
|
}
|
||||||
|
}else{
|
||||||
|
passable = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (passable == false){
|
||||||
|
System.out.println(parts[1] + " has Length: " + parts[i].length() + ", Value: " + parts[i] + " @ Index: " + i);
|
||||||
|
error++;
|
||||||
|
errorBreak = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (errorBreak == true){
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
//passing is done now add stuff to array
|
||||||
|
//id, name, alias, iata, icao, callsign, country, active
|
||||||
|
airlName = parts[1];
|
||||||
|
airlAlias = parts[2];
|
||||||
|
airlIATA = parts[3];
|
||||||
|
airlICAO = parts[4];
|
||||||
|
airlCallsign = parts[5];
|
||||||
|
airlCountry = parts[6];
|
||||||
|
airlActive = parts[7];
|
||||||
|
parsedAirline.add(new Airline(airlName, airlAlias, airlIATA, airlICAO, airlCallsign, airlCountry, airlActive));
|
||||||
|
successful++;
|
||||||
|
}
|
||||||
|
} catch (FileNotFoundException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
throw new DataException("File: " +this.filePath+" is Missing.");
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
throw new DataException(this.filePath + " is Corrupted.");
|
||||||
|
} finally {
|
||||||
|
try {
|
||||||
|
if (reader != null) {
|
||||||
|
reader.close();
|
||||||
|
}
|
||||||
|
} catch (IOException e) {
|
||||||
|
throw new DataException(this.filePath + " is unable to initialise reader.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return String.format("Entries Successfully Entered: %1$d.\n" +
|
||||||
|
"Entries With Errors: %2$d", successful, error);
|
||||||
|
}
|
||||||
|
|
||||||
|
public ArrayList<Airline> getResult(){
|
||||||
|
return parsedAirline;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,184 @@
|
|||||||
|
package seng202.group9.Controller;
|
||||||
|
|
||||||
|
import seng202.group9.Core.Airport;
|
||||||
|
import seng202.group9.Core.City;
|
||||||
|
import seng202.group9.Core.Country;
|
||||||
|
|
||||||
|
import java.io.*;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
|
||||||
|
public class AirportParser extends Parser {
|
||||||
|
String filePath = "";
|
||||||
|
ArrayList<Airport> parsedAirports;
|
||||||
|
ArrayList<City> parsedCities;
|
||||||
|
ArrayList<Country> parsedCountries;
|
||||||
|
|
||||||
|
public AirportParser(String filePath){
|
||||||
|
this.filePath = filePath;
|
||||||
|
parsedAirports = new ArrayList<Airport>();
|
||||||
|
parsedCities = new ArrayList<City>();
|
||||||
|
parsedCountries = new ArrayList<Country>();
|
||||||
|
}
|
||||||
|
|
||||||
|
public String parse() throws DataException{
|
||||||
|
int successful = 0;
|
||||||
|
int error = 0;
|
||||||
|
int duplicate = 0;
|
||||||
|
|
||||||
|
File file = new File(filePath);
|
||||||
|
BufferedReader reader = null;
|
||||||
|
|
||||||
|
try {
|
||||||
|
reader = new BufferedReader(new FileReader(file));
|
||||||
|
String line = null;
|
||||||
|
|
||||||
|
while ((line = reader.readLine()) != null) {
|
||||||
|
//read file here
|
||||||
|
//id, name, city, country, iata/ffa, icao, lat, long, altitude, Timezone, DST, TimeOlson
|
||||||
|
//sample line: 1,"Goroka","Goroka","Papua New Guinea","GKA","AYGA",-6.081689,145.391881,5282,10,"U","Pacific/Port_Moresby"
|
||||||
|
String airpName = "";
|
||||||
|
String airpCity = "";
|
||||||
|
String airpCountry = "";
|
||||||
|
String airpIATA_FFA = "";
|
||||||
|
String airpICAO = "";
|
||||||
|
double airpLat = 0.0;
|
||||||
|
double airpLong = 0.0;
|
||||||
|
double airpAltitude = 0.0;
|
||||||
|
double airpTimezone = 0;
|
||||||
|
String airpDST = "U";
|
||||||
|
String airpOlson = "";
|
||||||
|
//line = line.replaceAll("\"", "");
|
||||||
|
String parts[] = {"", "", "", "", "", "", "", "", "", "", "", ""};
|
||||||
|
int part = 0;
|
||||||
|
boolean inQuotes = false;
|
||||||
|
for (int i = 0; i < line.length(); i ++){
|
||||||
|
if (line.charAt(i) == ','){
|
||||||
|
if (inQuotes == true){
|
||||||
|
parts[part] += line.charAt(i);
|
||||||
|
}else{
|
||||||
|
part++;
|
||||||
|
}
|
||||||
|
}else if (line.charAt(i) == '\"'){
|
||||||
|
inQuotes = !inQuotes;
|
||||||
|
}else {
|
||||||
|
parts[part] += line.charAt(i);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//System.out.println(parts[0] + " | " + parts[1] + " | " + parts[2] + " | " + parts[3] + " | " + parts[4] + " | "
|
||||||
|
// + parts[5] + " | " + parts[6] + " | " + parts[7] + " | " + parts[8] + " | " + parts[9] + " | " + parts[10] + " | " + parts[11]);
|
||||||
|
//check length
|
||||||
|
if (parts.length != 12){
|
||||||
|
System.out.println(parts[1] + " does not have 12 entries.");
|
||||||
|
error++;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
//check types I = integer, S = String D = Double
|
||||||
|
char partTypes[] = {'I','S', 'S','S', 'S', 'S', 'D', 'D', 'D', 'D', 'S', 'S'};
|
||||||
|
//ignore the first value as their id is not useful to us.
|
||||||
|
boolean errorBreak = false;
|
||||||
|
for (int i = 1; i < partTypes.length; i ++){
|
||||||
|
if (partTypes[i] == 'I'){
|
||||||
|
try {
|
||||||
|
if (parts[i].equals("\\N")){
|
||||||
|
parts[i] = "0";
|
||||||
|
}
|
||||||
|
Integer.parseInt(parts[i]);
|
||||||
|
}catch (NumberFormatException e){
|
||||||
|
System.out.println(parts[1] + " has Value: " + parts[i] + " And is not a Integer Formattable Value.");
|
||||||
|
error++;
|
||||||
|
errorBreak = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}else if (partTypes[i] == 'D'){
|
||||||
|
try{
|
||||||
|
if (parts[i].equals("\\N")){
|
||||||
|
parts[i] = "0";
|
||||||
|
}
|
||||||
|
Double.parseDouble(parts[i]);
|
||||||
|
}catch (NumberFormatException e){
|
||||||
|
System.out.println(parts[1] + " has Value: " + parts[i] + " And is not a Double Formattable Value.");
|
||||||
|
error++;
|
||||||
|
errorBreak = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (errorBreak == true){
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
//cehck sizes of [][] eg {3,0} will check if length == 3 or == 0. if -1 the size is ignored
|
||||||
|
int partSizes[][] = {{-1}, {-1}, {-1}, {-1}, {3,0}, {4,0}, {-1}, {-1}, {-1}, {-1}, {1,0}, {-1}};
|
||||||
|
for (int i = 1; i < partSizes.length; i ++){
|
||||||
|
boolean passable = false;
|
||||||
|
for (int j = 0; j < partSizes[i].length; j++){
|
||||||
|
if (partSizes[i][j] != -1) {
|
||||||
|
if (parts[i].equals("\\N")){
|
||||||
|
parts[i] = "";
|
||||||
|
}
|
||||||
|
if (parts[i].length() == partSizes[i][j]) {
|
||||||
|
passable = true;
|
||||||
|
}
|
||||||
|
}else{
|
||||||
|
passable = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (passable == false){
|
||||||
|
System.out.println(parts[1] + " has Length: " + parts[i].length() + ", Value: " + parts[i] + " @ Index: " + i);
|
||||||
|
error++;
|
||||||
|
errorBreak = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (errorBreak == true){
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
//passing is done now add stuff to array
|
||||||
|
airpName = parts[1];
|
||||||
|
airpCity = parts[2];
|
||||||
|
airpCountry = parts[3];
|
||||||
|
airpIATA_FFA = parts[4];
|
||||||
|
airpICAO = parts[5];
|
||||||
|
airpLat = Double.parseDouble(parts[6]);
|
||||||
|
airpLong = Double.parseDouble(parts[7]);
|
||||||
|
airpAltitude = Double.parseDouble(parts[8]);
|
||||||
|
airpTimezone = Double.parseDouble(parts[9]);
|
||||||
|
airpDST = parts[10];
|
||||||
|
airpOlson = parts[11];
|
||||||
|
parsedAirports.add(new Airport(airpName, airpCity, airpCountry, airpIATA_FFA, airpICAO, airpLat, airpLong, airpAltitude));
|
||||||
|
parsedCities.add(new City(airpCity, airpCountry, airpTimezone, airpOlson));
|
||||||
|
parsedCountries.add(new Country(airpDST, airpCountry));
|
||||||
|
successful++;
|
||||||
|
}
|
||||||
|
} catch (FileNotFoundException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
throw new DataException("File: " +this.filePath+" is Missing.");
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
throw new DataException(this.filePath + " is Corrupted.");
|
||||||
|
} finally {
|
||||||
|
try {
|
||||||
|
if (reader != null) {
|
||||||
|
reader.close();
|
||||||
|
}
|
||||||
|
} catch (IOException e) {
|
||||||
|
throw new DataException(this.filePath + " is unable to initialise reader.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return String.format("Entries Successfully Entered: %1$d.\n" +
|
||||||
|
"Entries With Errors: %2$d", successful, error);
|
||||||
|
}
|
||||||
|
|
||||||
|
public ArrayList<Airport> getResult(){
|
||||||
|
return parsedAirports;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ArrayList<City> getCityResult(){
|
||||||
|
return parsedCities;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ArrayList<Country> getCountryResult(){
|
||||||
|
return parsedCountries;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -14,17 +14,15 @@ import seng202.group9.GUI.MainMenuBar;
|
|||||||
*/
|
*/
|
||||||
public class App extends Application
|
public class App extends Application
|
||||||
{
|
{
|
||||||
ArrayList<DatasetController> Datasets = new ArrayList<DatasetController>();
|
ArrayList<Dataset> Datasets = new ArrayList<Dataset>();
|
||||||
|
|
||||||
public static void main( String[] args )
|
public static void main( String[] args )
|
||||||
{
|
{
|
||||||
launch(args);
|
launch(args);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Starts the application
|
* Starts the application
|
||||||
* @param primaryStage main "stage" of the program
|
* @param primaryStage main "stage" of the program
|
||||||
* @see The last sessions menu or the getting started page.
|
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void start(Stage primaryStage) {
|
public void start(Stage primaryStage) {
|
||||||
@@ -37,5 +35,33 @@ public class App extends Application
|
|||||||
|
|
||||||
primaryStage.setScene(scene);
|
primaryStage.setScene(scene);
|
||||||
primaryStage.show();
|
primaryStage.show();
|
||||||
|
//testing out dataset
|
||||||
|
Dataset dataset1 = null;
|
||||||
|
try {
|
||||||
|
dataset1 = new Dataset("test's", Dataset.getExisting);
|
||||||
|
}catch (DataException e){
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
//testing out airport parser
|
||||||
|
AirportParser airportParser = new AirportParser("res/Samples/Airports.txt");
|
||||||
|
try {
|
||||||
|
System.out.println(airportParser.parse());
|
||||||
|
} catch (DataException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
//testing out airline parser
|
||||||
|
AirlineParser airlineParser = new AirlineParser("res/Samples/Airlines.txt");
|
||||||
|
try {
|
||||||
|
System.out.println(airlineParser.parse());
|
||||||
|
} catch (DataException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
//testing out route parser
|
||||||
|
RouteParser routeParser = new RouteParser("res/Samples/Routes.txt");
|
||||||
|
try {
|
||||||
|
System.out.println(routeParser.parse());
|
||||||
|
} catch (DataException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,321 @@
|
|||||||
|
package seng202.group9.Controller;
|
||||||
|
|
||||||
|
|
||||||
|
import seng202.group9.Core.*;
|
||||||
|
|
||||||
|
import java.sql.Connection;
|
||||||
|
import java.sql.DriverManager;
|
||||||
|
import java.sql.ResultSet;
|
||||||
|
import java.sql.Statement;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
|
||||||
|
public class Dataset {
|
||||||
|
|
||||||
|
String name;
|
||||||
|
static boolean getExisting = true;
|
||||||
|
static boolean createNew = false;
|
||||||
|
ArrayList<Airline> airlines;
|
||||||
|
ArrayList<Airport> airports;
|
||||||
|
ArrayList<Route> routes;
|
||||||
|
ArrayList<FlightPath> flightPaths;
|
||||||
|
ArrayList<Country> countries;
|
||||||
|
ArrayList<City> cities;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @param name Name of the database
|
||||||
|
* @param action either Dataset.getExisting or Dataset.createNew
|
||||||
|
* @throws DataException Throws an exception if there is some error ie databases with the same name
|
||||||
|
*/
|
||||||
|
public Dataset(String name, boolean action) throws DataException {
|
||||||
|
this.name = name;
|
||||||
|
this.airlines = new ArrayList<Airline>();
|
||||||
|
this.airports = new ArrayList<Airport>();
|
||||||
|
this.flightPaths = new ArrayList<FlightPath>();
|
||||||
|
this.routes = new ArrayList<Route>();
|
||||||
|
this.cities = new ArrayList<City>();
|
||||||
|
this.countries = new ArrayList<Country>();
|
||||||
|
if (action == getExisting){
|
||||||
|
updateDataset();
|
||||||
|
//after this make connections. ie filling in the country.cities airports.routes etc
|
||||||
|
}else if (action == createNew){
|
||||||
|
createTables();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Updates Dataset Arrays from Database.
|
||||||
|
* @throws DataException
|
||||||
|
*/
|
||||||
|
public void updateDataset() throws DataException{
|
||||||
|
Connection c = null;
|
||||||
|
Statement stmt = null;
|
||||||
|
int numOfDuplicateNames = 0;
|
||||||
|
try {
|
||||||
|
Class.forName("org.sqlite.JDBC");
|
||||||
|
c = DriverManager.getConnection("jdbc:sqlite:res/userdb.db");
|
||||||
|
stmt = c.createStatement();
|
||||||
|
String queryName = this.name.replace("'", "''").replace("\"", "\"\"");//this allows quotes in datasets
|
||||||
|
ResultSet rs = stmt.executeQuery( "SELECT COUNT(*) FROM `Datasets` WHERE `Dataset_Name` = '"+queryName+"';" );
|
||||||
|
while ( rs.next() ) {
|
||||||
|
numOfDuplicateNames = rs.getInt("COUNT(*)");
|
||||||
|
}
|
||||||
|
if (numOfDuplicateNames == 0){
|
||||||
|
throw new DataException("There is no Dataset under this Name.");
|
||||||
|
}
|
||||||
|
rs.close();
|
||||||
|
stmt.close();
|
||||||
|
//if no problem update data;
|
||||||
|
/*//////////////////
|
||||||
|
//get all airlines//
|
||||||
|
//////////////////*/
|
||||||
|
stmt = c.createStatement();
|
||||||
|
String queryAirlines = "SELECT * FROM `"+this.name+"_Airline`";
|
||||||
|
rs = stmt.executeQuery(queryAirlines);
|
||||||
|
while ( rs.next() ){
|
||||||
|
//Airline(int ID, String name, String alias, String IATA, String ICAO, String callSign, String country, String active)
|
||||||
|
int airID = rs.getInt("Airline_ID");
|
||||||
|
String airName = rs.getString("Name");
|
||||||
|
String airIATA = rs.getString("IATA");
|
||||||
|
String airICAO = rs.getString("ICAO");
|
||||||
|
String airAlias = rs.getString("Alias");
|
||||||
|
String airCallsign = rs.getString("CallSign");
|
||||||
|
String airCountry = rs.getString("Country");
|
||||||
|
String airActive = rs.getString("Active");
|
||||||
|
airlines.add(new Airline(airID, airName, airIATA, airICAO, airAlias, airCallsign, airCountry, airActive));
|
||||||
|
}
|
||||||
|
rs.close();
|
||||||
|
stmt.close();
|
||||||
|
/*//////////////////
|
||||||
|
//get all Airports//
|
||||||
|
//////////////////*/
|
||||||
|
stmt = c.createStatement();
|
||||||
|
String queryAirport = "SELECT * FROM `"+this.name+"_Airport`";
|
||||||
|
rs = stmt.executeQuery(queryAirport);
|
||||||
|
while ( rs.next() ){
|
||||||
|
//Airport(int ID, String name, String city, String country, String IATA_FFA, String ICAO, double latitude, double longitude, double altitude)
|
||||||
|
int airpID = rs.getInt("Airport_ID");
|
||||||
|
String airpName = rs.getString("Name");
|
||||||
|
String airpCity = rs.getString("City");
|
||||||
|
String airpCountry = rs.getString("Country");
|
||||||
|
String airpIATA_FFA = rs.getString("IATA/FFA");
|
||||||
|
String airpICAO = rs.getString("ICAO");
|
||||||
|
double airpLatitude = rs.getDouble("Latitude");
|
||||||
|
double airpLongitude = rs.getDouble("Longitude");
|
||||||
|
double airpAltitude = rs.getDouble("Altitude");
|
||||||
|
airports.add(new Airport(airpID, airpName, airpCity, airpCountry, airpIATA_FFA, airpICAO, airpLatitude, airpLongitude, airpAltitude));
|
||||||
|
}
|
||||||
|
rs.close();
|
||||||
|
stmt.close();
|
||||||
|
/*////////////////
|
||||||
|
//get all cities//
|
||||||
|
////////////////*/
|
||||||
|
stmt = c.createStatement();
|
||||||
|
String queryCities = "SELECT * FROM `"+this.name+"_City`";
|
||||||
|
rs = stmt.executeQuery(queryCities);
|
||||||
|
while ( rs.next() ){
|
||||||
|
//City(String name, String timezone, String timeOlson)
|
||||||
|
String cityName = rs.getString("City_Name");
|
||||||
|
String cityCountry = rs.getString("Country_Name");
|
||||||
|
double cityTz = rs.getDouble("Timezone");
|
||||||
|
String cityTimeOlson = rs.getString("Olson_Timezone");
|
||||||
|
cities.add(new City(cityName, cityCountry, cityTz, cityTimeOlson));
|
||||||
|
}
|
||||||
|
rs.close();
|
||||||
|
stmt.close();
|
||||||
|
/*///////////////////
|
||||||
|
//get all Countries//
|
||||||
|
///////////////////*/
|
||||||
|
stmt = c.createStatement();
|
||||||
|
String queryCountry = "SELECT * FROM `"+this.name+"_Country`";
|
||||||
|
rs = stmt.executeQuery(queryCountry);
|
||||||
|
while ( rs.next() ){
|
||||||
|
//Country(String DST, String name)
|
||||||
|
String countName = rs.getString("Country_Name");
|
||||||
|
String countDST = rs.getString("DST");
|
||||||
|
countries.add(new Country(countDST, countName));
|
||||||
|
}
|
||||||
|
rs.close();
|
||||||
|
stmt.close();
|
||||||
|
/*/////////////////////
|
||||||
|
//get all Flight Path//
|
||||||
|
/////////////////////*/
|
||||||
|
stmt = c.createStatement();
|
||||||
|
String queryFlightPath = "SELECT * FROM `"+this.name+"_Flight_Path`";
|
||||||
|
rs = stmt.executeQuery(queryFlightPath);
|
||||||
|
while ( rs.next() ){
|
||||||
|
//FlightPath(int ID, String departureAirport, String arrivalAirport)
|
||||||
|
int flightpID = rs.getInt("Path_ID");
|
||||||
|
String flightpDepart = rs.getString("Source_Airport");
|
||||||
|
String flightpArrive = rs.getString("Destination_Airport");
|
||||||
|
flightPaths.add(new FlightPath(flightpID, flightpDepart, flightpArrive));
|
||||||
|
}
|
||||||
|
rs.close();
|
||||||
|
stmt.close();
|
||||||
|
/*///////////////////////
|
||||||
|
//get all flight points//
|
||||||
|
///////////////////////*/
|
||||||
|
for (int i = 0; i < flightPaths.size(); i++){
|
||||||
|
stmt = c.createStatement();
|
||||||
|
String queryFlightPoints = "SELECT * FROM `" + this.name + "_Flight_Points` WHERE `Index_ID` = "+flightPaths.get(i).getID() + " ORDER BY `Order` ASC";
|
||||||
|
rs = stmt.executeQuery(queryFlightPoints);
|
||||||
|
while (rs.next()) {
|
||||||
|
//FlightPoint(String name, int ID, int indexID, String type, String via,
|
||||||
|
//int heading, double altitude, double legDistance, double totalDistance,
|
||||||
|
//double latitude, double longitude)
|
||||||
|
String flightPtName = rs.getString("Name");
|
||||||
|
int flightPtID = rs.getInt("Point_ID");
|
||||||
|
int flightPtInd = rs.getInt("Index_ID");
|
||||||
|
String flightPtType = rs.getString("Type");
|
||||||
|
String flightPtVia = rs.getString("Via");
|
||||||
|
int flightPtheading = rs.getInt("Heading");
|
||||||
|
double flightPtAltitude = rs.getDouble("Altitude");
|
||||||
|
double flightPtLegDistance = rs.getDouble("Leg_Dist");
|
||||||
|
double flightPtTotDist = rs.getDouble("Tot_Dist");
|
||||||
|
double flightPtLatitude = rs.getDouble("Latitude");
|
||||||
|
double flightPtLongitude = rs.getDouble("Longitude");
|
||||||
|
flightPaths.get(i).addFlightPoint(new FlightPoint(flightPtName, flightPtID, flightPtInd
|
||||||
|
, flightPtType, flightPtVia, flightPtheading, flightPtAltitude, flightPtLegDistance, flightPtTotDist,
|
||||||
|
flightPtLatitude, flightPtLongitude));
|
||||||
|
}
|
||||||
|
rs.close();
|
||||||
|
stmt.close();
|
||||||
|
}
|
||||||
|
/*////////////////
|
||||||
|
//Get all Routes//
|
||||||
|
////////////////*/
|
||||||
|
stmt = c.createStatement();
|
||||||
|
String queryRoute = "SELECT * FROM `"+this.name+"_Routes`";
|
||||||
|
rs = stmt.executeQuery(queryRoute);
|
||||||
|
while ( rs.next() ){
|
||||||
|
//Route(int ID, String airline, String departureAirport, String arrivalAirport,
|
||||||
|
//String codeShare, int stops, String equipment)
|
||||||
|
int routeID = rs.getInt("Route_ID");
|
||||||
|
String routeAirline = rs.getString("Airline");
|
||||||
|
String routeDestAirport = rs.getString("Source_Airport");
|
||||||
|
String routeArrvAirport = rs.getString("Destination_Airport");
|
||||||
|
String routeCodeShare = rs.getString("Codeshare");
|
||||||
|
int routeStops = rs.getInt("Stops");
|
||||||
|
String routeEquip = rs.getString("Equipment");
|
||||||
|
routes.add(new Route(routeID, routeAirline, routeDestAirport, routeArrvAirport, routeCodeShare, routeStops, routeEquip));
|
||||||
|
}
|
||||||
|
rs.close();
|
||||||
|
stmt.close();
|
||||||
|
c.close();
|
||||||
|
} catch ( Exception e ) {
|
||||||
|
System.err.println( e.getClass().getName() + ": " + e.getMessage() );
|
||||||
|
System.exit(0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void createTables() throws DataException{
|
||||||
|
Connection c = null;
|
||||||
|
Statement stmt = null;
|
||||||
|
int numOfDuplicateNames = 0;
|
||||||
|
try {
|
||||||
|
Class.forName("org.sqlite.JDBC");
|
||||||
|
c = DriverManager.getConnection("jdbc:sqlite:res/userdb.db");
|
||||||
|
stmt = c.createStatement();
|
||||||
|
String queryName = this.name.replace("'", "''").replace("\"", "\"");//this allows quotes in datasets
|
||||||
|
ResultSet rs = stmt.executeQuery( "SELECT COUNT(*) FROM `Datasets` WHERE `Dataset_Name` = '"+queryName+"';" );
|
||||||
|
while ( rs.next() ) {
|
||||||
|
numOfDuplicateNames = rs.getInt("COUNT(*)");
|
||||||
|
}
|
||||||
|
if (numOfDuplicateNames > 0){
|
||||||
|
throw new DataException("There is already a Dataset with this Name.");
|
||||||
|
}
|
||||||
|
stmt.close();
|
||||||
|
rs.close();
|
||||||
|
//if no problem create tables;
|
||||||
|
//create airline table;
|
||||||
|
stmt = c.createStatement();
|
||||||
|
String createAirlineQuery = "CREATE TABLE `"+this.name+"_Airline` " +
|
||||||
|
"(`Airline_ID` INTEGER PRIMARY KEY AUTOINCREMENT UNIQUE, " +
|
||||||
|
"`Name` TEXT, " +
|
||||||
|
"`Alias` TEXT, " +
|
||||||
|
"`IATA` VARCHAR(2), " +
|
||||||
|
"`ICAO` VARCHAR(3), " +
|
||||||
|
"`Callsign` TEXT, " +
|
||||||
|
"`Country` TEXT, " +
|
||||||
|
"`Active` VARCHAR(1));";
|
||||||
|
stmt.execute(createAirlineQuery);
|
||||||
|
stmt.close();
|
||||||
|
//create airport table;
|
||||||
|
stmt = c.createStatement();
|
||||||
|
String createAirportQuery = "CREATE TABLE `"+this.name+"_Airport` " +
|
||||||
|
"(`Airport_ID` INTEGER PRIMARY KEY AUTOINCREMENT UNIQUE, " +
|
||||||
|
"`Name` TEXT, " +
|
||||||
|
"`City` TEXT, " +
|
||||||
|
"`Country` TEXT, " +
|
||||||
|
"`IATA/FFA` VARCHAR(3), " +
|
||||||
|
"`ICAO` VARCHAR(4), " +
|
||||||
|
"`Latitude` REAL, " +
|
||||||
|
"`Longitude` REAL, " +
|
||||||
|
"`Altitude` REAL);";
|
||||||
|
stmt.execute(createAirportQuery);
|
||||||
|
stmt.close();
|
||||||
|
//create City table;
|
||||||
|
stmt = c.createStatement();
|
||||||
|
String createCityTable = "CREATE TABLE `"+this.name+"_City` " +
|
||||||
|
"(`City_Name` TEXT UNIQUE, " +
|
||||||
|
"`Country_Name` TEXT, " +
|
||||||
|
"`Timezone` REAL, " +
|
||||||
|
"`Olson_Timezone` TEXT)";
|
||||||
|
stmt.execute(createCityTable);
|
||||||
|
stmt.close();
|
||||||
|
//create Country Table
|
||||||
|
stmt = c.createStatement();
|
||||||
|
String createCountryTable = "CREATE TABLE `"+this.name+"_Country` " +
|
||||||
|
"(`Country_Name` TEXT UNIQUE, " +
|
||||||
|
"`DST` VARCHAR(1))";
|
||||||
|
stmt.execute(createCountryTable);
|
||||||
|
stmt.close();
|
||||||
|
//create flightpath table
|
||||||
|
stmt = c.createStatement();
|
||||||
|
String createFlightPathTable = "CREATE TABLE `"+this.name+"_Flight_Path` " +
|
||||||
|
"(`Path_ID` INTEGER PRIMARY KEY AUTOINCREMENT UNIQUE, " +
|
||||||
|
"`Source_Airport` TEXT, " +
|
||||||
|
"`Destination_Airport` TEXT)";
|
||||||
|
stmt.execute(createFlightPathTable);
|
||||||
|
//create flight point table
|
||||||
|
stmt = c.createStatement();
|
||||||
|
String createFlightPointTable = "CREATE TABLE `"+this.name+"_Flight_Points` " +
|
||||||
|
"(`Index_ID` INTEGER ," +
|
||||||
|
"`Name` TEXT, " +
|
||||||
|
"`Point_ID` INTEGER PRIMARY KEY AUTOINCREMENT UNIQUE, " +
|
||||||
|
"`Type` TEXT, " +
|
||||||
|
"`Via` TEXT, " +
|
||||||
|
"`Heading` TEXT, " +
|
||||||
|
"`Altitude` INTEGER, " +
|
||||||
|
"`Tot_Dist` INTEGER, " +
|
||||||
|
"`Longitude` REAL, " +
|
||||||
|
"`Latitude` REAL, " +
|
||||||
|
"`Leg_Dist` INTEGER, " +
|
||||||
|
"`Order` INTEGER)";
|
||||||
|
stmt.execute(createFlightPointTable);
|
||||||
|
stmt.close();
|
||||||
|
//create routes table
|
||||||
|
stmt = c.createStatement();
|
||||||
|
String createRoutesTable = "CREATE TABLE `"+this.name+"_Routes` " +
|
||||||
|
"(`Route_ID` INTEGER PRIMARY KEY AUTOINCREMENT UNIQUE, " +
|
||||||
|
"`Airline` TEXT, " +
|
||||||
|
"`Source_Airport` TEXT, " +
|
||||||
|
"`Destination_Airport` TEXT, " +
|
||||||
|
"`Codeshare` VARCHAR(1), " +
|
||||||
|
"`Stops` INTEGER, " +
|
||||||
|
"`Equipment` TEXT)";
|
||||||
|
stmt.execute(createRoutesTable);
|
||||||
|
stmt.close();
|
||||||
|
//insert dataset into table
|
||||||
|
stmt = c.createStatement();
|
||||||
|
String insertDataset = "INSERT INTO `Datasets` (`Dataset_Name`) VALUES ('"+queryName+"');";
|
||||||
|
stmt.execute(insertDataset);
|
||||||
|
stmt.close();
|
||||||
|
c.close();
|
||||||
|
} catch ( Exception e ) {
|
||||||
|
System.err.println( e.getClass().getName() + ": " + e.getMessage() );
|
||||||
|
System.exit(0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -1,5 +0,0 @@
|
|||||||
package seng202.group9.Controller;
|
|
||||||
|
|
||||||
public class DatasetController {
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,158 @@
|
|||||||
|
package seng202.group9.Controller;
|
||||||
|
|
||||||
|
import seng202.group9.Core.FlightPoint;
|
||||||
|
|
||||||
|
import java.io.*;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
|
||||||
|
public class FlightPathParser extends Parser {
|
||||||
|
String filePath = "";
|
||||||
|
ArrayList<FlightPoint> parsedPoints;
|
||||||
|
|
||||||
|
public FlightPathParser(String filePath){
|
||||||
|
this.filePath = filePath;
|
||||||
|
parsedPoints = new ArrayList<FlightPoint>();
|
||||||
|
}
|
||||||
|
|
||||||
|
public String parse() throws DataException{
|
||||||
|
int successful = 0;
|
||||||
|
int error = 0;
|
||||||
|
int duplicate = 0;
|
||||||
|
|
||||||
|
File file = new File(filePath);
|
||||||
|
BufferedReader reader = null;
|
||||||
|
|
||||||
|
try {
|
||||||
|
reader = new BufferedReader(new FileReader(file));
|
||||||
|
String line = null;
|
||||||
|
|
||||||
|
while ((line = reader.readLine()) != null) {
|
||||||
|
//read file here
|
||||||
|
//(String type, String via, double altitude, double latitude, double longitude
|
||||||
|
//APT,NZCH,0,-43.48664019,172.53368221
|
||||||
|
String flightPtType = "";
|
||||||
|
String flightPtVia = "";
|
||||||
|
double flightPtAltitude = 0.0;
|
||||||
|
double flightPtLat = 0.0;
|
||||||
|
double flightPtLong = 0.0;
|
||||||
|
//line = line.replaceAll("\"", "");
|
||||||
|
String parts[] = {"", "", "", "", ""};
|
||||||
|
int part = 0;
|
||||||
|
boolean inQuotes = false;
|
||||||
|
for (int i = 0; i < line.length(); i ++){
|
||||||
|
if (line.charAt(i) == ','){
|
||||||
|
if (inQuotes == true){
|
||||||
|
parts[part] += line.charAt(i);
|
||||||
|
}else{
|
||||||
|
part++;
|
||||||
|
}
|
||||||
|
}else if (line.charAt(i) == '\"'){
|
||||||
|
inQuotes = !inQuotes;
|
||||||
|
}else {
|
||||||
|
parts[part] += line.charAt(i);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//System.out.println(parts[0] + " | " + parts[1] + " | " + parts[2] + " | " + parts[3] + " | " + parts[4] + " | "
|
||||||
|
// + parts[5] + " | " + parts[6] + " | " + parts[7] + " | " + parts[8] + " | " + parts[9] + " | " + parts[10] + " | " + parts[11]);
|
||||||
|
//check length this may need to be optional depending on size as the lecturers have given us size 5 while the websites give a lot more
|
||||||
|
if (parts.length != 5){
|
||||||
|
System.out.println(parts[1] + " does not have 5 entries.");
|
||||||
|
error++;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
//check types I = integer, S = String D = Double P = Pass
|
||||||
|
char partTypes[] = {'S', 'S', 'D', 'D', 'D'};
|
||||||
|
boolean errorBreak = false;
|
||||||
|
for (int i = 0; i < partTypes.length; i ++){
|
||||||
|
if(partTypes[i] == 'P'){
|
||||||
|
//if P it is a pass
|
||||||
|
} else if (partTypes[i] == 'I'){
|
||||||
|
try {
|
||||||
|
if (parts[i].equals("\\N")){
|
||||||
|
parts[i] = "0";
|
||||||
|
}
|
||||||
|
Integer.parseInt(parts[i]);
|
||||||
|
}catch (NumberFormatException e){
|
||||||
|
System.out.println(parts[1] + " has Value: " + parts[i] + " And is not a Integer Formattable Value.");
|
||||||
|
error++;
|
||||||
|
errorBreak = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}else if (partTypes[i] == 'D'){
|
||||||
|
try{
|
||||||
|
if (parts[i].equals("\\N")){
|
||||||
|
parts[i] = "0";
|
||||||
|
}
|
||||||
|
Double.parseDouble(parts[i]);
|
||||||
|
}catch (NumberFormatException e){
|
||||||
|
System.out.println(parts[1] + " has Value: " + parts[i] + " And is not a Double Formattable Value.");
|
||||||
|
error++;
|
||||||
|
errorBreak = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (errorBreak == true){
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
//cehck sizes of [][] eg {3,0} will check if length == 3 or == 0. if -1 the size is ignored
|
||||||
|
int partSizes[][] = {{3}, {-1}, {-1}, {-1}, {-1}};
|
||||||
|
for (int i = 0; i < partSizes.length; i ++){
|
||||||
|
boolean passable = false;
|
||||||
|
for (int j = 0; j < partSizes[i].length; j++){
|
||||||
|
if (partSizes[i][j] != -1) {
|
||||||
|
if (parts[i].equals("\\N")){
|
||||||
|
parts[i] = "";
|
||||||
|
}
|
||||||
|
if (parts[i].length() == partSizes[i][j]) {
|
||||||
|
passable = true;
|
||||||
|
}
|
||||||
|
}else{
|
||||||
|
passable = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (passable == false){
|
||||||
|
System.out.println(parts[1] + " has Length: " + parts[i].length() + ", Value: " + parts[i] + " @ Index: " + i);
|
||||||
|
error++;
|
||||||
|
errorBreak = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (errorBreak == true){
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
//passing is done now add stuff to array
|
||||||
|
//(String type, String via, double altitude, double latitude, double longitude
|
||||||
|
flightPtType = parts[0];
|
||||||
|
flightPtVia = parts[1];
|
||||||
|
flightPtAltitude = Double.parseDouble(parts[2]);
|
||||||
|
flightPtLat = Double.parseDouble(parts[3]);
|
||||||
|
flightPtLong = Double.parseDouble(parts[4]);
|
||||||
|
parsedPoints.add(new FlightPoint(flightPtType, flightPtVia, flightPtAltitude, flightPtLat, flightPtLong));
|
||||||
|
successful++;
|
||||||
|
}
|
||||||
|
} catch (FileNotFoundException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
throw new DataException("File: " +this.filePath+" is Missing.");
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
throw new DataException(this.filePath + " is Corrupted.");
|
||||||
|
} finally {
|
||||||
|
try {
|
||||||
|
if (reader != null) {
|
||||||
|
reader.close();
|
||||||
|
}
|
||||||
|
} catch (IOException e) {
|
||||||
|
throw new DataException(this.filePath + " is unable to initialise reader.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return String.format("Entries Successfully Entered: %1$d.\n" +
|
||||||
|
"Entries With Errors: %2$d", successful, error);
|
||||||
|
}
|
||||||
|
|
||||||
|
public ArrayList<FlightPoint> getResult(){
|
||||||
|
return parsedPoints;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
package seng202.group9.Controller;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
|
||||||
|
public abstract class Parser {
|
||||||
|
|
||||||
|
abstract String parse() throws DataException;
|
||||||
|
}
|
||||||
@@ -0,0 +1,160 @@
|
|||||||
|
package seng202.group9.Controller;
|
||||||
|
|
||||||
|
import seng202.group9.Core.Route;
|
||||||
|
|
||||||
|
import java.io.*;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
|
||||||
|
public class RouteParser extends Parser {
|
||||||
|
String filePath = "";
|
||||||
|
ArrayList<Route> parsedRoutes;
|
||||||
|
|
||||||
|
public RouteParser(String filePath){
|
||||||
|
this.filePath = filePath;
|
||||||
|
parsedRoutes = new ArrayList<Route>();
|
||||||
|
}
|
||||||
|
|
||||||
|
public String parse() throws DataException{
|
||||||
|
int successful = 0;
|
||||||
|
int error = 0;
|
||||||
|
int duplicate = 0;
|
||||||
|
|
||||||
|
File file = new File(filePath);
|
||||||
|
BufferedReader reader = null;
|
||||||
|
|
||||||
|
try {
|
||||||
|
reader = new BufferedReader(new FileReader(file));
|
||||||
|
String line = null;
|
||||||
|
|
||||||
|
while ((line = reader.readLine()) != null) {
|
||||||
|
//read file here
|
||||||
|
//String airline, airline id, String departureAirport, airport id, String arrivalAirport, arrival airport id, String codeShare, int stops, String equipment
|
||||||
|
//sample line: 2B,410,AER,2965,KZN,2990,,0,CR2
|
||||||
|
String routeAirName = "";
|
||||||
|
String routeDepart = "";
|
||||||
|
String routeArrive = "";
|
||||||
|
String routeCodeshare = "";
|
||||||
|
int routeStops = 0;
|
||||||
|
String routeEquip = "";
|
||||||
|
//line = line.replaceAll("\"", "");
|
||||||
|
String parts[] = {"", "", "", "", "", "", "", "", ""};
|
||||||
|
int part = 0;
|
||||||
|
boolean inQuotes = false;
|
||||||
|
for (int i = 0; i < line.length(); i ++){
|
||||||
|
if (line.charAt(i) == ','){
|
||||||
|
if (inQuotes == true){
|
||||||
|
parts[part] += line.charAt(i);
|
||||||
|
}else{
|
||||||
|
part++;
|
||||||
|
}
|
||||||
|
}else if (line.charAt(i) == '\"'){
|
||||||
|
inQuotes = !inQuotes;
|
||||||
|
}else {
|
||||||
|
parts[part] += line.charAt(i);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//System.out.println(parts[0] + " | " + parts[1] + " | " + parts[2] + " | " + parts[3] + " | " + parts[4] + " | "
|
||||||
|
// + parts[5] + " | " + parts[6] + " | " + parts[7] + " | " + parts[8] + " | " + parts[9] + " | " + parts[10] + " | " + parts[11]);
|
||||||
|
//check length
|
||||||
|
if (parts.length != 9){
|
||||||
|
System.out.println(parts[1] + " does not have 9 entries.");
|
||||||
|
error++;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
//check types I = integer, S = String D = Double P = Pass
|
||||||
|
char partTypes[] = {'S', 'P', 'S','P', 'S', 'P', 'S', 'I', 'S'};
|
||||||
|
boolean errorBreak = false;
|
||||||
|
for (int i = 0; i < partTypes.length; i ++){
|
||||||
|
if(partTypes[i] == 'P'){
|
||||||
|
//if P it is a pass
|
||||||
|
} else if (partTypes[i] == 'I'){
|
||||||
|
try {
|
||||||
|
if (parts[i].equals("\\N")){
|
||||||
|
parts[i] = "0";
|
||||||
|
}
|
||||||
|
Integer.parseInt(parts[i]);
|
||||||
|
}catch (NumberFormatException e){
|
||||||
|
System.out.println(parts[1] + " has Value: " + parts[i] + " And is not a Integer Formattable Value.");
|
||||||
|
error++;
|
||||||
|
errorBreak = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}else if (partTypes[i] == 'D'){
|
||||||
|
try{
|
||||||
|
if (parts[i].equals("\\N")){
|
||||||
|
parts[i] = "0";
|
||||||
|
}
|
||||||
|
Double.parseDouble(parts[i]);
|
||||||
|
}catch (NumberFormatException e){
|
||||||
|
System.out.println(parts[1] + " has Value: " + parts[i] + " And is not a Double Formattable Value.");
|
||||||
|
error++;
|
||||||
|
errorBreak = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (errorBreak == true){
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
//cehck sizes of [][] eg {3,0} will check if length == 3 or == 0. if -1 the size is ignored
|
||||||
|
int partSizes[][] = {{2,3}, {-1}, {3,4}, {-1}, {3,4}, {-1}, {1,0}, {-1}, {-1}};
|
||||||
|
for (int i = 0; i < partSizes.length; i ++){
|
||||||
|
boolean passable = false;
|
||||||
|
for (int j = 0; j < partSizes[i].length; j++){
|
||||||
|
if (partSizes[i][j] != -1) {
|
||||||
|
if (parts[i].equals("\\N")){
|
||||||
|
parts[i] = "";
|
||||||
|
}
|
||||||
|
if (parts[i].length() == partSizes[i][j]) {
|
||||||
|
passable = true;
|
||||||
|
}
|
||||||
|
}else{
|
||||||
|
passable = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (passable == false){
|
||||||
|
System.out.println(parts[1] + " has Length: " + parts[i].length() + ", Value: " + parts[i] + " @ Index: " + i);
|
||||||
|
error++;
|
||||||
|
errorBreak = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (errorBreak == true){
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
//passing is done now add stuff to array
|
||||||
|
//String airline, airline id, String departureAirport, airport id, String arrivalAirport, arrival airport id, String codeShare, int stops, String equipment
|
||||||
|
routeAirName = parts[0];
|
||||||
|
routeDepart = parts[1];
|
||||||
|
routeArrive = parts[2];
|
||||||
|
routeCodeshare = parts[3];
|
||||||
|
routeStops = Integer.parseInt(parts[4]);
|
||||||
|
routeEquip = parts[5];
|
||||||
|
parsedRoutes.add(new Route(routeAirName, routeDepart, routeArrive, routeCodeshare, routeStops, routeEquip));
|
||||||
|
successful++;
|
||||||
|
}
|
||||||
|
} catch (FileNotFoundException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
throw new DataException("File: " +this.filePath+" is Missing.");
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
throw new DataException(this.filePath + " is Corrupted.");
|
||||||
|
} finally {
|
||||||
|
try {
|
||||||
|
if (reader != null) {
|
||||||
|
reader.close();
|
||||||
|
}
|
||||||
|
} catch (IOException e) {
|
||||||
|
throw new DataException(this.filePath + " is unable to initialise reader.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return String.format("Entries Successfully Entered: %1$d.\n" +
|
||||||
|
"Entries With Errors: %2$d", successful, error);
|
||||||
|
}
|
||||||
|
|
||||||
|
public ArrayList<Route> getResult(){
|
||||||
|
return parsedRoutes;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -1,5 +1,7 @@
|
|||||||
package seng202.group9.Core;
|
package seng202.group9.Core;
|
||||||
|
|
||||||
|
import seng202.group9.Controller.DataException;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -42,6 +44,18 @@ public class Airline {
|
|||||||
this.routes = new ArrayList<Route>();
|
this.routes = new ArrayList<Route>();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public Airline(String name, String alias, String IATA, String ICAO, String callSign, String country, String active){
|
||||||
|
this.ID = -1;
|
||||||
|
this.IATA = IATA;
|
||||||
|
this.ICAO = ICAO;
|
||||||
|
this.name = name;
|
||||||
|
this.alias = alias;
|
||||||
|
this.callSign = callSign;
|
||||||
|
this.active = active;
|
||||||
|
this.country = country;
|
||||||
|
this.routes = new ArrayList<Route>();
|
||||||
|
}
|
||||||
/**
|
/**
|
||||||
* Changes the ID of the Airline this is correlated to the database.
|
* Changes the ID of the Airline this is correlated to the database.
|
||||||
* @param iD
|
* @param iD
|
||||||
@@ -117,9 +131,13 @@ public class Airline {
|
|||||||
* get the ID of relative to the database
|
* get the ID of relative to the database
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public int getID(){
|
public int getID() throws DataException {
|
||||||
|
if (this.ID == -1){
|
||||||
|
throw new DataException("ID not set.");
|
||||||
|
}else{
|
||||||
return ID;
|
return ID;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
/**
|
/**
|
||||||
* get the IATA code
|
* get the IATA code
|
||||||
* @return
|
* @return
|
||||||
@@ -194,6 +212,22 @@ public class Airline {
|
|||||||
routes.add(routesToAdd.get(i));
|
routes.add(routesToAdd.get(i));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* deletes a route by matching the route class/pointer in routes array keep in mind that the array position will change for all indexs after this.
|
||||||
|
* @param route
|
||||||
|
*/
|
||||||
|
public void delRoutes(Route route){
|
||||||
|
routes.remove(route);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* deletes a route by matching index keep in mind that the array position will change for all indexs after this.
|
||||||
|
* @param index
|
||||||
|
*/
|
||||||
|
public void delRoutes(int index){
|
||||||
|
routes.remove(index);
|
||||||
|
}
|
||||||
/**
|
/**
|
||||||
* returns the name of the airline when concatenated to a string.
|
* returns the name of the airline when concatenated to a string.
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -17,6 +17,7 @@ public class Airport {
|
|||||||
private double longitude;
|
private double longitude;
|
||||||
private double latitude;
|
private double latitude;
|
||||||
private String city;
|
private String city;
|
||||||
|
private String country;
|
||||||
private ArrayList<Route> departureRoutes = new ArrayList<Route>();
|
private ArrayList<Route> departureRoutes = new ArrayList<Route>();
|
||||||
private ArrayList<Route> arrivalRoutes = new ArrayList<Route>();
|
private ArrayList<Route> arrivalRoutes = new ArrayList<Route>();
|
||||||
|
|
||||||
@@ -31,7 +32,7 @@ public class Airport {
|
|||||||
* @param longitude
|
* @param longitude
|
||||||
* @param latitude
|
* @param latitude
|
||||||
*/
|
*/
|
||||||
public Airport(int ID, String name, String city, String IATA_FFA, String ICAO, double latitude, double longitude
|
public Airport(int ID, String name, String city, String country, String IATA_FFA, String ICAO, double latitude, double longitude
|
||||||
, double altitude){
|
, double altitude){
|
||||||
this.ID = ID;
|
this.ID = ID;
|
||||||
this.name = name;
|
this.name = name;
|
||||||
@@ -41,6 +42,7 @@ public class Airport {
|
|||||||
this.longitude = longitude;
|
this.longitude = longitude;
|
||||||
this.latitude = latitude;
|
this.latitude = latitude;
|
||||||
this.city = city;
|
this.city = city;
|
||||||
|
this.country = country;
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* Secondary Constructor the ID needs to be set after.
|
* Secondary Constructor the ID needs to be set after.
|
||||||
@@ -51,7 +53,7 @@ public class Airport {
|
|||||||
* @param longitude
|
* @param longitude
|
||||||
* @param latitude
|
* @param latitude
|
||||||
*/
|
*/
|
||||||
public Airport(String name, String city, String IATA_FFA, String ICAO, double latitude, double longitude
|
public Airport(String name, String city, String country, String IATA_FFA, String ICAO, double latitude, double longitude
|
||||||
, double altitude){
|
, double altitude){
|
||||||
this.ID = -1;
|
this.ID = -1;
|
||||||
this.name = name;
|
this.name = name;
|
||||||
@@ -61,6 +63,7 @@ public class Airport {
|
|||||||
this.longitude = longitude;
|
this.longitude = longitude;
|
||||||
this.latitude = latitude;
|
this.latitude = latitude;
|
||||||
this.city = city;
|
this.city = city;
|
||||||
|
this.country = country;
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* returns the IATA/FFA code
|
* returns the IATA/FFA code
|
||||||
@@ -148,7 +151,7 @@ public class Airport {
|
|||||||
public void setArrivalRoutes(ArrayList<Route> arrivalRoutes) {
|
public void setArrivalRoutes(ArrayList<Route> arrivalRoutes) {
|
||||||
//the array list must be clones else future errors may occur
|
//the array list must be clones else future errors may occur
|
||||||
this.arrivalRoutes = new ArrayList<Route>();
|
this.arrivalRoutes = new ArrayList<Route>();
|
||||||
for (int i = 0; i < departureRoutes.size(); i ++){
|
for (int i = 0; i < arrivalRoutes.size(); i ++){
|
||||||
this.arrivalRoutes.add(arrivalRoutes.get(i));
|
this.arrivalRoutes.add(arrivalRoutes.get(i));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -235,6 +238,15 @@ public class Airport {
|
|||||||
public void addDepartureRoutes(Route route){
|
public void addDepartureRoutes(Route route){
|
||||||
departureRoutes.add(route);
|
departureRoutes.add(route);
|
||||||
}
|
}
|
||||||
|
/**
|
||||||
|
* Adds each member of routes to array list;
|
||||||
|
* @param routes
|
||||||
|
*/
|
||||||
|
public void addDepartureRoutes(ArrayList<Route> routes){
|
||||||
|
for (int i = 0; i < routes.size(); i ++){
|
||||||
|
addDepartureRoutes(routes.get(i));
|
||||||
|
}
|
||||||
|
}
|
||||||
/**
|
/**
|
||||||
* add arriving routes to this airport
|
* add arriving routes to this airport
|
||||||
* @param route
|
* @param route
|
||||||
@@ -242,12 +254,38 @@ public class Airport {
|
|||||||
public void addArrivalRoutes(Route route){
|
public void addArrivalRoutes(Route route){
|
||||||
arrivalRoutes.add(route);
|
arrivalRoutes.add(route);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Adds each member of routes to array list;
|
||||||
|
* @param routes
|
||||||
|
*/
|
||||||
|
public void addArrivalRoutes(ArrayList<Route> routes){
|
||||||
|
for (int i = 0; i < routes.size(); i ++){
|
||||||
|
addArrivalRoutes(routes.get(i));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* deletes a member of arrival routes by matching route pointer
|
||||||
|
* @param route
|
||||||
|
*/
|
||||||
|
public void delArrivalRoutes(Route route){
|
||||||
|
arrivalRoutes.remove(route);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* deletes a member of arrival routes by index
|
||||||
|
* @param index
|
||||||
|
*/
|
||||||
|
public void delArrivalRoutes(int index){
|
||||||
|
arrivalRoutes.remove(index);
|
||||||
|
}
|
||||||
/**
|
/**
|
||||||
* Information of the airport returned in String format.
|
* Information of the airport returned in String format.
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public String toString(){
|
public String toString(){
|
||||||
return this.city+" Airport has ICAO: "+this.ICAO+", IATA/FFA: "+this.IATA_FFA+" and is located at ("+this.latitude+", "+this.longitude
|
return this.city+" Airport has ICAO: "+this.ICAO+", IATA/FFA: "+this.IATA_FFA+" and is located at ("+this.latitude+", "+this.longitude
|
||||||
+ ").\n It has "+this.departureRoutes.size()+" departing routes and "+this.arrivalRoutes+" arriving routes.";
|
+ ").\n It has "+this.departureRoutes.size()+" departing routes and "+this.arrivalRoutes.size()+" arriving routes.";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,12 +4,14 @@ import java.util.ArrayList;
|
|||||||
|
|
||||||
public class City {
|
public class City {
|
||||||
private String name;
|
private String name;
|
||||||
private String timezone;
|
private String country;
|
||||||
|
private double timezone;
|
||||||
private String timeOlson;
|
private String timeOlson;
|
||||||
private ArrayList<Airport> airports;
|
private ArrayList<Airport> airports;
|
||||||
|
|
||||||
public City(String name, String timezone, String timeOlson){
|
public City(String name, String country, double timezone, String timeOlson){
|
||||||
this.name = name;
|
this.name = name;
|
||||||
|
this.country = country;
|
||||||
this.timezone = timezone;
|
this.timezone = timezone;
|
||||||
this.timeOlson = timeOlson;
|
this.timeOlson = timeOlson;
|
||||||
this.airports = new ArrayList<Airport>();
|
this.airports = new ArrayList<Airport>();
|
||||||
@@ -19,7 +21,11 @@ public class City {
|
|||||||
this.name = name;
|
this.name = name;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setTimezone(String timezone) {
|
public void setCountry(String country){
|
||||||
|
this.country = country;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setTimezone(double timezone) {
|
||||||
this.timezone = timezone;
|
this.timezone = timezone;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -28,14 +34,22 @@ public class City {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void setAirports(ArrayList<Airport> airports) {
|
public void setAirports(ArrayList<Airport> airports) {
|
||||||
this.airports = airports;
|
this.airports = new ArrayList<Airport>();
|
||||||
|
for (int i = 0; i < airports.size(); i ++) {
|
||||||
|
this.airports.add(airports.get(i));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getName(){
|
public String getName(){
|
||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getTimezone(){
|
public String getCountry(){
|
||||||
|
return country;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public double getTimezone(){
|
||||||
return timezone;
|
return timezone;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -50,4 +64,22 @@ public class City {
|
|||||||
public void addAirport(Airport airport){
|
public void addAirport(Airport airport){
|
||||||
airports.add(airport);
|
airports.add(airport);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void addAirport(ArrayList<Airport> airports){
|
||||||
|
for (int i = 0; i < airports.size(); i++){
|
||||||
|
addAirport(airports.get(i));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void delAirport(Airport airport){
|
||||||
|
airports.remove(airport);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void delAirport(int index) {
|
||||||
|
airports.remove(index);
|
||||||
|
}
|
||||||
|
@Override
|
||||||
|
public String toString(){
|
||||||
|
return this.name;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import java.util.ArrayList;
|
|||||||
|
|
||||||
public class Country {
|
public class Country {
|
||||||
private String DST, name;
|
private String DST, name;
|
||||||
|
private ArrayList<City> cities = new ArrayList<City>();
|
||||||
private ArrayList<Airline> airlines = new ArrayList<Airline>();
|
private ArrayList<Airline> airlines = new ArrayList<Airline>();
|
||||||
|
|
||||||
public Country(String DST, String name){
|
public Country(String DST, String name){
|
||||||
@@ -20,7 +21,10 @@ public class Country {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void setAirlines(ArrayList<Airline> airlines) {
|
public void setAirlines(ArrayList<Airline> airlines) {
|
||||||
this.airlines = airlines;
|
this.airlines = new ArrayList<Airline>();
|
||||||
|
for (int i = 0; i < airlines.size(); i ++) {
|
||||||
|
this.airlines.add(airlines.get(i));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getDST(){
|
public String getDST(){
|
||||||
@@ -38,4 +42,43 @@ public class Country {
|
|||||||
public void addAirline(Airline airline){
|
public void addAirline(Airline airline){
|
||||||
this.airlines.add(airline);
|
this.airlines.add(airline);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void addAirline(ArrayList<Airline> airlines){
|
||||||
|
for (int i = 0; i < airlines.size(); i++){
|
||||||
|
addAirline(airlines.get(i));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void delAirline(Airline airline){
|
||||||
|
airlines.remove(airline);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void delAirline(int index){
|
||||||
|
airlines.remove(index);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setCities(ArrayList<City> cities){
|
||||||
|
this.cities = new ArrayList<City>();
|
||||||
|
for (int i = 0; i < cities.size(); i++){
|
||||||
|
this.cities.add(cities.get(i));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addCities(City city){
|
||||||
|
this.cities.add(city);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addCities(ArrayList<City> cities){
|
||||||
|
for (int i = 0; i < cities.size(); i++){
|
||||||
|
this.cities.add(cities.get(i));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void delCities(City city){
|
||||||
|
this.cities.remove(city);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void delCities(int index){
|
||||||
|
this.cities.remove(index);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,10 +5,16 @@ import java.util.ArrayList;
|
|||||||
public class FlightPath {
|
public class FlightPath {
|
||||||
private int ID;
|
private int ID;
|
||||||
private ArrayList<FlightPoint> flightPoints;
|
private ArrayList<FlightPoint> flightPoints;
|
||||||
private Airport departureAirport;
|
private String departureAirport;
|
||||||
private Airport arrivalAirport;
|
private String arrivalAirport;
|
||||||
|
|
||||||
public FlightPath(int ID, Airport departureAirport, Airport arrivalAirport){
|
/**
|
||||||
|
*
|
||||||
|
* @param ID id of the the flight path in the database
|
||||||
|
* @param departureAirport Iata/FFA of the airport
|
||||||
|
* @param arrivalAirport IATA/FFA of the airport
|
||||||
|
*/
|
||||||
|
public FlightPath(int ID, String departureAirport, String arrivalAirport){
|
||||||
this.ID = ID;
|
this.ID = ID;
|
||||||
this.departureAirport = departureAirport;
|
this.departureAirport = departureAirport;
|
||||||
this.arrivalAirport = arrivalAirport;
|
this.arrivalAirport = arrivalAirport;
|
||||||
@@ -20,22 +26,17 @@ public class FlightPath {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void setFlightPoints(ArrayList<FlightPoint> flightPoints) {
|
public void setFlightPoints(ArrayList<FlightPoint> flightPoints) {
|
||||||
|
this.flightPoints = new ArrayList<FlightPoint>();
|
||||||
|
for (int i = 0; i < flightPoints.size(); i ++) {
|
||||||
this.flightPoints = flightPoints;
|
this.flightPoints = flightPoints;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Airport getDepartureAirport() {
|
|
||||||
return departureAirport;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setDepartureAirport(Airport departureAirport) {
|
public void setDepartureAirport(String departureAirport) {
|
||||||
this.departureAirport = departureAirport;
|
this.departureAirport = departureAirport;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Airport getArrivalAirport() {
|
public void setArrivalAirport(String arrivalAirport) {
|
||||||
return arrivalAirport;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setArrivalAirport(Airport arrivalAirport) {
|
|
||||||
this.arrivalAirport = arrivalAirport;
|
this.arrivalAirport = arrivalAirport;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -47,11 +48,11 @@ public class FlightPath {
|
|||||||
return ID;
|
return ID;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Airport departsFrom(){
|
public String departsFrom(){
|
||||||
return departureAirport;
|
return departureAirport;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Airport arrivesAt(){
|
public String arrivesAt(){
|
||||||
return arrivalAirport;
|
return arrivalAirport;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -62,4 +63,22 @@ public class FlightPath {
|
|||||||
public void addFlightPoint(FlightPoint flightPoint){
|
public void addFlightPoint(FlightPoint flightPoint){
|
||||||
flightPoints.add(flightPoint);
|
flightPoints.add(flightPoint);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void addFlightPoint(FlightPoint flightPoint, int index){
|
||||||
|
flightPoints.add(index, flightPoint);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void delFlightPoint(FlightPoint flightPoint){
|
||||||
|
flightPoints.remove(flightPoint);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void delFlightPoint(int index){
|
||||||
|
flightPoints.remove(index);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addFlightPoint(ArrayList<FlightPoint> flightPoints){
|
||||||
|
for (int i = 0; i < flightPoints.size(); i ++){
|
||||||
|
this.flightPoints.add(flightPoints.get(i));
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,21 +1,39 @@
|
|||||||
package seng202.group9.Core;
|
package seng202.group9.Core;
|
||||||
|
|
||||||
|
import seng202.group9.Controller.DataException;
|
||||||
|
|
||||||
public class FlightPoint {
|
public class FlightPoint {
|
||||||
private String name;
|
private String name;
|
||||||
private int ID;
|
private int ID;
|
||||||
private int indexID;
|
private int indexID;
|
||||||
private String type;
|
private String type;
|
||||||
private String via;
|
private String via;
|
||||||
private String heading;
|
private int heading;
|
||||||
private float altitude;//note float has a max value so they may try to break this
|
private double altitude;//note double has a max value so they may try to break this
|
||||||
private float legDistance;
|
private double legDistance;
|
||||||
private float totalDistance;
|
private double totalDistance;
|
||||||
private float latitude;
|
private double latitude;
|
||||||
private float longitude;
|
private double longitude;
|
||||||
|
|
||||||
|
public FlightPoint(String type, String via, double altitude, double latitude, double longitude){
|
||||||
|
//extra calculations will have to be used to find heading, legdistance and total distance. If necessary
|
||||||
|
//Type 1 file the file the lecturers gave us
|
||||||
|
this.name = "";
|
||||||
|
this.ID = -1;
|
||||||
|
this.indexID = -1;
|
||||||
|
this.type = type;
|
||||||
|
this.via = via;
|
||||||
|
this.heading = 0;
|
||||||
|
this.altitude = altitude;
|
||||||
|
this.legDistance = 0.0;
|
||||||
|
this.totalDistance = 0.0;
|
||||||
|
this.latitude = latitude;
|
||||||
|
this.longitude = longitude;
|
||||||
|
}
|
||||||
|
|
||||||
public FlightPoint(String name, int ID, int indexID, String type, String via,
|
public FlightPoint(String name, int ID, int indexID, String type, String via,
|
||||||
String heading, float altitude, float legDistance, float totalDistance,
|
int heading, double altitude, double legDistance, double totalDistance,
|
||||||
float latitude, float longitude){
|
double latitude, double longitude){
|
||||||
this.name = name;
|
this.name = name;
|
||||||
this.ID = ID;
|
this.ID = ID;
|
||||||
this.indexID = indexID;
|
this.indexID = indexID;
|
||||||
@@ -29,8 +47,12 @@ public class FlightPoint {
|
|||||||
this.longitude = longitude;
|
this.longitude = longitude;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getIndexID() {
|
public int getIndexID() throws DataException {
|
||||||
return indexID;
|
if (this.ID == -1){
|
||||||
|
throw new DataException("ID not set.");
|
||||||
|
}else{
|
||||||
|
return ID;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setIndexID(int indexID) {
|
public void setIndexID(int indexID) {
|
||||||
@@ -53,27 +75,27 @@ public class FlightPoint {
|
|||||||
this.via = via;
|
this.via = via;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setHeading(String heading) {
|
public void setHeading(int heading) {
|
||||||
this.heading = heading;
|
this.heading = heading;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setAltitude(float altitude) {
|
public void setAltitude(double altitude) {
|
||||||
this.altitude = altitude;
|
this.altitude = altitude;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setLegDistance(float legDistance) {
|
public void setLegDistance(double legDistance) {
|
||||||
this.legDistance = legDistance;
|
this.legDistance = legDistance;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setTotalDistance(float totalDistance) {
|
public void setTotalDistance(double totalDistance) {
|
||||||
this.totalDistance = totalDistance;
|
this.totalDistance = totalDistance;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setLatitude(float latitude) {
|
public void setLatitude(double latitude) {
|
||||||
this.latitude = latitude;
|
this.latitude = latitude;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setLongitude(float longitude) {
|
public void setLongitude(double longitude) {
|
||||||
this.longitude = longitude;
|
this.longitude = longitude;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -81,9 +103,13 @@ public class FlightPoint {
|
|||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getID(){
|
public int getID() throws DataException {
|
||||||
|
if (this.ID == -1){
|
||||||
|
throw new DataException("ID not set.");
|
||||||
|
}else{
|
||||||
return ID;
|
return ID;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public int getIndex(){
|
public int getIndex(){
|
||||||
return indexID;
|
return indexID;
|
||||||
@@ -97,27 +123,27 @@ public class FlightPoint {
|
|||||||
return via;
|
return via;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getHeading(){
|
public int getHeading(){
|
||||||
return heading;
|
return heading;
|
||||||
}
|
}
|
||||||
|
|
||||||
public float getAltitude(){
|
public double getAltitude(){
|
||||||
return altitude;
|
return altitude;
|
||||||
}
|
}
|
||||||
|
|
||||||
public float getLegDistance(){
|
public double getLegDistance(){
|
||||||
return legDistance;
|
return legDistance;
|
||||||
}
|
}
|
||||||
|
|
||||||
public float getTotalDistance(){
|
public double getTotalDistance(){
|
||||||
return totalDistance;
|
return totalDistance;
|
||||||
}
|
}
|
||||||
|
|
||||||
public float getLongitude(){
|
public double getLongitude(){
|
||||||
return longitude;
|
return longitude;
|
||||||
}
|
}
|
||||||
|
|
||||||
public float getLatitude(){
|
public double getLatitude(){
|
||||||
return latitude;
|
return latitude;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import java.util.ArrayList;
|
|||||||
import junit.framework.Test;
|
import junit.framework.Test;
|
||||||
import junit.framework.TestCase;
|
import junit.framework.TestCase;
|
||||||
import junit.framework.TestSuite;
|
import junit.framework.TestSuite;
|
||||||
|
import seng202.group9.Controller.DataException;
|
||||||
import seng202.group9.Core.Airline;
|
import seng202.group9.Core.Airline;
|
||||||
import seng202.group9.Core.Route;
|
import seng202.group9.Core.Route;
|
||||||
|
|
||||||
@@ -45,7 +46,11 @@ public class AirlineTest extends TestCase {
|
|||||||
Airline allNipponAirways = new Airline(324, "All Nippon Airways", "ANA All Nippon Airways",
|
Airline allNipponAirways = new Airline(324, "All Nippon Airways", "ANA All Nippon Airways",
|
||||||
"NH", "ANA", "ALL NIPPON", "Japan", "Y");
|
"NH", "ANA", "ALL NIPPON", "Japan", "Y");
|
||||||
//check constructor
|
//check constructor
|
||||||
|
try {
|
||||||
assertTrue(allNipponAirways.getID() == 324); //test id
|
assertTrue(allNipponAirways.getID() == 324); //test id
|
||||||
|
} catch (DataException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
assertTrue(allNipponAirways.getName() == "All Nippon Airways");//test name
|
assertTrue(allNipponAirways.getName() == "All Nippon Airways");//test name
|
||||||
assertTrue(allNipponAirways.getAlias() == "ANA All Nippon Airways");// test alias
|
assertTrue(allNipponAirways.getAlias() == "ANA All Nippon Airways");// test alias
|
||||||
assertTrue(allNipponAirways.getIATA() == "NH");// test iata
|
assertTrue(allNipponAirways.getIATA() == "NH");// test iata
|
||||||
@@ -55,7 +60,11 @@ public class AirlineTest extends TestCase {
|
|||||||
assertTrue(allNipponAirways.getActive() == "Y");// get active
|
assertTrue(allNipponAirways.getActive() == "Y");// get active
|
||||||
//check set
|
//check set
|
||||||
allNipponAirways.setID(322);//ID
|
allNipponAirways.setID(322);//ID
|
||||||
|
try {
|
||||||
assertTrue(allNipponAirways.getID() == 322);
|
assertTrue(allNipponAirways.getID() == 322);
|
||||||
|
} catch (DataException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
allNipponAirways.setName("All Nike Airways");//Name
|
allNipponAirways.setName("All Nike Airways");//Name
|
||||||
assertTrue(allNipponAirways.getName() == "All Nike Airways");
|
assertTrue(allNipponAirways.getName() == "All Nike Airways");
|
||||||
|
|||||||
@@ -7,6 +7,9 @@ import org.junit.rules.ExpectedException;
|
|||||||
|
|
||||||
import seng202.group9.Controller.DataException;
|
import seng202.group9.Controller.DataException;
|
||||||
import seng202.group9.Core.Airport;
|
import seng202.group9.Core.Airport;
|
||||||
|
import seng202.group9.Core.Route;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Unit test for Airport
|
* Unit test for Airport
|
||||||
@@ -21,7 +24,7 @@ public class AirportUnitTest {
|
|||||||
public void airportGetterAndSetterTest() {
|
public void airportGetterAndSetterTest() {
|
||||||
//507,"Heathrow","London","United Kingdom","LHR","EGLL",51.4775,-0.461389,83,0,"E","Europe/London"
|
//507,"Heathrow","London","United Kingdom","LHR","EGLL",51.4775,-0.461389,83,0,"E","Europe/London"
|
||||||
//ID, Name, City, Country, IATA/FFA, ICAO, Latitude, Longitude, Altitude, Timezone, DST, Tz Data
|
//ID, Name, City, Country, IATA/FFA, ICAO, Latitude, Longitude, Altitude, Timezone, DST, Tz Data
|
||||||
Airport heathrow = new Airport(507, "Heathrow", "London", "LHR", "EGLL", 51.4775, -0.41389, 83);
|
Airport heathrow = new Airport(507, "Heathrow", "London", "United Kingdom", "LHR", "EGLL", 51.4775, -0.41389, 83);
|
||||||
/////////////////
|
/////////////////
|
||||||
//check getters//
|
//check getters//
|
||||||
/////////////////
|
/////////////////
|
||||||
@@ -65,10 +68,60 @@ public class AirportUnitTest {
|
|||||||
assertTrue(heathrow.getAltitude() == 0);
|
assertTrue(heathrow.getAltitude() == 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void checkRoutesFnc(){
|
||||||
|
//507,"Heathrow","London","United Kingdom","LHR","EGLL",51.4775,-0.461389,83,0,"E","Europe/London"
|
||||||
|
//ID, Name, City, Country, IATA/FFA, ICAO, Latitude, Longitude, Altitude, Timezone, DST, Tz Data
|
||||||
|
Airport heathrow = new Airport(507, "Heathrow", "London", "United Kingdom", "LHR", "EGLL", 51.4775, -0.41389, 83);
|
||||||
|
//BA,1355,SIN,3316,LHR,507,,0,744 777
|
||||||
|
//airline, airline ID (This is not parsed as this will be different
|
||||||
|
//from our database id for this route), source Aiport, source Airport ID (not parsed),
|
||||||
|
//destination airport, destination ID (not parsed), Codeshare, stops, Equipment
|
||||||
|
Route route1 = new Route("BA1", "SIN1", "LHR1", "", 0, "744 777");
|
||||||
|
Route route2 = new Route("BA2", "SIN2", "LHR2", "", 0, "744 777");
|
||||||
|
Route route3 = new Route("BA3", "SIN3", "LHR3", "", 0, "744 777");
|
||||||
|
|
||||||
|
ArrayList<Route> routes = new ArrayList<Route>();
|
||||||
|
routes.add(route1);
|
||||||
|
routes.add(route2);
|
||||||
|
routes.add(route3);
|
||||||
|
|
||||||
|
//first check addArrivalRoutes;
|
||||||
|
heathrow.addArrivalRoutes(route1);
|
||||||
|
heathrow.addArrivalRoutes(routes);
|
||||||
|
|
||||||
|
assertEquals(heathrow.getArrivalRoutes().get(0).arrivesAt(), "LHR1");
|
||||||
|
assertEquals(heathrow.getArrivalRoutes().get(1).arrivesAt(), "LHR1");
|
||||||
|
assertEquals(heathrow.getArrivalRoutes().get(2).arrivesAt(), "LHR2");
|
||||||
|
assertEquals(heathrow.getArrivalRoutes().get(3).arrivesAt(), "LHR3");
|
||||||
|
|
||||||
|
//check add departrue routes;
|
||||||
|
heathrow.addDepartureRoutes(route1);
|
||||||
|
heathrow.addDepartureRoutes(routes);
|
||||||
|
|
||||||
|
assertEquals(heathrow.getDepartureRoutes().get(0).departsFrom(), "SIN1");
|
||||||
|
assertEquals(heathrow.getDepartureRoutes().get(1).departsFrom(), "SIN1");
|
||||||
|
assertEquals(heathrow.getDepartureRoutes().get(2).departsFrom(), "SIN2");
|
||||||
|
assertEquals(heathrow.getDepartureRoutes().get(3).departsFrom(), "SIN3");
|
||||||
|
|
||||||
|
//check set
|
||||||
|
heathrow.setArrivalRoutes(routes);
|
||||||
|
heathrow.setDepartureRoutes(routes);
|
||||||
|
//Arrival check
|
||||||
|
assertEquals(heathrow.getArrivalRoutes().get(0).arrivesAt(), "LHR1");
|
||||||
|
assertEquals(heathrow.getArrivalRoutes().get(1).arrivesAt(), "LHR2");
|
||||||
|
assertEquals(heathrow.getArrivalRoutes().get(2).arrivesAt(), "LHR3");
|
||||||
|
//departure check
|
||||||
|
assertEquals(heathrow.getDepartureRoutes().get(0).departsFrom(), "SIN1");
|
||||||
|
assertEquals(heathrow.getDepartureRoutes().get(1).departsFrom(), "SIN2");
|
||||||
|
assertEquals(heathrow.getDepartureRoutes().get(2).departsFrom(), "SIN3");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void checkIDException(){
|
public void checkIDException(){
|
||||||
//507,"Heathrow","London","United Kingdom","LHR","EGLL",51.4775,-0.461389,83,0,"E","Europe/London"
|
//507,"Heathrow","London","United Kingdom","LHR","EGLL",51.4775,-0.461389,83,0,"E","Europe/London"
|
||||||
//ID, Name, City, Country, IATA/FFA, ICAO, Latitude, Longitude, Altitude, Timezone, DST, Tz Data
|
//ID, Name, City, Country, IATA/FFA, ICAO, Latitude, Longitude, Altitude, Timezone, DST, Tz Data
|
||||||
Airport heathrow = new Airport("Heathrow", "London", "LHR", "EGLL", 51.4775, -0.41389, 83);
|
Airport heathrow = new Airport("Heathrow", "London", "United Kingdom", "LHR", "EGLL", 51.4775, -0.41389, 83);
|
||||||
thrown.expect(DataException.class);
|
thrown.expect(DataException.class);
|
||||||
thrown.expectMessage("ID not set.");
|
thrown.expectMessage("ID not set.");
|
||||||
try {
|
try {
|
||||||
|
|||||||
Reference in New Issue
Block a user