Merge remote-tracking branch 'origin/master'

main
Liam Beckett 9 years ago
commit b5d04ef922

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
1 APT NZCH 0 -43.48664019 172.53368221
2 VOR CH 400 -43.50411111 172.51463889000001
3 FIX VANDA 34000 -42.421806 169.34450000000004
4 FIX UKLAK 34000 -41.4245 166.71119399999998
5 FIX SULON 34000 -39.858528 163
6 FIX PLUGA 34000 -35.6075 154.68888900000002
7 FIX CAWLY 34000 -34.326111 151.95777799999996
8 VOR SY 34000 -33.94277778 151.18055556000002
9 NDB KAT 34000 -33.710806 150.299622
10 VOR PKS 34000 -33.131111 148.23722199999997
11 FIX VIMAB 34000 -31.515277999999995 145.358611
12 FIX APOMA 34000 -29.898055999999997 142.681667
13 FIX POLEV 34000 -26.920277999999996 138.16916700000002
14 FIX KALUG 34000 -25.900000000000006 136.72500000000002
15 VOR AS 34000 -23.792889000000002 133.87820299999998
16 FIX TIMMI 34000 -21.922483 130.65954399999998
17 FIX TATUK 34000 -19.429444000000004 126.646389
18 VOR CIN 34000 -17.588888889999993 123.85194444000001
19 FIX ATMAP 34000 -12 118.255
20 FIX ILDAM 34000 -10.592113999999995 116.88456400000001
21 VOR BLI 34000 -8.750583329999998 115.16330556000003
22 FIX SIPUT 34000 -6.283332999999999 112.58333299999998
23 FIX SUMBU 34000 -4.7549999999999955 110.82333299999999
24 FIX SABIL 34000 -4.019069000000002 109.93852800000002
25 FIX AKULA 34000 -3.119878 108.95092499999998
26 FIX APAGA 34000 -2.7826749999999976 108.580897
27 FIX APARI 34000 -2.043471999999994 107.84038299999997
28 FIX SANOS 34000 -0.7000000000000028 106.316667
29 FIX AKTOD 34300 -0.4133329999999944 105.99305600000002
30 NDB TI 8800 0.9197280000000063 104.52616899999998
31 APT WSSS 0 1.3519171399999976 103.99560303999999

File diff suppressed because it is too large Load Diff

@ -0,0 +1,34 @@
APT,NZCH,0,-43.48664,172.53368
FIX,KIDAL,14000,42.85864,172.28600
FIX,UDUMO,34000,41.20481,171.99256
FIX,MOTKO,34000,-39.12419,171.64394
FIX,PAPTI,34000,-35.56533,171.09314
FIX,SALAG,35000,-34.84506,171.68336
FIX,LEBOL,34000,-29.14631,165.21556
FIX,NOGOL,34000,-28.83722,164.86833
FIX,DUBEV,34000,-27.55056,163.45472
FIX,LEMIB,34000,-26.01333,163.45472
FIX,ISTEM,34000,-26.01333,161.82806
FIX,MEPAB,35000,-24.59750,160.3833
FIX,BODEG,35000,-21.38047,163.00000
FIX,IKODA,34000,-20.12667,163.00000
FIX,RIPNA,35000,-16.62333,157.44833
FIX,BISTT,35000,-14.00000,158.41667
FIX,KOPAU,35000,-11.02667,159.46833
FIX,IRRIE,34000,-9.53167,159.60667
FIX,KAKOP,34000,-8.59000,159.48500
FIX,KAKOP,34000,-5.64500,157.66833
FIX,ADBON,34000,-5.65167,157.65000
FIX,OKOLE,34000,0.00000,154.22833
FIX,GALSS,34000,6.06667,150.51667
FIX,KLOUT,35000,10.46167,147.79167
FIX,STINE,34000,12.78167,147.87000
FIX,SNAPP,34000,14.46796,147.63881
FIX,TEEDE,34000,15.85344,146.60578
FIX,TEGOD,34000,17.42306,146.51806
FIX,SAGOP,34000,21.00000,145.19667
FIX,NOGAK,34000,25.00500,144.34000
FIX,ADKAK,30300,30.00333,143.16500
FIX,RENAU,22600,33.90350,142.16331
FIX,SUNNS,18900,34.46783,141.89803
APT,RJAA,0,35.77655,140.38277
1 APT NZCH 0 -43.48664 172.53368
2 FIX KIDAL 14000 42.85864 172.28600
3 FIX UDUMO 34000 41.20481 171.99256
4 FIX MOTKO 34000 -39.12419 171.64394
5 FIX PAPTI 34000 -35.56533 171.09314
6 FIX SALAG 35000 -34.84506 171.68336
7 FIX LEBOL 34000 -29.14631 165.21556
8 FIX NOGOL 34000 -28.83722 164.86833
9 FIX DUBEV 34000 -27.55056 163.45472
10 FIX LEMIB 34000 -26.01333 163.45472
11 FIX ISTEM 34000 -26.01333 161.82806
12 FIX MEPAB 35000 -24.59750 160.3833
13 FIX BODEG 35000 -21.38047 163.00000
14 FIX IKODA 34000 -20.12667 163.00000
15 FIX RIPNA 35000 -16.62333 157.44833
16 FIX BISTT 35000 -14.00000 158.41667
17 FIX KOPAU 35000 -11.02667 159.46833
18 FIX IRRIE 34000 -9.53167 159.60667
19 FIX KAKOP 34000 -8.59000 159.48500
20 FIX KAKOP 34000 -5.64500 157.66833
21 FIX ADBON 34000 -5.65167 157.65000
22 FIX OKOLE 34000 0.00000 154.22833
23 FIX GALSS 34000 6.06667 150.51667
24 FIX KLOUT 35000 10.46167 147.79167
25 FIX STINE 34000 12.78167 147.87000
26 FIX SNAPP 34000 14.46796 147.63881
27 FIX TEEDE 34000 15.85344 146.60578
28 FIX TEGOD 34000 17.42306 146.51806
29 FIX SAGOP 34000 21.00000 145.19667
30 FIX NOGAK 34000 25.00500 144.34000
31 FIX ADKAK 30300 30.00333 143.16500
32 FIX RENAU 22600 33.90350 142.16331
33 FIX SUNNS 18900 34.46783 141.89803
34 APT RJAA 0 35.77655 140.38277

Binary file not shown.

@ -12,6 +12,10 @@ public class AirlineFilter extends Filter{
private ArrayList<Airline> baseArray;
private ArrayList<Airline> filteredList;
/**
* Constructor of the class sets the base array that will be used for filtering
* @param baseList
*/
public AirlineFilter(ArrayList<Airline> baseList){
filteredList = new ArrayList<Airline>();
baseArray = new ArrayList<Airline>();
@ -21,6 +25,10 @@ public class AirlineFilter extends Filter{
}
}
/**
* filters the list base by name case insensitive.
* @param name
*/
public void filterName(String name){
String regexCode = "(?i).*"+name+".*";
int index = 0;
@ -33,6 +41,10 @@ public class AirlineFilter extends Filter{
}
}
/**
* filters list based on alias case insensitive.
* @param alias
*/
public void filterAlias(String alias){
String regexCode = "(?i).*"+alias+".*";
int index = 0;
@ -45,6 +57,10 @@ public class AirlineFilter extends Filter{
}
}
/**
* Filters the list based on IATA code Case Insensitive.
* @param IATA
*/
public void filterIATA(String IATA){
String regexCode = "(?i).*"+IATA+".*";
int index = 0;
@ -57,6 +73,10 @@ public class AirlineFilter extends Filter{
}
}
/**
* Filters the list based on ICAO code Case Insensitive.
* @param ICAO
*/
public void filterICAO(String ICAO){
String regexCode = "(?i).*"+ICAO+".*";
int index = 0;
@ -69,6 +89,10 @@ public class AirlineFilter extends Filter{
}
}
/**
* FIlters the list based on Callsign case Insensitive.
* @param callsign
*/
public void filterCallsign(String callsign){
String regexCode = "(?i).*"+callsign+".*";
int index = 0;
@ -81,6 +105,10 @@ public class AirlineFilter extends Filter{
}
}
/**
* Filters the list based on the country case insensitive.
* @param country
*/
public void filterCountry(String country){
String regexCode = "(?i).*"+country+".*";
int index = 0;
@ -93,6 +121,10 @@ public class AirlineFilter extends Filter{
}
}
/**
* Filters the list by activity.
* @param active
*/
public void filterActive(String active){
String regexCode = "(?i).*"+active+".*";
int index = 0;
@ -105,6 +137,9 @@ public class AirlineFilter extends Filter{
}
}
/**
* resets the filtered list back to the original list.
*/
public void reset() {
filteredList = new ArrayList<Airline>();
for (Airline airline: filteredList){
@ -112,17 +147,29 @@ public class AirlineFilter extends Filter{
}
}
/**
* gets the filtered list.
* @return
*/
public ArrayList getFilteredData() {
return filteredList;
}
/**
* sets a new base list of the filter.
* @param arrayList
*/
public void setBaseList(ArrayList<Airline> arrayList) {
baseArray = new ArrayList<Airline>();
for (Airline airline: arrayList){
baseArray.add(airline);
}
reset();
}
/**
* prints the filter to the console.
*/
public void printFilter(){
for (Airline airline: filteredList){
System.out.println(airline);

@ -7,15 +7,27 @@ import seng202.group9.Core.Airline;
import java.io.*;
import java.util.ArrayList;
/**
* Created By Fan-Wu Yang (fwy13)
*/
public class AirlineParser extends Parser {
String filePath = "";
ArrayList<Airline> parsedAirline;
/**
* Constructor takes in a filepath and waits for the parse() call.
* @param filePath
*/
public AirlineParser(String filePath){
this.filePath = filePath;
parsedAirline = new ArrayList<Airline>();
}
/**
* Parses data and then returns a message of number of successful parses.
* @return
* @throws DataException
*/
public String parse() throws DataException{
int successful = 0;
int error = 0;
@ -122,6 +134,10 @@ public class AirlineParser extends Parser {
"Airlines With Errors: %2$d", successful, error);
}
/**
* Returns the result of the Parse.
* @return
*/
public ArrayList<Airline> getResult(){
return parsedAirline;
}

@ -13,6 +13,10 @@ public class AirportFilter extends Filter{
private ArrayList<Airport> baseArray;
private ArrayList<Airport> filteredList;
/**
* Constructor of the Airport FIlter.
* @param baseList
*/
public AirportFilter(ArrayList<Airport> baseList){
filteredList = new ArrayList<Airport>();
baseArray = new ArrayList<Airport>();
@ -22,6 +26,10 @@ public class AirportFilter extends Filter{
}
}
/**
* Filters the list by name Case Insensitive.
* @param name
*/
public void filterName(String name){
String regexCode = "(?i).*"+name+".*";
int index = 0;
@ -34,6 +42,10 @@ public class AirportFilter extends Filter{
}
}
/**
* filters the list by the city Case Insensitive.
* @param city
*/
public void filterCity(String city){
String regexCode = "(?i).*"+city+".*";
int index = 0;
@ -46,6 +58,10 @@ public class AirportFilter extends Filter{
}
}
/**
* Filters the list by Country Case Insensitive.
* @param country
*/
public void filterCountry(String country){
String regexCode = "(?i).*"+country+".*";
int index = 0;
@ -58,6 +74,10 @@ public class AirportFilter extends Filter{
}
}
/**
* FIlters list by IATA/FFA Case Insensitive.
* @param IATA_FFA
*/
public void filterIATA_FFA(String IATA_FFA){
String regexCode = "(?i).*"+IATA_FFA+".*";
int index = 0;
@ -70,6 +90,10 @@ public class AirportFilter extends Filter{
}
}
/**
* Filters the list by ICAO Case Insensitive.
* @param ICAO
*/
public void filterICAO(String ICAO){
String regexCode = "(?i).*"+ICAO+".*";
int index = 0;
@ -82,6 +106,10 @@ public class AirportFilter extends Filter{
}
}
/**
* FIlters the list by latitude Case Insensitive.
* @param latitude
*/
public void filterLatitude(String latitude){
String regexCode = ".*"+latitude+".*";
int index = 0;
@ -94,6 +122,10 @@ public class AirportFilter extends Filter{
}
}
/**
* Filters the list by longitude Case Insensitive.
* @param longitude
*/
public void filterLongitude(String longitude){
String regexCode = ".*"+longitude+".*";
int index = 0;
@ -106,6 +138,10 @@ public class AirportFilter extends Filter{
}
}
/**
* FIlters the list by Altitude Case Insensitive.
* @param altitude
*/
public void filterAltitude(String altitude){
String regexCode = ".*"+altitude+".*";
int index = 0;
@ -118,6 +154,10 @@ public class AirportFilter extends Filter{
}
}
/**
* FIlters the list by Timezeon Case Insensitive.
* @param timezone
*/
public void filterTimezone(String timezone){
String regexCode = "(?i).*"+timezone+".*";
int index = 0;
@ -130,6 +170,10 @@ public class AirportFilter extends Filter{
}
}
/**
* Filters the list by Olson Timezone format Case Insensitive.
* @param olson
*/
public void filterOlson(String olson){
String regexCode = "(?i).*"+olson+".*";
int index = 0;
@ -142,6 +186,10 @@ public class AirportFilter extends Filter{
}
}
/**
* Filters the list by DST Case Insensitive.
* @param DST
*/
public void filterDST(String DST){
String regexCode = "(?i).*"+DST+".*";
int index = 0;
@ -154,6 +202,9 @@ public class AirportFilter extends Filter{
}
}
/**
* Resets the list to it original state before filter
*/
public void reset() {
filteredList = new ArrayList<Airport>();
for (Airport airport: filteredList){
@ -161,6 +212,10 @@ public class AirportFilter extends Filter{
}
}
/**
* gets the filtered list
* @return
*/
public ArrayList getFilteredData() {
return filteredList;
}
@ -170,8 +225,12 @@ public class AirportFilter extends Filter{
for (Airport airport: arrayList){
baseArray.add(airport);
}
reset();
}
/**
* prints the filtered list to console.
*/
public void printFilter(){
for (Airport airport: filteredList){
System.out.println(airport);

@ -11,12 +11,19 @@ import java.io.*;
import java.lang.reflect.Array;
import java.util.ArrayList;
/**
* created by Fan-Wu Yang(fwy13)
*/
public class AirportParser extends Parser {
String filePath = "";
ArrayList<Airport> parsedAirports;
ArrayList<City> parsedCities;
ArrayList<Country> parsedCountries;
/**
* Constructer is passed a file path which is then ready for the parse() call.
* @param filePath
*/
public AirportParser(String filePath){
this.filePath = filePath;
parsedAirports = new ArrayList<Airport>();
@ -24,6 +31,11 @@ public class AirportParser extends Parser {
parsedCountries = new ArrayList<Country>();
}
/**
* Parses the given file and returns a succession message of how many entries were successfully parsed.
* @return
* @throws DataException
*/
public String parse() throws DataException{
int successful = 0;
int error = 0;
@ -173,14 +185,26 @@ public class AirportParser extends Parser {
"Airports With Errors: %2$d", successful, error);
}
/**
* gets the parsed Airport results
* @return
*/
public ArrayList<Airport> getResult(){
return parsedAirports;
}
/**
* gets the parsed City restuls
* @return
*/
public ArrayList<City> getCityResult(){
return parsedCities;
}
/**
* gets the parsed COuntry results
* @return
*/
public ArrayList<Country> getCountryResult(){
return parsedCountries;
}

@ -18,16 +18,16 @@ import seng202.group9.GUI.*;
/**
* Main Application frame of the Flight Data Analyser.
*
* Created By Fan-Wu Yang (fwy13)
*/
public class App extends Application
{
private ArrayList<Dataset> datasets = new ArrayList<Dataset>();
private Dataset currentDataset = null;
private Stage primaryStage = null;
private VBox mainContainer;
private Session session;
private MenuController menuController;
private VBox mainContainer = null;
private Session session = null;
private MenuController menuController = null;
public static void main( String[] args )
{
@ -65,60 +65,10 @@ public class App extends Application
//testing out dataset
try {
currentDataset = new Dataset("test's", Dataset.getExisting);
}catch (DataException e){
e.printStackTrace();
}
/*
AirlineFilter filter = new AirlineFilter(currentDataset.getAirlines());
filter.filterName("NZ");
filter.filterAlias("flight");
filter.printFilter();
//testout single route adding
try {
currentDataset.addRoute("D2", "MAC", "WIN", "Y", "0", "NOW");
}catch (DataException e){
e.printStackTrace();
}
//testout single airport adding
try {
currentDataset.addAirport("Windows 10", "PC", "Windows", "WIN", "WIND", "0.0", "0.0", "0.0", "0.0", "U", "PC/Windows");
datasets.add(currentDataset);
}catch (DataException e){
e.printStackTrace();
}
//testout single airline adding
try {
currentDataset.addAirline("Dota2", "Valve", "D2", "DOT", "Defence of the Ancients", "Steam", "Y");
}catch (DataException e){
e.printStackTrace();
}
//testing out airport parser
try {
System.out.println(currentDataset.importAirport("res/Samples/Airports.txt"));
} catch (DataException e) {
e.printStackTrace();
}
//testing out airline parser
try{
System.out.println(currentDataset.importAirline("res/Samples/Airlines.txt"));
} catch (DataException e){
e.printStackTrace();
}
//testing out route parser
try {
System.out.println(currentDataset.importRoute("res/Samples/Routes.txt"));
} catch (DataException e) {
e.printStackTrace();
}
//testing out flight parser
try {
System.out.println(currentDataset.importFlight("res/Samples/NZCH-WSSS.csv"));
} catch (DataException e) {
e.printStackTrace();
}*/
//after all loading then load the previous session
try{
FileInputStream fileIn = new FileInputStream("res/session.ser");
@ -181,16 +131,54 @@ public class App extends Application
return (Initializable) loader.getController();
}
/**
* Returns the Menu COntroller of the App.
* @return
*/
public MenuController getMenuController() {
return menuController;
}
/**
* returns the current dataset that the user is using.
* @return
*/
public Dataset getCurrentDataset(){
return currentDataset;
}
/**
* Creates new dataset.
* @param datasetName
* @throws DataException
*/
public void createDataset(String datasetName) throws DataException{
Dataset newDataset = new Dataset(datasetName, Dataset.createNew);
datasets.add(newDataset);
currentDataset = newDataset;
}
/**
* gets the amount of datasets the user has.
* @return
*/
public ArrayList<Dataset> getDatasets() {
return datasets;
}
/**
* deletes a dataset.
* @param dataset
*/
public void deleteDataset(Dataset dataset){
dataset.deleteDataset();
datasets.remove(dataset);
if (dataset == currentDataset){
if (datasets.size() > 0){
currentDataset = datasets.get(0);
}else{
currentDataset = null;
}
}
}
}

@ -709,6 +709,7 @@ public class Dataset {
insertFlightPointQuery += "(" + flightPathId +", \""+ flightName +"\", \"" + flightType + "\", "+ flightAltitude + ", " +
"" + flightLatitude + ", " + flightLongitude + ")";
flightPointsToImport.get(i).setID(nextID);
flightPointsToImport.get(i).setIndexID(flightPathId);
//add data to dataset array.
//this is placed after incase the database messes up
flightPathToAdd.addFlightPoint(flightPointsToImport.get(i));
@ -739,11 +740,23 @@ public class Dataset {
public void createDataLinks(){
//this may be seperated into more sepearate function in the future for time optimisation
HashMap<String, Airline> airlineByIATA= new HashMap<String, Airline>();
for (Country country: countries){
country.setAirlines(new ArrayList<Airline>());
country.setCities(new ArrayList<City>());
}
for (City city: cities){
city.setAirports(new ArrayList<Airport>());
}
//create Airline country link
for (Airline airline: airlines){
airlineByIATA.put(airline.getIATA(), airline);
//System.out.println(airline.getAlias());
airline.setRoutes(new ArrayList<Route>());
airline.setCountry(countryDictionary.get(airline.getCountryName()));
Country country = countryDictionary.get(airline.getCountryName());
if (country != null){
country.addAirline(airline);
}
}
//create Airport City and Country Link
HashMap<String, Airport> airportsByIATA = new HashMap<String, Airport>(); //this is used later for connecting the routes
@ -757,6 +770,8 @@ public class Dataset {
//TODO Add City in country (This is extra work).
airport.setCity(cityDictionary.get(airport.getCityName()));
airport.getCity().addAirport(airport);
airport.setDepartureRoutes(new ArrayList<Route>());
airport.setArrivalRoutes(new ArrayList<Route>());
}
//set Airport variables for route
for (Route route: routes){
@ -771,6 +786,10 @@ public class Dataset {
route.setDestinationAirport(airportsByIATA.get(route.getArrivalAirport()));
}
route.setAirline(airlineByIATA.get(route.getAirlineName()));
Airline airline = airlineByIATA.get(route.getAirlineName());
if (airline != null){
airline.addRoutes(route);
}
}
System.out.println("Links Made");
}
@ -800,6 +819,11 @@ public class Dataset {
addAirline(airlineToAdd);
}
/**
* Adds a Single Airline from the Program to the Database
* @param airlineToAdd
* @throws DataException
*/
public void addAirline(Airline airlineToAdd) throws DataException{
if (airlineToAdd.getIATA().length() != 0 && airlineToAdd.getIATA().length() != 2){
throw new DataException("IATA is either empty or length of 2 Letters.");
@ -847,6 +871,21 @@ public class Dataset {
createDataLinks();
}
/**
* Adds a single Airport from the Program to the Database
* @param name
* @param city
* @param country
* @param IATA_FFA
* @param ICAO
* @param latitude
* @param longitude
* @param altitude
* @param timezone
* @param DST
* @param olsonTz
* @throws DataException
*/
public void addAirport(String name, String city, String country, String IATA_FFA, String ICAO, String latitude, String longitude,
String altitude, String timezone, String DST, String olsonTz) throws DataException{
try{
@ -873,7 +912,20 @@ public class Dataset {
}
}
public void addAirport(Airport airportToAdd) throws DataException{
/**
* gets the name of the dataset.
* @return
*/
public String getName() {
return name;
}
/**
* Adds an Airport to the database and dataset.
* @param airportToAdd
* @throws DataException
*/
private void addAirport(Airport airportToAdd) throws DataException{
if (airportToAdd.getIATA_FFA().length() != 0 && airportToAdd.getIATA_FFA().length() != 3){
throw new DataException("IATA/FFA either empty or 3 letters");
}
@ -907,6 +959,7 @@ public class Dataset {
ResultSet airportIDRes= stmt.executeQuery(airportIDQuery);
int airportID = 0;
while (airportIDRes.next()){
airportID = Integer.parseInt(airportIDRes.getString("seq"));
}
airportToAdd.setID(airportID);
@ -921,7 +974,11 @@ public class Dataset {
}
}
public void addCity(City city){
/**
* Adds a city to the dataset and database
* @param city
*/
private void addCity(City city){
if (!cityDictionary.containsKey(city.getName())){
Connection c = null;
Statement stmt = null;
@ -947,7 +1004,11 @@ public class Dataset {
}
}
public void addCountry(Country country){
/**
* Adds a Country to the dataset and database
* @param country
*/
private void addCountry(Country country){
if (!countryDictionary.containsKey(country.getName())){
Connection c = null;
Statement stmt = null;
@ -996,6 +1057,11 @@ public class Dataset {
addRoute(routeToAdd);
}
/**
* Adds a single route the dataset and database.
* @param routeToAdd
* @throws DataException
*/
public void addRoute(Route routeToAdd) throws DataException{
if (routeToAdd.getAirlineName().length() != 2 && routeToAdd.getAirlineName().length() != 3){
throw new DataException("Airline ICAO code must be 2 or 3 letters.");
@ -1040,7 +1106,7 @@ public class Dataset {
routeToAdd.setID(routeID);
routes.add(routeToAdd);
//routeAirline + routeSourceAirport + routeArrvAirport + routeCodeShare + routeStops + routeEquip
String routeKey = routeToAdd.getAirline() + routeToAdd.getDepartureAirport() + routeToAdd.getArrivalAirport() + routeToAdd.getCode() + routeToAdd.getStops() + routeToAdd.getEquipment();
String routeKey = routeToAdd.getAirlineName() + routeToAdd.getDepartureAirport() + routeToAdd.getArrivalAirport() + routeToAdd.getCode() + routeToAdd.getStops() + routeToAdd.getEquipment();
routeDictionary.put(routeKey, routeToAdd);
stmt.close();
c.close();
@ -1100,7 +1166,7 @@ public class Dataset {
* @param totDist
*/
public void addFlightPointToPath(int id, String name, String type, String via, String altitude, String latitude, String longitude,
String heading, String legDist, String totDist) throws DataException{
String heading, String legDist, String totDist , int index) throws DataException{
double altitudeVal = 0.0;
double latitudeVal = 0.0;
double longitudeVal = 0.0;
@ -1171,9 +1237,49 @@ public class Dataset {
FlightPoint pointToAdd = new FlightPoint(name, pointID+1, id, type, via, headingVal, altitudeVal, legDistVal,
totalDistVal,latitudeVal, longitudeVal);
flightPathDictionary.get(id).addFlightPoint(pointToAdd);
flightPathDictionary.get(Integer.valueOf(id)).addFlightPoint(pointToAdd, index);
}
/***
* Adds a single flight Point to an Existing FLight Path.
* @param point
* @param index
* @throws DataException
*/
public void addFlightPointToPath(FlightPoint point, int index) throws DataException{
addFlightPointToPath(point.getIndex(), point.getName(), point.getType(), point.getVia(), String.valueOf(point.getAltitude()),
String.valueOf( point.getLatitude()),String.valueOf(point.getLongitude()),
String.valueOf(point.getHeading()), String.valueOf(point.getLegDistance()), String.valueOf(point.getTotalDistance()), index);
}
/***
* Adds a single flight Point to an Existing FLight Path appended on the end of the list.
* @param point
* @throws DataException
*/
public void addFlightPointToPath(FlightPoint point) throws DataException{
addFlightPointToPath(point.getIndex(), point.getName(), point.getType(), point.getVia(), String.valueOf(point.getAltitude()),
String.valueOf( point.getLatitude()),String.valueOf(point.getLongitude()),
String.valueOf(point.getHeading()), String.valueOf(point.getLegDistance()), String.valueOf(point.getTotalDistance()), -1);
}
/**
* Adds a single flight Point to an Existing FLight Path appended on the end of the list.
* @param id
* @param name
* @param type
* @param via
* @param altitude
* @param latitude
* @param longitude
* @param heading
* @param legDist
* @param totDist
* @throws DataException
*/
public void addFlightPointToPath(int id, String name, String type, String via, String altitude, String latitude, String longitude,
String heading, String legDist, String totDist) throws DataException{
addFlightPointToPath(id, name, type, via, altitude, latitude, longitude, heading, legDist, totDist, -1);
}
/**
* This is called in conjunction to the App deleteDataset DO NOT CALL UNLESS THROUGH APP.DELETEDATASET
@ -1259,8 +1365,14 @@ public class Dataset {
//System.exit(0);
}
airlines.remove(airline);
airlineDictionary.remove(airline.getName());
createDataLinks();
}
/**
* Deletes an AIrline from the dataset and database based on it index
* @param index
*/
public void deleteAirline(int index){
deleteAirline(airlines.get(index));
}
@ -1307,6 +1419,8 @@ public class Dataset {
String deleteCountry = "DELETE FROM `"+this.name+"_Country` WHERE `Country_Name` = \""+airport.getCountry().getName()+"\"";
stmt.execute(deleteCountry);
stmt.close();
countries.remove(countryDictionary.get(airport.getCountryName()));
countryDictionary.remove(airport.getCountryName());
}
//cehck if number cities that contain airports > 0 else delete the city
String countCity = "SELECT COUNT(*) FROM `"+this.name+"_Airport` JOIN `"+this.name+"_City` ON" +
@ -1325,6 +1439,8 @@ public class Dataset {
String deleteCity = "DELETE FROM `"+this.name+"_City` WHERE `City_Name` = \""+airport.getCityName()+"\"";
stmt.execute(deleteCity);
stmt.close();
cities.remove(cityDictionary.get(airport.getCityName()));
cityDictionary.remove(airport.getCityName());
}
c.close();
} catch ( Exception e ) {
@ -1332,8 +1448,14 @@ public class Dataset {
System.exit(0);
}
airports.remove(airport);
airportDictionary.remove(airport.getName());
createDataLinks();
}
/**
* Deletes an Airport from the dataset and database based on it index.
* @param index
*/
public void deleteAirport(int index){
deleteAirport(airports.get(index));
}
@ -1357,8 +1479,16 @@ public class Dataset {
System.exit(0);
}
routes.remove(route);
//routeAirline + routeSourceAirport + routeArrvAirport + routeCodeShare + routeStops + routeEquip
String key = route.getAirlineName() + route.getDepartureAirport() + route.getArrivalAirport() + route.getCode() + route.getStops() + route.getEquipment();
routeDictionary.remove(key);
createDataLinks();
}
/**
* Deletes a Route from the dataset and database based on its index
* @param index
*/
public void deleteRoute(int index){
deleteRoute(routes.get(index));
}
@ -1377,6 +1507,10 @@ public class Dataset {
try {
Class.forName("org.sqlite.JDBC");
c = DriverManager.getConnection("jdbc:sqlite:res/userdb.db");
stmt = c.createStatement();
String deletePointsQuery = "DELETE FROM `"+this.name+"_FlightPoints` WHERE `Index_ID` = "+flightPath.getID()+ ";";
stmt.execute(deletePointsQuery);
stmt.close();
String deleteQuery = "DELETE FROM `"+this.name+"_Flight_Path` WHERE `Path_ID` = " + flightPath.getID() + ";";
stmt = c.createStatement();
stmt.execute(deleteQuery);
@ -1386,8 +1520,17 @@ public class Dataset {
System.exit(0);
}
flightPaths.remove(flightPath);
try {
flightPathDictionary.remove(flightPath.getID());
} catch (DataException e) {
e.printStackTrace();
}
}
/**
* Deletes a flight path from the database based on its index.
* @param index
*/
public void deleteFlightPath(int index){
deleteFlightPath(flightPaths.get(index));
}
@ -1414,54 +1557,107 @@ public class Dataset {
flightPath.getFlightPoints().remove(flightPoint);
}
/**
* deletes a single flight point from a given path.
* @param pathIndex
* @param pointIndex
*/
public void deleteFlightPoint(int pathIndex, int pointIndex){
deleteFlightPoint(flightPaths.get(pathIndex).getFlightPoints().get(pointIndex), flightPaths.get(pathIndex));
deleteFlightPoint(flightPathDictionary.get(pathIndex).getFlightPoints().get(pointIndex), flightPathDictionary.get(pathIndex));
}
/**
* returns the airlines that are part of this dataset.
* @return
*/
public ArrayList<Airline> getAirlines() {
return airlines;
}
/**
* returns the airports that are associated with this dataset.
* @return
*/
public ArrayList<Airport> getAirports() {
return airports;
}
/**
* returns the routes that are associated with this dataset.
* @return
*/
public ArrayList<Route> getRoutes() {
return routes;
}
/**
* returns the flight paths that are associated with this dataset.
* @return
*/
public ArrayList<FlightPath> getFlightPaths() {
return flightPaths;
}
/**
* returns the countries that are associated with this dataset.
* @return
*/
public ArrayList<Country> getCountries() {
return countries;
}
/**
* returns the cities that are associate wit hthis dataset.
* @return
*/
public ArrayList<City> getCities() {
return cities;
}
/**
* returns a dictionary with the airlines that are associated with this datatset.
* @return
*/
public LinkedHashMap<String, Airline> getAirlineDictionary() {
return airlineDictionary;
}
/**
* returns a dictionary with the airports that are associated with this dataset.
* @return
*/
public LinkedHashMap<String, Airport> getAirportDictionary() {
return airportDictionary;
}
/**
* returns a route dictionary with the routes that are associated wit hthis dataset.
* @return
*/
public LinkedHashMap<String, Route> getRouteDictionary() {
return routeDictionary;
}
/**
* returns a flightpath dictionary with the flights that are associated with this dataset.
* @return
*/
public LinkedHashMap<Integer, FlightPath> getFlightPathDictionary() {
return flightPathDictionary;
}
/**
* returns a Country Dictionary with the COuntries that are associated with this dataset.
* @return
*/
public LinkedHashMap<String, Country> getCountryDictionary() {
return countryDictionary;
}
/**
* returns a City Dictionary with the Cities that are associated with this datatset.
* @return
*/
public LinkedHashMap<String, City> getCityDictionary() {
return cityDictionary;
}

@ -5,15 +5,27 @@ import seng202.group9.Core.FlightPoint;
import java.io.*;
import java.util.ArrayList;
/**
* Created by Fan-Wu Yang(fwy13)
*/
public class FlightPathParser extends Parser {
String filePath = "";
ArrayList<FlightPoint> parsedPoints;
/**
* Constructor for parsing flight paths, reads in a file and gets it ready for the parse() call.
* @param filePath
*/
public FlightPathParser(String filePath){
this.filePath = filePath;
parsedPoints = new ArrayList<FlightPoint>();
}
/**
* Parses the file that and returns a success message.
* @return
* @throws DataException
*/
public String parse() throws DataException{
int successful = 0;
int error = 0;
@ -151,6 +163,10 @@ public class FlightPathParser extends Parser {
"Flight Points With Errors: %2$d", successful, error);
}
/**
* returns the resultant Flight points that are successfully parsed.
* @return
*/
public ArrayList<FlightPoint> getResult(){
return parsedPoints;
}

@ -12,6 +12,10 @@ public class RouteFilter extends Filter{
private ArrayList<Route> baseArray;
private ArrayList<Route> filteredList;
/**
* Constructor which takes in a base List which all data is filtered from.
* @param baseList
*/
public RouteFilter(ArrayList<Route> baseList){
filteredList = new ArrayList<Route>();
baseArray = new ArrayList<Route>();
@ -21,6 +25,10 @@ public class RouteFilter extends Filter{
}
}
/**
* Filters the list by the Airline Case Insensitive.
* @param airline
*/
public void filterAirline(String airline){
String regexCode = "(?i).*"+airline+".*";
int index = 0;
@ -33,6 +41,10 @@ public class RouteFilter extends Filter{
}
}
/**
* filters list by Airport Case Insensitive.
* @param airport
*/
public void filterSourceAirport(String airport){
String regexCode = "(?i).*"+airport+".*";
int index = 0;
@ -45,6 +57,10 @@ public class RouteFilter extends Filter{
}
}
/**
* filters lsit by destination airport Case Insensitive.
* @param airport
*/
public void filterDestinationAirport(String airport){
String regexCode = "(?i).*"+airport+".*";
int index = 0;
@ -57,6 +73,10 @@ public class RouteFilter extends Filter{
}
}
/**
* filters the list by its codeshare Case Insensitive.
* @param code
*/
public void filterCodeshare(String code){
String regexCode = "(?i).*"+code+".*";
int index = 0;
@ -69,6 +89,10 @@ public class RouteFilter extends Filter{
}
}
/**
* filters the list by how many stops it does Case Insensitive, Doesn't have to match exactly.
* @param stops
*/
public void filterDestinationStops(String stops){
String regexCode = "(?i).*"+stops+".*";
int index = 0;
@ -81,6 +105,10 @@ public class RouteFilter extends Filter{
}
}
/**
* filters the list by the equipment used for the route Case Insensitive.
* @param equipment
*/
public void filterEquipment(String equipment){
String regexCode = "(?i).*"+equipment+".*";
int index = 0;
@ -93,6 +121,9 @@ public class RouteFilter extends Filter{
}
}
/**
* resets the list to what the baselist.
*/
public void reset() {
filteredList = new ArrayList<Route>();
for (Route airline: filteredList){
@ -100,17 +131,29 @@ public class RouteFilter extends Filter{
}
}
/**
* get the filnal filtered array.
* @return
*/
public ArrayList getFilteredData() {
return filteredList;
}
/**
* sets the new baselist.
* @param arrayList
*/
public void setBaseList(ArrayList<Route> arrayList) {
baseArray = new ArrayList<Route>();
for (Route route: arrayList){
baseArray.add(route);
}
reset();
}
/**
* prints the filtered list to Console.
*/
public void printFilter(){
for (Route route: filteredList){
System.out.println(route);

@ -5,15 +5,27 @@ import seng202.group9.Core.Route;
import java.io.*;
import java.util.ArrayList;
/**
* Created By Fan-Wu Yang(fwy13)
*/
public class RouteParser extends Parser {
String filePath = "";
ArrayList<Route> parsedRoutes;
/**
* Constructor for Route Parser takes in a file and gets ready for the parse() call.
* @param filePath
*/
public RouteParser(String filePath){
this.filePath = filePath;
parsedRoutes = new ArrayList<Route>();
}
/**
* parses the given file for ROutes.
* @return
* @throws DataException
*/
public String parse() throws DataException{
int successful = 0;
int error = 0;
@ -153,6 +165,10 @@ public class RouteParser extends Parser {
"Routes With Errors: %2$d", successful, error);
}
/**
* returns the final successful results.
* @return
*/
public ArrayList<Route> getResult(){
return parsedRoutes;
}

@ -2,6 +2,7 @@ package seng202.group9.Controller;
/**
* Created by fwy13 on 16/09/16.
* SceneCode enum is used for Serialization of sessions as well as changing the GUI state from one to the other.
*/
public enum SceneCode {
INITIAL(""), AIRLINE_SUMMARY("airline_summary.fxml"), AIRLINE_RAW_DATA("airline_raw_data.fxml"),
@ -12,10 +13,16 @@ public enum SceneCode {
private String filePath;
/**
* COnstructor for Scene
* @param filePath
*/
SceneCode(String filePath){
this.filePath = filePath;
}
/**
* gets the filepath of the specific scene
*/
public String getFilePath(){
return filePath;
}

@ -4,23 +4,39 @@ import java.io.Serializable;
/**
* Created by fwy13 on 16/09/16.
* Users last session state is store here.
*/
public class Session implements Serializable {
private SceneCode sceneDisplayed;
/**
* Constructor for a new session
*/
public Session(){
//blank constructor
this.sceneDisplayed = SceneCode.INITIAL;
}
/**
* Constructor for a previous session.
* @param scene
*/
public Session(SceneCode scene){
this.sceneDisplayed = scene;
}
/**
* changes the serialized scene.
* @param sceneDisplayed
*/
public void setSceneDisplayed(SceneCode sceneDisplayed) {
this.sceneDisplayed = sceneDisplayed;
}
/**
* gets the last scene displayed.
* @return
*/
public SceneCode getSceneDisplayed() {
return sceneDisplayed;
}

@ -2,6 +2,7 @@ package seng202.group9.Core;
import seng202.group9.Controller.DataException;
import javax.xml.crypto.Data;
import java.util.ArrayList;
/**
@ -251,8 +252,12 @@ public class Airline{
* 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);
public void delRoutes(int index) throws DataException{
if (routes.size() > index && index >= 0) {
routes.remove(index);
}else{
throw new DataException("The Route at index "+index+ "does not exist to be deleted.");
}
}
/**
@ -264,7 +269,7 @@ public class Airline{
if (this.name.equals(airline.getName())){
throw new DataException("This Airline Name already Exists, Please Choose Another.");
}
if (this.name.equals("")){
if (airline.getName().equals("")){
throw new DataException("This Airline Name cannot be Empty");
}
if (!this.IATA.equals("") && this.IATA.equals(airline.getIATA())){

@ -2,6 +2,7 @@ package seng202.group9.Core;
import java.util.ArrayList;
import javafx.scene.chart.PieChart;
import seng202.group9.Controller.DataException;
/**
* Airport Class
@ -363,8 +364,31 @@ public class Airport {
* deletes a member of arrival routes by index
* @param index
*/
public void delArrivalRoutes(int index){
arrivalRoutes.remove(index);
public void delArrivalRoutes(int index) throws DataException{
if (arrivalRoutes.size() > index && index >= 0) {
arrivalRoutes.remove(index);
}else{
throw new DataException("Index "+index+" of number of Arrival Routes array size.");
}
}
/**
* deletes a member of departure routes by matching route pointer
* @param route
*/
public void delDepartureRoutes(Route route){
departureRoutes.remove(route);
}
/**
* deletes a member of departure routes by index
* @param index
*/
public void delDepartureRoutes(int index) throws DataException{
if (departureRoutes.size() > index && index >= 0) {
departureRoutes.remove(index);
}else{
throw new DataException("Index "+index+" is out of number of Departure Routes array size.");
}
}
/**
@ -376,8 +400,10 @@ public class Airport {
double distance = 0;
double dLong = this.longitude - airport.getLongitude();
double dLat = this.latitude - airport.getLatitude();
double a = Math.pow((Math.sin(dLat/2)), 2) + Math.cos(this.latitude) * Math.cos(airport.getLatitude()) * Math.pow(Math.sin(dLong/2), 2);
double c = a * Math.atan2(Math.sqrt(a), Math.sqrt(1-a));
dLong = Math.toRadians(dLong);
dLat = Math.toRadians(dLat);
double a = Math.pow((Math.sin(dLat/2)), 2) + Math.cos(Math.toRadians(this.latitude)) * Math.cos(Math.toRadians(airport.getLatitude())) * Math.pow(Math.sin(dLong/2), 2);
double c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1-a));
distance = 6371 * c;
return distance;
}
@ -388,13 +414,16 @@ public class Airport {
* @throws DataException
*/
public void hasDuplicate(Airport airport) throws DataException{
if (airport.getName().equals("") || airport.getName().equals(this.name)){
if (airport.getName().equals(this.name)){
throw new DataException("Airport Name already Exists, Please Choose Another.");
}
if (!airport.getIATA_FFA().equals("") && airport.getIATA_FFA().equals(this.name)){
if (airport.getName().equals("")){
throw new DataException("Airport name cannot be Empty. Please Choose Another.");
}
if (!airport.getIATA_FFA().equals("") && airport.getIATA_FFA().equals(this.IATA_FFA)){
throw new DataException("Airport IATA/FFA already Exists, Please Choose Another.");
}
if (!airport.getICAO().equals("") && airport.getICAO().equals(this.name)){
if (!airport.getICAO().equals("") && airport.getICAO().equals(this.ICAO)){
throw new DataException("Airport ICAO already Exists, Please Choose Another.");
}
}
@ -403,7 +432,7 @@ public class Airport {
*/
@Override
public String toString(){
return this.cityName +" Airport has ICAO: "+this.ICAO+", IATA/FFA: "+this.IATA_FFA+" and is located at ("+this.latitude+", "+this.longitude
return this.name +" 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.size()+" arriving routes.";
}
}

@ -1,7 +1,12 @@
package seng202.group9.Core;
import seng202.group9.Controller.DataException;
import java.util.ArrayList;
/**
* Created By Fan-Wu Yang.
*/
public class City {
private String name;
private String country;
@ -137,8 +142,12 @@ public class City {
* Deletes an Airport by Index from this City.
* @param index
*/
public void delAirport(int index) {
airports.remove(index);
public void delAirport(int index) throws DataException{
if (airports.size() > index && index >= 0) {
airports.remove(index);
}else{
throw new DataException("Index "+index+" is out of number of City Airports array size.");
}
}
@Override
public String toString(){

@ -1,11 +1,16 @@
package seng202.group9.Core;
import seng202.group9.Controller.DataException;
import java.util.ArrayList;
import java.util.HashMap;
public class Country {
private String DST, name;
private ArrayList<City> cities = new ArrayList<City>();
private ArrayList<Airline> airlines = new ArrayList<Airline>();
private HashMap<String, Airline> airlineDict = new HashMap<String, Airline>();
private HashMap<String, City> cityDict = new HashMap<String, City>();
private Position position;
/**
@ -40,8 +45,10 @@ public class Country {
*/
public void setAirlines(ArrayList<Airline> airlines) {
this.airlines = new ArrayList<Airline>();
this.airlineDict = new HashMap<String, Airline>();
for (int i = 0; i < airlines.size(); i ++) {
this.airlines.add(airlines.get(i));
airlineDict.put(airlines.get(i).getName(), airlines.get(i));
}
}
@ -74,7 +81,10 @@ public class Country {
* @param airline
*/
public void addAirline(Airline airline){
this.airlines.add(airline);
if (!airlineDict.containsKey(airline.getName())) {
this.airlines.add(airline);
airlineDict.put(airline.getName(), airline);
}
}
/**
@ -93,14 +103,20 @@ public class Country {
*/
public void delAirline(Airline airline){
airlines.remove(airline);
airlineDict.remove(airline.getName());
}
/**
* deletes an Airline in this country.
* @param index
*/
public void delAirline(int index){
airlines.remove(index);
public void delAirline(int index) throws DataException{
if (airlines.size() > index && index >= 0) {
airlineDict.remove(airlines.get(index).getName());
airlines.remove(index);
}else{
throw new DataException("Index " + index + " does not exist in list of Airlines in this Country.");
}
}
/**
@ -109,8 +125,10 @@ public class Country {
*/
public void setCities(ArrayList<City> cities){
this.cities = new ArrayList<City>();
this.cityDict = new HashMap<String, City>();
for (int i = 0; i < cities.size(); i++){
this.cities.add(cities.get(i));
cityDict.put(cities.get(i).getName(), cities.get(i));
}
}
@ -119,7 +137,10 @@ public class Country {
* @param city
*/
public void addCities(City city){
this.cities.add(city);
if (!cityDict.containsKey(city.getName())) {
this.cities.add(city);
cityDict.put(city.getName(), city);
}
}
/**
@ -144,8 +165,12 @@ public class Country {
* Deletes Cities in this Country
* @param index
*/
public void delCities(int index){
this.cities.remove(index);
public void delCities(int index) throws DataException{
if (cities.size() > index && index >= 0) {
this.cities.remove(index);
}else{
throw new DataException("City at Index "+ index + " does not exist.");
}
}
/**

@ -1,7 +1,12 @@
package seng202.group9.Core;
import seng202.group9.Controller.DataException;
import java.util.ArrayList;
/**
* Created By Fan-Wu Yang
*/
public class FlightPath {
private int ID;
private ArrayList<FlightPoint> flightPoints;
@ -49,7 +54,7 @@ public class FlightPath {
public void setFlightPoints(ArrayList<FlightPoint> flightPoints) {
this.flightPoints = new ArrayList<FlightPoint>();
for (int i = 0; i < flightPoints.size(); i ++) {
this.flightPoints = flightPoints;
this.flightPoints.add(flightPoints.get(i));
}
}
@ -82,7 +87,10 @@ public class FlightPath {
* gets the ID of the Flight Path.
* @return
*/
public int getID(){
public int getID() throws DataException{
if (ID == -1){
throw new DataException("This Flight Path has no ID set yet");
}
return ID;
}
@ -125,7 +133,11 @@ public class FlightPath {
* @param index
*/
public void addFlightPoint(FlightPoint flightPoint, int index){
flightPoints.add(index, flightPoint);
if (index >= flightPoints.size() || index < 0){
flightPoints.add(flightPoint);
}else {
flightPoints.add(index, flightPoint);
}
}
/**
@ -140,8 +152,12 @@ public class FlightPath {
* delets a point from the flight at a specific index.
* @param index
*/
public void delFlightPoint(int index){
flightPoints.remove(index);
public void delFlightPoint(int index) throws DataException{
if (flightPoints.size() > index && index >= 0) {
flightPoints.remove(index);
}else{
throw new DataException("Flight Point at Index " + index + " does not exist for this flight Path.");
}
}
/**

@ -197,7 +197,10 @@ public class FlightPoint {
* gets the Path Index ID at this point.
* @return
*/
public int getIndex(){
public int getIndex() throws DataException{
if (indexID == -1){
throw new DataException("Index ID is not set.");
}
return indexID;
}

@ -268,6 +268,9 @@ public class Route {
* @return
*/
public RoutePath getRoutePath(){
if (getSourceAirport() == null || getDestinationAirport() == null){
return new RoutePath();
}
if (routePath == null) {
routePath = new RoutePath(
new Position(getSourceAirport().getLatitude(), getSourceAirport().getLongitude()),

@ -9,6 +9,7 @@ import javafx.scene.control.*;
import javafx.scene.control.cell.PropertyValueFactory;
import javafx.scene.input.MouseEvent;
import seng202.group9.Controller.App;
import seng202.group9.Controller.DataException;
import seng202.group9.Controller.Dataset;
import seng202.group9.Core.FlightPath;
import seng202.group9.Core.FlightPoint;
@ -121,7 +122,11 @@ public class FlightRDController extends Controller {
*/
public void load() {
theDataSet = getParent().getCurrentDataset();
currentPathId = theDataSet.getFlightPaths().get(0).getID(); //Sets the default to the 1st Path
try {
currentPathId = theDataSet.getFlightPaths().get(0).getID(); //Sets the default to the 1st Path
} catch (DataException e) {
e.printStackTrace();
}
flightIdCol.setCellValueFactory(new PropertyValueFactory<FlightPoint, String>("ID"));
flightNameCol.setCellValueFactory(new PropertyValueFactory<FlightPoint, String>("Name"));
flightTypeCol.setCellValueFactory(new PropertyValueFactory<FlightPoint, String>("Type"));
@ -199,7 +204,14 @@ public class FlightRDController extends Controller {
*/
public void deletePoint() {
FlightPoint toDelete = flightTableView.getSelectionModel().getSelectedItem();
int pathID = toDelete.getIndex();
int pathID = 0;
try {
pathID = toDelete.getIndex();
} catch (DataException e) {
e.printStackTrace();
System.out.println("Point is Undeletable as the Index ID is not set.");
return;
}
LinkedHashMap<Integer, FlightPath> flightPathDict = theDataSet.getFlightPathDictionary();
FlightPath toDeletesPath = flightPathDict.get(pathID);
theDataSet.deleteFlightPoint(toDelete, toDeletesPath);

@ -116,7 +116,7 @@ public class FlightSummaryController extends Controller {
}
flightPathListView.getSelectionModel().selectedItemProperty().addListener(new ChangeListener<String>() {
public void changed(ObservableValue<? extends String> observable, String oldValue, String newValue) {
//map.displayRoute(theDataSet.getFlightPaths().get(flightPathListView.getSelectionModel().getSelectedIndices().get(0)).getRoutePath());
map.displayRoute(theDataSet.getFlightPaths().get(flightPathListView.getSelectionModel().getSelectedIndices().get(0)).getRoutePath());
}
});
}

@ -12,6 +12,9 @@ import seng202.group9.Controller.App;
import seng202.group9.Controller.Dataset;
import seng202.group9.Controller.SceneCode;
/**
* Created By Fan-Wu Yang (fwy13)
*/
public class MenuController extends Controller{
public void importAirports(){

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
1 APT NZCH 0 -43.48664019 172.53368221
2 VOR CH 400 -43.50411111 172.51463889000001
3 FIX VANDA 34000 -42.421806 169.34450000000004
4 FIX UKLAK 34000 -41.4245 166.71119399999998
5 FIX SULON 34000 -39.858528 163
6 FIX PLUGA 34000 -35.6075 154.68888900000002
7 FIX CAWLY 34000 -34.326111 151.95777799999996
8 VOR SY 34000 -33.94277778 151.18055556000002
9 NDB KAT 34000 -33.710806 150.299622
10 VOR PKS 34000 -33.131111 148.23722199999997
11 FIX VIMAB 34000 -31.515277999999995 145.358611
12 FIX APOMA 34000 -29.898055999999997 142.681667
13 FIX POLEV 34000 -26.920277999999996 138.16916700000002
14 FIX KALUG 34000 -25.900000000000006 136.72500000000002
15 VOR AS 34000 -23.792889000000002 133.87820299999998
16 FIX TIMMI 34000 -21.922483 130.65954399999998
17 FIX TATUK 34000 -19.429444000000004 126.646389
18 VOR CIN 34000 -17.588888889999993 123.85194444000001
19 FIX ATMAP 34000 -12 118.255
20 FIX ILDAM 34000 -10.592113999999995 116.88456400000001
21 VOR BLI 34000 -8.750583329999998 115.16330556000003
22 FIX SIPUT 34000 -6.283332999999999 112.58333299999998
23 FIX SUMBU 34000 -4.7549999999999955 110.82333299999999
24 FIX SABIL 34000 -4.019069000000002 109.93852800000002
25 FIX AKULA 34000 -3.119878 108.95092499999998
26 FIX APAGA 34000 -2.7826749999999976 108.580897
27 FIX APARI 34000 -2.043471999999994 107.84038299999997
28 FIX SANOS 34000 -0.7000000000000028 106.316667
29 FIX AKTOD 34300 -0.4133329999999944 105.99305600000002
30 NDB TI 8800 0.9197280000000063 104.52616899999998
31 APT WSSS 0 1.3519171399999976 103.99560303999999

File diff suppressed because it is too large Load Diff

@ -2,13 +2,17 @@ package seng202.group9;
import java.util.ArrayList;
import junit.framework.Test;
import junit.framework.TestCase;
import junit.framework.TestSuite;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import seng202.group9.Controller.DataException;
import seng202.group9.Core.Airline;
import seng202.group9.Core.Country;
import seng202.group9.Core.Route;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
/**
* Test the functions for the Airline
* this is the get, set methods for in the class Airline
@ -16,30 +20,13 @@ import seng202.group9.Core.Route;
* @author Fan-Wu Yang
*
*/
public class AirlineTest extends TestCase {
/**
* Create the test case
*
* @param testName name of the test case
*/
public AirlineTest(String testName){
super(testName);
}
/**
* @return the suite of tests being tested
*/
public static Test suite()
{
return new TestSuite( AirlineTest.class );
}
public class AirlineTest{
/**
* Test for Airline get and setting methods
* (Currently missing ADD ROUTES)
*/
@Test
public void testAirlineGetSet(){
//ID, Name, Alias, IATA, ICAO, CallSign, Country, Active
//324,"All Nippon Airways","ANA All Nippon Airways","NH","ANA","ALL NIPPON","Japan","Y"
@ -116,8 +103,119 @@ public class AirlineTest extends TestCase {
assertEquals(allNipponAirways.getRoutes().get(1), route2);
assertEquals(allNipponAirways.getRoutes().get(2), route1);
assertEquals(allNipponAirways.getRoutes().get(3), route2);
try {
allNipponAirways.delRoutes(3);
}catch (DataException e){
fail("3 is a valid deletable index.");
}
assertTrue(allNipponAirways.getRoutes().size() == 3);
allNipponAirways.delRoutes(route2);
assertTrue(allNipponAirways.getRoutes().size() == 2);
}
@Test(expected = DataException.class)
public void testInvalidRouteDelete() throws DataException{
//ID, Name, Alias, IATA, ICAO, CallSign, Country, Active
//324,"All Nippon Airways","ANA All Nippon Airways","NH","ANA","ALL NIPPON","Japan","Y"
Airline allNipponAirways = new Airline(324, "All Nippon Airways", "ANA All Nippon Airways",
"NH", "ANA", "ALL NIPPON", "Japan", "Y");
allNipponAirways.delRoutes(0);
}
@Test(expected = DataException.class)
public void testInvalidIndexRouteDelete() throws DataException{
//ID, Name, Alias, IATA, ICAO, CallSign, Country, Active
//324,"All Nippon Airways","ANA All Nippon Airways","NH","ANA","ALL NIPPON","Japan","Y"
Airline allNipponAirways = new Airline(324, "All Nippon Airways", "ANA All Nippon Airways",
"NH", "ANA", "ALL NIPPON", "Japan", "Y");
allNipponAirways.delRoutes(-1);
}
@Test(expected = DataException.class)
public void hasDuplicateNameTest() throws DataException {
Airline allNipponAirways = new Airline(324, "All Nippon Airways", "ANA All Nippon Airways",
"NH", "ANA", "ALL NIPPON", "Japan", "Y");
Airline allNipponAirway = new Airline(325, "All Nippon Airways", "ANA All Nippon Airway",
"NP", "ANP", "ALL NIPPONP", "Japan", "Y");//duplicate name should be thrown
allNipponAirways.hasDuplicate(allNipponAirway);
}
@Test(expected = DataException.class)
public void hasDuplicateMissingNameTest() throws DataException {
Airline allNipponAirways = new Airline(324, "All Nippon Airways", "ANA All Nippon Airways",
"NH", "ANA", "ALL NIPPON", "Japan", "Y");
Airline allNipponAirway = new Airline(325, "", "ANA All Nippon Airway",
"NP", "ANP", "ALL NIPPONP", "Japan", "Y");//duplicate name should be thrown
allNipponAirways.hasDuplicate(allNipponAirway);
}
@Test(expected = DataException.class)
public void hasDuplicateIATATest() throws DataException {
Airline allNipponAirways = new Airline(324, "All Nippon Airways", "ANA All Nippon Airways",
"NH", "ANA", "ALL NIPPON", "Japan", "Y");
Airline allNipponAirway = new Airline(325, "All Nippon Airway", "ANA All Nippon Airway",
"NH", "ANP", "ALL NIPPONP", "Japan", "Y");//duplicate name should be thrown
allNipponAirways.hasDuplicate(allNipponAirway);
}
@Test(expected = DataException.class)
public void hasDuplicateICAOTest() throws DataException {
Airline allNipponAirways = new Airline(324, "All Nippon Airways", "ANA All Nippon Airways",
"NH", "ANA", "ALL NIPPON", "Japan", "Y");
Airline allNipponAirway = new Airline(325, "All Nippon Airway", "ANA All Nippon Airway",
"NP", "ANA", "ALL NIPPONP", "Japan", "Y");//duplicate name should be thrown
allNipponAirways.hasDuplicate(allNipponAirway);
}
@Test(expected = DataException.class)
public void hasDuplicateAliasTest() throws DataException {
Airline allNipponAirways = new Airline(324, "All Nippon Airways", "ANA All Nippon Airways",
"NH", "ANA", "ALL NIPPON", "Japan", "Y");
Airline allNipponAirway = new Airline(325, "All Nippon Airway", "ANA All Nippon Airways",
"NH", "ANA", "ALL NIPPONP", "Japan", "Y");//duplicate name should be thrown
allNipponAirways.hasDuplicate(allNipponAirway);
}
@Test(expected = DataException.class)
public void hasDuplicateCallTest() throws DataException {
Airline allNipponAirways = new Airline(324, "All Nippon Airways", "ANA All Nippon Airways",
"NH", "ANA", "ALL NIPPON", "Japan", "Y");
Airline allNipponAirway = new Airline(325, "All Nippon Airway", "ANA All Nippon Airway",
"NH", "ANP", "ALL NIPPON", "Japan", "Y");//duplicate name should be thrown
allNipponAirways.hasDuplicate(allNipponAirway);
}
@Test
public void testCountry(){
Airline allNipponAirways = new Airline(324, "All Nippon Airways", "ANA All Nippon Airways",
"NH", "ANA", "ALL NIPPON", "Japan", "Y");
//,9,"U","Asia/Tokyo"
Country japan = new Country("U", "Japan");
allNipponAirways.setCountry(japan);
assertEquals(japan, allNipponAirways.getCountry());
}
@Test(expected = DataException.class)
public void getIDNullError() throws DataException{
Airline allNipponAirways = new Airline("All Nippon Airways", "ANA All Nippon Airways",
"NH", "ANA", "ALL NIPPON", "Japan", "Y");
allNipponAirways.getID();
}
@Test
public void testToString(){
//ID, Name, Alias, IATA, ICAO, CallSign, Country, Active
//324,"All Nippon Airways","ANA All Nippon Airways","NH","ANA","ALL NIPPON","Japan","Y"

@ -7,6 +7,8 @@ import org.junit.rules.ExpectedException;
import seng202.group9.Controller.DataException;
import seng202.group9.Core.Airport;
import seng202.group9.Core.City;
import seng202.group9.Core.Country;
import seng202.group9.Core.Route;
import java.util.ArrayList;
@ -35,6 +37,7 @@ public class AirportUnitTest {
}
assertEquals(heathrow.getName(), "Heathrow");
assertEquals(heathrow.getCityName(), "London");//check city
assertEquals(heathrow.getCountryName(), "United Kingdom");
assertEquals(heathrow.getIATA_FFA(), "LHR");//check IATA/FFA
assertEquals(heathrow.getICAO(), "EGLL");//check ICAO
assertTrue(heathrow.getLatitude() == 51.4775);//check latitude
@ -53,6 +56,8 @@ public class AirportUnitTest {
assertEquals(heathrow.getName(), "Hearthstone");
heathrow.setCityName("Blizzard Servers");//check city
assertEquals(heathrow.getCityName(), "Blizzard Servers");
heathrow.setCountryName("America");
assertEquals(heathrow.getCountryName(), "America");
heathrow.setIATA_FFA("HTS");//test set IATA/FFA
assertEquals(heathrow.getIATA_FFA(), "HTS");
heathrow.setICAO("BLIZ");// test set ICAO
@ -95,6 +100,16 @@ public class AirportUnitTest {
assertEquals(heathrow.getArrivalRoutes().get(2).getArrivalAirport(), "LHR2");
assertEquals(heathrow.getArrivalRoutes().get(3).getArrivalAirport(), "LHR3");
try {
heathrow.delArrivalRoutes(0);
} catch (DataException e) {
}
assertTrue(heathrow.getArrivalRoutes().size() == 3);
heathrow.delArrivalRoutes(heathrow.getArrivalRoutes().get(0));
assertTrue(heathrow.getArrivalRoutes().size() == 2);
//check add departrue routes;
heathrow.addDepartureRoutes(route1);
heathrow.addDepartureRoutes(routes);
@ -104,6 +119,15 @@ public class AirportUnitTest {
assertEquals(heathrow.getDepartureRoutes().get(2).getDepartureAirport(), "SIN2");
assertEquals(heathrow.getDepartureRoutes().get(3).getDepartureAirport(), "SIN3");
try {
heathrow.delDepartureRoutes(0);
} catch (DataException e) {
}
assertTrue(heathrow.getDepartureRoutes().size() == 3);
heathrow.delDepartureRoutes(heathrow.getDepartureRoutes().get(0));
assertTrue(heathrow.getDepartureRoutes().size() == 2);
//check set
heathrow.setArrivalRoutes(routes);
heathrow.setDepartureRoutes(routes);
@ -118,17 +142,126 @@ public class AirportUnitTest {
}
@Test
public void checkIDException(){
public void testCountryAndCity(){
Airport heathrow = new Airport(507, "Heathrow", "London", "United Kingdom", "LHR", "EGLL", 51.4775, -0.41389, 83);
Country UnitedKing = new Country("E", "United Kingdom");
heathrow.setCountry(UnitedKing);
City london = new City("London", "United Kingdom", 0, "Europe/London");
UnitedKing.addCities(london);
heathrow.setCity(london);
assertEquals(heathrow.getCity().getName(), "London");
assertEquals(heathrow.getCity().getCountry(), "United Kingdom");
assertEquals(heathrow.getCity().getTimeOlson(), "Europe/London");
assertTrue(heathrow.getCity().getTimezone() == 0);
//country tests
assertEquals(heathrow.getCountry().getDST(), "E");
assertEquals(heathrow.getCountry().getName(), "United Kingdom");
//check if the country has city london
assertEquals(heathrow.getCountry().getCities().get(0), london);
//check the get commands from the airport city
assertEquals(heathrow.getDST(), "E");
assertEquals(heathrow.getDST(), heathrow.getCountry().getDST());
assertEquals(heathrow.getCityName(), heathrow.getCity().getName());
assertEquals(heathrow.getCity().getCountry(), heathrow.getCountryName());
assertEquals(heathrow.getCity().getCountry(), "United Kingdom");
assertEquals(heathrow.getTz(), "Europe/London");
assertEquals(heathrow.getTz(), heathrow.getCity().getTimeOlson());
assertTrue(heathrow.getTimezone() == 0);
assertTrue(heathrow.getTimezone() == heathrow.getCity().getTimezone());
//check the get commands for airport countries
assertEquals(heathrow.getCountryName(), heathrow.getCountry().getName());
assertEquals(heathrow.getCountry().getDST(), heathrow.getDST());
assertEquals(heathrow.getCountry().getDST(), "E");
}
@Test
public void checkCalculateDistance(){
//check whether the airport distance between teh same airport is 0
Airport heathrow = new Airport(507, "Heathrow", "London", "United Kingdom", "LHR", "EGLL", 51.4775, -0.41389, 83);
Airport heathrow2 = new Airport(507, "Heathrow", "London", "United Kingdom", "LHR", "EGLL", 51.4775, -0.41389, 83);
assertTrue(heathrow.calculateDistance(heathrow2) == 0);
//check the correct distance between this and Edmonton
Airport edmonton = new Airport(26,"Kugaaruk","Pelly Bay","Canada","YBB","CYBB",68.534444,-89.808056,56);
//must be correct with a 0.3% margin of error calculations from http://www.movable-type.co.uk/scripts/latlong.html
assertTrue(heathrow.calculateDistance(edmonton) <= 4789 * 1.003);
assertTrue(heathrow.calculateDistance(edmonton) >= 4789 * 0.997);
}
@Test(expected = DataException.class)
public void checkNameDuplicate() throws DataException{
Airport heathrow = new Airport(507, "Heathrow", "London", "United Kingdom", "LHR", "EGLL", 51.4775, -0.41389, 83);
Airport heathrow2 = new Airport(507, "Heathrow", "Londons", "United Ksingdom", "LRR", "EPLL", 51.4775, -0.41389, 83);
heathrow.hasDuplicate(heathrow2);
}
@Test(expected = DataException.class)
public void checkEmptyNameDuplicate() throws DataException{
Airport heathrow = new Airport(507, "Heathrow", "London", "United Kingdom", "LHR", "EGLL", 51.4775, -0.41389, 83);
Airport heathrow2 = new Airport(507, "", "Londons", "United Ksingdom", "LRR", "EPLL", 51.4775, -0.41389, 83);
heathrow.hasDuplicate(heathrow2);
}
@Test(expected = DataException.class)
public void checkIATADuplicate() throws DataException{
Airport heathrow = new Airport(507, "Heathrow", "London", "United Kingdom", "LHR", "EGLL", 51.4775, -0.41389, 83);
Airport heathrow2 = new Airport(507, "Heathrsow", "Lossndon", "United Kisssngdom", "LHR", "EKLL", 51.4775, -0.41389, 83);
heathrow.hasDuplicate(heathrow2);
}
@Test(expected = DataException.class)
public void checkICAODuplicate() throws DataException{
Airport heathrow = new Airport(507, "Heathrow", "London", "United Kingdom", "LHR", "EGLL", 51.4775, -0.41389, 83);
Airport heathrow2 = new Airport(507, "Heathrows", "Lonsdon", "United Kisngdom", "LJR", "EGLL", 51.4775, -0.41389, 83);
heathrow.hasDuplicate(heathrow2);
}
@Test(expected = DataException.class)
public void checkIDException() throws DataException{
//507,"Heathrow","London","United Kingdom","LHR","EGLL",51.4775,-0.461389,83,0,"E","Europe/London"
//ID, NaWme, City, Country, IATA/FFA, ICAO, Latitude, Longitude, Altitude, Timezone, DST, Tz Data
Airport heathrow = new Airport("Heathrow", "London", "United Kingdom", "LHR", "EGLL", 51.4775, -0.41389, 83);
assertEquals(heathrow.getID(), 544);//check ID no id should be thrown
}
@Test(expected = DataException.class)
public void checkDelArrivalNoIndexFailure() throws DataException{
//507,"Heathrow","London","United Kingdom","LHR","EGLL",51.4775,-0.461389,83,0,"E","Europe/London"
//ID, NaWme, City, Country, IATA/FFA, ICAO, Latitude, Longitude, Altitude, Timezone, DST, Tz Data
Airport heathrow = new Airport("Heathrow", "London", "United Kingdom", "LHR", "EGLL", 51.4775, -0.41389, 83);
heathrow.delArrivalRoutes(0);
}
@Test(expected = DataException.class)
public void checkDelArrivalNegativeIndexFailure() throws DataException{
//507,"Heathrow","London","United Kingdom","LHR","EGLL",51.4775,-0.461389,83,0,"E","Europe/London"
//ID, NaWme, City, Country, IATA/FFA, ICAO, Latitude, Longitude, Altitude, Timezone, DST, Tz Data
Airport heathrow = new Airport("Heathrow", "London", "United Kingdom", "LHR", "EGLL", 51.4775, -0.41389, 83);
heathrow.delArrivalRoutes(-1);
}
@Test(expected = DataException.class)
public void checkDelDepartureNoIndexFailure() throws DataException{
//507,"Heathrow","London","United Kingdom","LHR","EGLL",51.4775,-0.461389,83,0,"E","Europe/London"
//ID, NaWme, City, Country, IATA/FFA, ICAO, Latitude, Longitude, Altitude, Timezone, DST, Tz Data
Airport heathrow = new Airport("Heathrow", "London", "United Kingdom", "LHR", "EGLL", 51.4775, -0.41389, 83);
heathrow.delDepartureRoutes(0);
}
@Test(expected = DataException.class)
public void checkDelDepatureNegativeIndexFailure() throws DataException{
//507,"Heathrow","London","United Kingdom","LHR","EGLL",51.4775,-0.461389,83,0,"E","Europe/London"
//ID, NaWme, City, Country, IATA/FFA, ICAO, Latitude, Longitude, Altitude, Timezone, DST, Tz Data
Airport heathrow = new Airport("Heathrow", "London", "United Kingdom", "LHR", "EGLL", 51.4775, -0.41389, 83);
heathrow.delDepartureRoutes(-1);
}
@Test
public void checkToString(){
//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, NaWme, City, Country, IATA/FFA, ICAO, Latitude, Longitude, Altitude, Timezone, DST, Tz Data
Airport heathrow = new Airport("Heathrow", "London", "United Kingdom", "LHR", "EGLL", 51.4775, -0.41389, 83);
thrown.expect(DataException.class);
thrown.expectMessage("ID not set.");
try {
assertEquals(heathrow.getID(), 544);//check ID no id should be thrown
} catch (DataException e) {
}
assertEquals(heathrow.toString(), "Heathrow Airport has ICAO: EGLL, IATA/FFA: LHR and is located at (51.4775, -0.41389).\n" +
" It has 0 departing routes and 0 arriving routes.");
}
}

@ -1,38 +1,32 @@
package seng202.group9;
import junit.framework.Test;
import junit.framework.TestCase;
import junit.framework.TestSuite;
import org.junit.Test;
import seng202.group9.Controller.App;
import seng202.group9.Controller.DataException;
import static org.junit.Assert.*;
/**
* Unit test for simple App.
*/
public class AppTest
extends TestCase
{
/**
* Create the test case
*
* @param testName name of the test case
*/
public AppTest( String testName )
{
super( testName );
}
public class AppTest {
@Test
public void testApp(){
App app = new App();
assertTrue(app.getMenuController() == null);
assertTrue(app.getPrimaryStage() == null);
try {
app.createDataset("FORUNITTESTINGDATASET");
} catch (DataException e) {
e.printStackTrace();
}
assertEquals(app.getCurrentDataset().getName(), "FORUNITTESTINGDATASET");
/**
* @return the suite of tests being tested
*/
public static Test suite()
{
return new TestSuite( AppTest.class );
}
app.deleteDataset(app.getCurrentDataset());
/**
* Rigourous Test :-)
*/
public void testApp()
{
assertTrue( true );
for (int i = 0; i < app.getDatasets().size(); i++){
assertTrue(!app.getDatasets().get(i).getName().equals("FORUNITTESTINGDATASET"));
}
//more to come as the program upgrades for for as of now this is the limit.
}
}

@ -0,0 +1,84 @@
package seng202.group9;/**
* Created by Gondr on 18/09/2016.
*/
import static org.junit.Assert.*;
import org.junit.Test;
import seng202.group9.Controller.DataException;
import seng202.group9.Core.Airport;
import seng202.group9.Core.City;
import java.util.ArrayList;
public class CityTest {
@Test
public void testConstructor(){
//Matsumoto, Japan 9,"Asia/Tokyo"
City matsumoto = new City("Matsumoto", "Japan", 9, "Asia/Tokyo");
assertEquals(matsumoto.getName(), "Matsumoto");
assertEquals(matsumoto.getCountry(), "Japan");
assertTrue(matsumoto.getTimezone() == 9);
assertEquals(matsumoto.getTimeOlson(), "Asia/Tokyo");
//check setters
matsumoto.setName("matsumoto");
matsumoto.setCountry("japan");
matsumoto.setTimezone(10);
matsumoto.setTimeOlson("Japan/Tokyo");
assertEquals(matsumoto.getName(), "matsumoto");
assertEquals(matsumoto.getCountry(), "japan");
assertTrue(matsumoto.getTimezone() == 10);
assertEquals(matsumoto.getTimeOlson(), "Japan/Tokyo");
}
@Test
public void testAirports(){
City matsumoto = new City("Matsumoto", "Japan", 9, "Asia/Tokyo");
Airport matsumotoAirport = new Airport(2280, "Matsumoto", "Matsumoto", "Japan", "MMJ", "RJAF", 36.166758, 137.922669, 2182);
assertTrue(matsumoto.getAirports().size() == 0);
matsumoto.addAirport(matsumotoAirport);
assertEquals(matsumoto.getAirports().get(0), matsumotoAirport);
assertTrue(matsumoto.getAirports().size() == 1);
matsumoto.delAirport(matsumotoAirport);
assertTrue(matsumoto.getAirports().size() == 0);
ArrayList<Airport> airports = new ArrayList<Airport>();
airports.add(matsumotoAirport);
airports.add(matsumotoAirport);
matsumoto.addAirport(airports);
assertTrue(matsumoto.getAirports().size() == 2);
try {
matsumoto.delAirport(0);
assertTrue(matsumoto.getAirports().size() == 1);
matsumoto.delAirport(0);
}catch (DataException e){
}
matsumoto.delAirport(matsumotoAirport);
//set the airports
matsumoto.setAirports(airports);
assertTrue(matsumoto.getAirports().size() == 2);
}
@Test(expected = DataException.class)
public void testDelAirportsMissingIndexErrors() throws DataException{
City matsumoto = new City("Matsumoto", "Japan", 9, "Asia/Tokyo");
matsumoto.delAirport(0);
}
@Test(expected = DataException.class)
public void testDelAirportsNegativeIndexErrors() throws DataException{
City matsumoto = new City("Matsumoto", "Japan", 9, "Asia/Tokyo");
matsumoto.delAirport(-1);
}
@Test
public void testString(){
City matsumoto = new City("Matsumoto", "Japan", 9, "Asia/Tokyo");
assertEquals(matsumoto.toString(), "Matsumoto has 0 Airports and is in Asia/Tokyo");
}
}

@ -0,0 +1,118 @@
package seng202.group9;/**
* Created by Gondr on 19/09/2016.
*/
import static org.junit.Assert.*;
import org.junit.Test;
import seng202.group9.Controller.DataException;
import seng202.group9.Core.Airline;
import seng202.group9.Core.City;
import seng202.group9.Core.Country;
import seng202.group9.Core.Position;
import java.lang.reflect.Array;
import java.util.ArrayList;
public class CountryTest {
@Test
public void testConstructor(){
Country country = new Country("A", "Japan");
assertEquals(country.getName(), "Japan");
assertEquals(country.getDST(), "A");
country.setName("United Kingdom");
country.setDST("E");
assertEquals(country.getName(), "United Kingdom");
assertEquals(country.getDST(), "E");
}
@Test
public void testAirlines(){
Country country = new Country("A", "Japan");
//71,"Advanced Air Co.",\N,"","ADD","","Japan","N"
Airline advancedAir = new Airline(71,"Advanced Air Co.","\\N","","ADD","","Japan","N");
//248,"ANA & JP Express",\N,"","AJV","AYJAY CARGO","Japan","N"
Airline jPExpress = new Airline(248,"ANA & JP Express","\\N","","AJV","AYJAY CARGO","Japan","N");
country.addAirline(advancedAir);
assertEquals(country.getAirlines().get(0), advancedAir);
assertTrue(country.getAirlines().size() == 1);
country.delAirline(advancedAir);
assertTrue(country.getAirlines().size() == 0);
ArrayList<Airline> airlines = new ArrayList<Airline>();
airlines.add(advancedAir);
airlines.add(jPExpress);
country.addAirline(airlines);
assertTrue(country.getAirlines().size() == 2);
try {
country.delAirline(0);
} catch (DataException e) {
e.printStackTrace();
}
assertTrue(country.getAirlines().size() == 1);
country.setAirlines(airlines);
assertTrue(country.getAirlines().size() == 2);
//Tokyo, Japan,9,"Asia/Tokyo"
City tokyo = new City("Tokyo", "Japan", 9, "Asia/Tokyo");
City matsumoto = new City("Matsumoto", "Japan", 9, "Asia/Tokyo");
country.addCities(tokyo);
assertEquals(country.getCities().get(0), tokyo);
country.delCities(tokyo);
assertTrue(country.getCities().size() == 0);
ArrayList<City> cities = new ArrayList<City>();
cities.add(tokyo);
cities.add(matsumoto);
country.addCities(cities);
assertTrue(country.getCities().size() == 2);
try {
country.delCities(0);
} catch (DataException e) {
fail("There is a city deletable");
}
country.setCities(cities);
assertTrue(country.getCities().size() == 2);
Position position = new Position(0, 0);
country.setPosition(position);
assertEquals(country.getPosition(), position);
}
@Test (expected = DataException.class)
public void delAirlineIndexOutOfRange() throws DataException{
Country country = new Country("A", "Japan");
country.delAirline(0);
}
@Test (expected = DataException.class)
public void delAirlineIndexNegative() throws DataException{
Country country = new Country("A", "Japan");
country.delAirline(-1);
}
@Test (expected = DataException.class)
public void delCityIndexOutOfRange() throws DataException{
Country country = new Country("A", "Japan");
country.delCities(0);
}
@Test (expected = DataException.class)
public void delCityIndexNegative() throws DataException{
Country country = new Country("A", "Japan");
country.delCities(-1);
}
}

@ -0,0 +1,210 @@
package seng202.group9;/**
* Created by Gondr on 19/09/2016.
*/
import static org.junit.Assert.*;
import org.junit.AfterClass;
import org.junit.Test;
import seng202.group9.Controller.App;
import seng202.group9.Controller.DataException;
import seng202.group9.Controller.Dataset;
import seng202.group9.Core.*;
public class DatasetTest {
static App app = new App();
@Test
public void DatasetConstructor(){
try {
app.createDataset("FORUNITTESTINGONLY");
} catch (DataException e) {
fail("There seems to be database already by this name");
}
Dataset dataset = app.getCurrentDataset();
assertEquals(dataset.getName(), "FORUNITTESTINGONLY");
try {
dataset.importAirline("res/Reduced Samples/Airlines.txt");
} catch (DataException e) {
fail("The sample file is missing");
}
assertTrue(dataset.getAirlines().size() == dataset.getAirlineDictionary().size());
try {
dataset.importAirport("res/Reduced Samples/Airports.txt");
} catch (DataException e) {
fail("The sample file is missing");
}
assertTrue(dataset.getAirports().size() == dataset.getAirportDictionary().size());
assertTrue(dataset.getCities().size() == dataset.getCityDictionary().size());
assertTrue(dataset.getCountries().size() == dataset.getCountryDictionary().size());
try {
dataset.importRoute("res/Reduced Samples/Routes.txt");
} catch (DataException e) {
fail("The sample file is missing");
}
assertTrue(dataset.getRoutes().size() == dataset.getRouteDictionary().size());
try {
dataset.importFlight("res/Reduced Samples/NZCH-WSSS.csv");
} catch (DataException e) {
fail("The sample file is missing");
}
assertTrue(dataset.getFlightPaths().size() == dataset.getFlightPathDictionary().size());
dataset.createDataLinks();
assertTrue(dataset.getAirlines().size() == dataset.getAirlineDictionary().size());
assertTrue(dataset.getAirports().size() == dataset.getAirportDictionary().size());
assertTrue(dataset.getCities().size() == dataset.getCityDictionary().size());
assertTrue(dataset.getCountries().size() == dataset.getCountryDictionary().size());
assertTrue(dataset.getRoutes().size() == dataset.getRouteDictionary().size());
assertTrue(dataset.getFlightPaths().size() == dataset.getFlightPathDictionary().size());
//make sure that datalinks does not increase the size of the dictionaries etc
app.deleteDataset(app.getCurrentDataset());
}
@Test
public void checkoutDataLinks() throws DataException {
try {
app.createDataset("FORUNITTESTINGONLY");
} catch (DataException e) {
fail("There seems to be database already by this name");
}
Dataset dataset = app.getCurrentDataset();
Airline allNipponAirways = new Airline(324, "All Nippon Airways", "ANA All Nippon Airways",
"NH", "ANA", "ALL NIPPON", "Japan", "Y");
dataset.addAirline(allNipponAirways);
assertEquals(dataset.getAirlines().get(0), allNipponAirways);
dataset.addAirline("British Airways","\\N","BA","BAW","SPEEDBIRD","United Kingdom","Y");
assertEquals(dataset.getAirlines().get(1).getName(), "British Airways");
assertTrue(dataset.getAirlines().get(0).getID() != -1);
assertTrue(dataset.getAirlines().get(1).getID() != -1);
dataset.addAirport("Heathrow","London","United Kingdom","LHR","EGLL","51.4775","-0.461389","83","0","E","Europe/London");
dataset.addAirport("Changi Intl","Singapore","Singapore","SIN","WSSS","1.350189","103.994433","22","8","N","Asia/Singapore");
dataset.addAirport("Matsumoto","Matsumoto","Japan","MMJ","RJAF","36.166758","137.922669","2182","9","U","Asia/Tokyo");
assertTrue(dataset.getAirports().size() == 3);
assertTrue(dataset.getCities().size() == 3);
assertTrue(dataset.getCountries().size() == 3);
Route route = new Route("BA", "SIN", "LHR", "", 0, "744 777");
dataset.addRoute(route);
dataset.addRoute("NH", "SIN", "LHR", "", "0","777");
//checked if everything is linked together properly
assertTrue(dataset.getAirlines().get(0).getCountry() != null);
assertTrue(dataset.getAirlines().get(1).getCountry() != null);
assertTrue(dataset.getAirlines().get(0).getRoutes().size() == 1);
assertTrue(dataset.getAirlines().get(1).getRoutes().size() == 1);
assertTrue(dataset.getCountryDictionary().get("United Kingdom").getAirlines().size() == 1);
assertTrue(dataset.getCountryDictionary().get("Japan").getAirlines().size() == 1);
assertEquals(dataset.getRoutes().get(0).getSourceAirport(), dataset.getAirportDictionary().get("Changi Intl"));
assertEquals(dataset.getRoutes().get(0).getDestinationAirport(), dataset.getAirportDictionary().get("Heathrow"));
assertEquals(dataset.getRoutes().get(0).getAirline(), dataset.getAirlineDictionary().get("British Airways"));
assertEquals(dataset.getRoutes().get(1).getSourceAirport(), dataset.getAirportDictionary().get("Changi Intl"));
assertEquals(dataset.getRoutes().get(1).getDestinationAirport(), dataset.getAirportDictionary().get("Heathrow"));
assertEquals(dataset.getRoutes().get(1).getAirline(), dataset.getAirlineDictionary().get("All Nippon Airways"));
//slowly delete everything and check if the links are retained/gone.
dataset.deleteRoute(0);
assertTrue(dataset.getRoutes().size() == 1);
assertTrue(dataset.getRoutes().size() == dataset.getRouteDictionary().size());
assertTrue(dataset.getAirlines().get(0).getRoutes().size() == 1);
assertTrue(dataset.getAirlines().get(1).getRoutes().size() == 0);
//add the route back
dataset.addRoute(route);
dataset.deleteAirport(0);
assertTrue(dataset.getCityDictionary().get("London") == null);
assertTrue(dataset.getCountryDictionary().get("United Kingdom") == null);
assertTrue(dataset.getRoutes().get(0).getDestinationAirport() == null);
assertTrue(dataset.getRoutes().get(1).getDestinationAirport() == null);
dataset.addAirport("Heathrow","London","United Kingdom","LHR","EGLL","51.4775","-0.461389","83","0","E","Europe/London");
//check that all changes are now back;
assertTrue(dataset.getCityDictionary().get("London") != null);
assertTrue(dataset.getCountryDictionary().get("United Kingdom") != null);
assertTrue(dataset.getRoutes().get(0).getDestinationAirport() != null);
assertTrue(dataset.getRoutes().get(1).getDestinationAirport() != null);
dataset.deleteAirline(dataset.getAirlines().get(0));
assertTrue(dataset.getRoutes().get(0).getAirline() == null);
assertTrue(dataset.getCountryDictionary().get("Japan").getAirlines().size() == 0);
//clean database and check whether dictionarys and arrays are empty
dataset.deleteAirline(0);
dataset.deleteAirport(0);
dataset.deleteAirport(0);
dataset.deleteAirport(0);
dataset.deleteRoute(0);
dataset.deleteRoute(0);
assertTrue(dataset.getAirlines().size() == 0);
assertTrue(dataset.getAirports().size() == 0);
assertTrue(dataset.getAirlineDictionary().size() == 0);
assertTrue(dataset.getAirportDictionary().size() == 0);
assertTrue(dataset.getRoutes().size() == 0);
assertTrue(dataset.getRouteDictionary().size() == 0);
assertTrue(dataset.getCities().size() == 0);
assertTrue(dataset.getCityDictionary().size() == 0);
assertTrue(dataset.getCountries().size() == 0);
assertTrue(dataset.getCountryDictionary().size() == 0);
app.deleteDataset(app.getCurrentDataset());
}
@Test
public void flightPathTester() throws DataException {
try {
app.createDataset("FORUNITTESTINGONLY");
} catch (DataException e) {
fail("There seems to be database already by this name");
}
Dataset dataset = app.getCurrentDataset();
try {
dataset.importFlight("res/Reduced Samples/NZCH-WSSS.csv");
} catch (DataException e) {
fail("The sample file is missing");
}
FlightPoint flightPoint = dataset.getFlightPaths().get(0).getFlightPoints().get(6);
FlightPoint flightPoint1 = dataset.getFlightPaths().get(0).getFlightPoints().get(5);
dataset.deleteFlightPoint(1, 5);
assertEquals(dataset.getFlightPaths().get(0).getFlightPoints().get(5), flightPoint);
int currentSize = dataset.getFlightPaths().get(0).getFlightPoints().size();
dataset.deleteFlightPoint(flightPoint, dataset.getFlightPaths().get(0));
assertTrue(dataset.getFlightPaths().get(0).getFlightPoints().size() == currentSize - 1);
dataset.addFlightPointToPath(flightPoint1, 5);
dataset.addFlightPointToPath(flightPoint, 6);
assertEquals(dataset.getFlightPaths().get(0).getFlightPoints().get(5).getName(), flightPoint1.getName());
assertEquals(dataset.getFlightPaths().get(0).getFlightPoints().get(6).getName(), flightPoint.getName());
app.deleteDataset(app.getCurrentDataset());
}
@AfterClass
public static void deleteDataset(){
while(app.getCurrentDataset() != null) {
app.deleteDataset(app.getCurrentDataset());
}
}
}

@ -0,0 +1,222 @@
package seng202.group9;/**
* Created by Gondr on 19/09/2016.
*/
import static org.junit.Assert.*;
import org.junit.AfterClass;
import org.junit.Test;
import seng202.group9.Controller.*;
public class FilterUnitTest {
static App app = new App();
@Test
public void airlineFilterTest(){
try {
app.createDataset("FORUNITTESTINGONLY");
} catch (DataException e) {
fail("There seems to be database already by this name");
}
Dataset dataset = app.getCurrentDataset();
try {
dataset.importAirline("res/Reduced Samples/Airlines.txt");
} catch (DataException e) {
fail("The sample file is missing");
}
AirlineFilter airlineFilter = new AirlineFilter(dataset.getAirlines());
int size = airlineFilter.getFilteredData().size();
airlineFilter.filterActive("Y");
assertTrue(size != airlineFilter.getFilteredData().size());
airlineFilter.reset();
airlineFilter.filterAlias("A");
assertTrue(size != airlineFilter.getFilteredData().size());
airlineFilter.reset();
airlineFilter.filterCallsign("Y");
assertTrue(size != airlineFilter.getFilteredData().size());
airlineFilter.reset();
airlineFilter.filterCountry("E");
assertTrue(size != airlineFilter.getFilteredData().size());
airlineFilter.reset();
airlineFilter.filterIATA("I");
assertTrue(size != airlineFilter.getFilteredData().size());
airlineFilter.reset();
airlineFilter.filterICAO("O");
assertTrue(size != airlineFilter.getFilteredData().size());
airlineFilter.reset();
airlineFilter.filterName("T");
assertTrue(size != airlineFilter.getFilteredData().size());
airlineFilter.printFilter();
airlineFilter.setBaseList(airlineFilter.getFilteredData());
app.deleteDataset(app.getCurrentDataset());
}
@Test
public void airportFilterTest(){
try {
app.createDataset("FORUNITTESTINGONLY");
} catch (DataException e) {
fail("There seems to be database already by this name");
}
Dataset dataset = app.getCurrentDataset();
try {
dataset.importAirport("res/Reduced Samples/Airports.txt");
} catch (DataException e) {
fail("The sample file is missing");
}
AirportFilter filter = new AirportFilter(dataset.getAirports());
int size = dataset.getAirports().size();
filter.filterName("d");
assertTrue(size != filter.getFilteredData().size());
filter.reset();
filter.filterCity("P");
assertTrue(size != filter.getFilteredData().size());
filter.reset();
filter.filterCountry("Q");
assertTrue(size != filter.getFilteredData().size());
filter.reset();
filter.filterIATA_FFA("U");
assertTrue(size != filter.getFilteredData().size());
filter.reset();
filter.filterICAO("L");
assertTrue(size != filter.getFilteredData().size());
filter.reset();
filter.filterLatitude("7");
assertTrue(size != filter.getFilteredData().size());
filter.reset();
filter.filterLongitude("4");
assertTrue(size != filter.getFilteredData().size());
filter.reset();
filter.filterAltitude("0");
assertTrue(size != filter.getFilteredData().size());
filter.reset();
filter.filterTimezone("1");
assertTrue(size != filter.getFilteredData().size());
filter.reset();
filter.filterOlson("Europe");
assertTrue(size != filter.getFilteredData().size());
filter.reset();
filter.filterDST("A");
assertTrue(size != filter.getFilteredData().size());
filter.printFilter();
filter.setBaseList(filter.getFilteredData());
size = filter.getFilteredData().size();
filter.reset();
assertTrue(size == filter.getFilteredData().size());
app.deleteDataset(app.getCurrentDataset());
}
@Test
public void routeFilterTest(){
try {
app.createDataset("FORUNITTESTINGONLY");
} catch (DataException e) {
fail("There seems to be database already by this name");
}
Dataset dataset = app.getCurrentDataset();
try {
dataset.importRoute("res/Reduced Samples/Routes.txt");
} catch (DataException e) {
fail("The sample file is missing");
}
RouteFilter filter = new RouteFilter(dataset.getRoutes());
int size = dataset.getRoutes().size();
filter.filterAirline("N");
assertTrue(size != filter.getFilteredData().size());
filter.reset();
filter.filterSourceAirport("H");
assertTrue(size != filter.getFilteredData().size());
filter.reset();
filter.filterDestinationAirport("P");
assertTrue(size != filter.getFilteredData().size());
filter.reset();
filter.filterCodeshare("Y");
assertTrue(size != filter.getFilteredData().size());
filter.reset();
filter.filterDestinationStops("3");
assertTrue(size != filter.getFilteredData().size());
filter.reset();
filter.filterEquipment("777");
assertTrue(size != filter.getFilteredData().size());
filter.printFilter();
filter.setBaseList(filter.getFilteredData());
size = filter.getFilteredData().size();
filter.reset();
assertTrue(filter.getFilteredData().size() == size);
app.deleteDataset(app.getCurrentDataset());
}
@AfterClass
public static void deleteDataset(){
while(app.getCurrentDataset() != null) {
app.deleteDataset(app.getCurrentDataset());
}
}
}

@ -0,0 +1,115 @@
package seng202.group9;/**
* Created by Gondr on 19/09/2016.
*/
import static org.junit.Assert.*;
import org.junit.Test;
import seng202.group9.Controller.DataException;
import seng202.group9.Core.FlightPath;
import seng202.group9.Core.FlightPoint;
import seng202.group9.Core.RoutePath;
import java.lang.reflect.Array;
import java.util.ArrayList;
public class FlightPathTest {
@Test
public void testConstructor(){
FlightPath flightPath = new FlightPath(1, "NZCH", "WSSS");
try {
assertTrue(flightPath.getID() == 1);
} catch (DataException e) {
fail("There is an ID set already.");
}
assertEquals(flightPath.arrivesAt(), "WSSS");
assertEquals(flightPath.departsFrom(), "NZCH");
flightPath.setArrivalAirport("WSSI");
flightPath.setDepartureAirport("NZAK");
flightPath.setID(2);
try {
assertTrue(flightPath.getID() == 2);
} catch (DataException e) {
fail("There is an ID set already.");
}
assertEquals(flightPath.arrivesAt(), "WSSI");
assertEquals(flightPath.departsFrom(), "NZAK");
}
@Test(expected = DataException.class)
public void testIDError() throws DataException{
FlightPath flightPath = new FlightPath("NZCH", "WSSS");
flightPath.getID();
}
@Test
public void testFlightPoints(){
FlightPath flightPath = new FlightPath(1, "NZCH", "WSSS");
FlightPoint startPoint = new FlightPoint("NZCH", 1, 1, "APT", "", 0, 0, 0, 0, 172.5336822, -43.48664019);
FlightPoint endPoint = new FlightPoint("WSSS", 2, 1, "APT", "", 0, 0, 0, 0, 103.995603, 1.35191714);
ArrayList<FlightPoint> flightPoints = new ArrayList<FlightPoint>();
flightPoints.add(startPoint);
flightPoints.add(endPoint);
flightPath.setFlightPoints(flightPoints);
assertTrue(flightPath.getFlightPoints().size() == 2);
assertTrue(flightPath.getFlight().size() == 2);
flightPath.delFlightPoint(endPoint);
assertTrue(flightPath.getFlightPoints().size() == 1);
flightPath.addFlightPoint(endPoint);
assertTrue(flightPath.getFlightPoints().size() == 2);
assertEquals(flightPath.getFlightPoints().get(1), endPoint);
try {
flightPath.delFlightPoint(0);
} catch (DataException e) {
fail("There is an existing point therefore it should be deletable");
}
flightPath.addFlightPoint(startPoint, 0);
assertEquals(flightPath.getFlightPoints().get(0), startPoint);
flightPath.addFlightPoint(flightPoints);
assertTrue(flightPath.getFlightPoints().size() == 4);
}
@Test
public void testAddingFlightPointAtInvalidPoints(){
FlightPath flightPath = new FlightPath(1, "NZCH", "WSSS");
FlightPoint startPoint = new FlightPoint("NZCH", 1, 1, "APT", "", 0, 0, 0, 0, 172.5336822, -43.48664019);
FlightPoint endPoint = new FlightPoint("WSSS", 2, 1, "APT", "", 0, 0, 0, 0, 103.995603, 1.35191714);
flightPath.addFlightPoint(startPoint);
flightPath.addFlightPoint(startPoint);
flightPath.addFlightPoint(startPoint);
flightPath.addFlightPoint(endPoint, -1);
flightPath.addFlightPoint(endPoint, 100);
assertEquals(flightPath.getFlightPoints().get(4), endPoint);
assertEquals(flightPath.getFlightPoints().get(4), endPoint);
}
@Test
public void getRoutePath(){
FlightPath flightPath = new FlightPath(1, "NZCH", "WSSS");
FlightPoint startPoint = new FlightPoint("NZCH", 1, 1, "APT", "", 0, 0, 0, 0, 172.5336822, -43.48664019);
FlightPoint endPoint = new FlightPoint("WSSS", 2, 1, "APT", "", 0, 0, 0, 0, 103.995603, 1.35191714);
flightPath.addFlightPoint(startPoint);
flightPath.addFlightPoint(endPoint);
RoutePath routePath = flightPath.getRoutePath();
assertTrue(routePath.getRoute().get(0).lat == 172.5336822);
assertTrue(routePath.getRoute().get(0).lng == -43.48664019);
assertTrue(routePath.getRoute().get(1).lat == 103.995603);
assertTrue(routePath.getRoute().get(1).lng == 1.35191714);
}
}

@ -0,0 +1,82 @@
package seng202.group9;/**
* Created by Gondr on 19/09/2016.
*/
import static org.junit.Assert.*;
import org.junit.Test;
import seng202.group9.Controller.DataException;
import seng202.group9.Core.FlightPoint;
public class FlightPointTest {
@Test
public void testConstructor(){
FlightPoint startPoint = new FlightPoint("NZCH", 1, 1, "APT", "", 0, 0, 0, 0, 172.5336822, -43.48664019);
try {
assertTrue(startPoint.getID() == 1);
assertTrue(startPoint.getIndexID() == 1);
} catch (DataException e) {
fail("The Initial ID is set for this class");
}
assertEquals(startPoint.getName(), "NZCH");
assertEquals(startPoint.getType(), "APT");
assertEquals(startPoint.getVia(), "");
assertTrue(startPoint.getHeading() == 0);
assertTrue(startPoint.getLegDistance() == 0);
assertTrue(startPoint.getAltitude() == 0);
assertTrue(startPoint.getTotalDistance() == 0);
assertTrue(startPoint.getLatitude() == 172.5336822);
assertTrue(startPoint.getLongitude() == -43.48664019);
startPoint.setName("NZAK");
startPoint.setType("FIX");
startPoint.setID(2);
startPoint.setIndexID(2);
startPoint.setVia("SIN");
startPoint.setHeading(15);
startPoint.setLegDistance(95.4);
startPoint.setAltitude(0.5);
startPoint.setTotalDistance(540.8);
startPoint.setLatitude(172.5);
startPoint.setLongitude(-43.5);
try {
assertTrue(startPoint.getID() == 2);
assertTrue(startPoint.getIndexID() == 2);
} catch (DataException e) {
fail("The Initial ID is set for this class");
}
assertEquals(startPoint.getName(), "NZAK");
assertEquals(startPoint.getType(), "FIX");
assertEquals(startPoint.getVia(), "SIN");
assertTrue(startPoint.getHeading() == 15);
assertTrue(startPoint.getLegDistance() == 95.4);
assertTrue(startPoint.getAltitude() == 0.5);
assertTrue(startPoint.getTotalDistance() == 540.8);
assertTrue(startPoint.getLatitude() == 172.5);
assertTrue(startPoint.getLongitude() == -43.5);
}
@Test (expected = DataException.class)
public void checkIDFail() throws DataException{
FlightPoint endPoint = new FlightPoint("APT", "WSSS", 0, 103.995603, 1.35191714);
endPoint.getID();
}
@Test (expected = DataException.class)
public void checkIndexIDFail() throws DataException{
FlightPoint endPoint = new FlightPoint("APT", "WSSS", 0, 103.995603, 1.35191714);
endPoint.getIndexID();
}
@Test (expected = DataException.class)
public void checkIndexFail() throws DataException{
FlightPoint endPoint = new FlightPoint("APT", "WSSS", 0, 103.995603, 1.35191714);
endPoint.getIndex();
}
}

@ -0,0 +1,37 @@
package seng202.group9;/**
* Created by Gondr on 19/09/2016.
*/
import static org.junit.Assert.*;
import org.junit.Test;
import seng202.group9.Core.Position;
import seng202.group9.Core.RoutePath;
public class RoutePathTest {
@Test
public void testConstructors(){
RoutePath routePath = new RoutePath(
new Position(5, 6),
new Position(0, 1)
);
assertTrue(routePath.getRoute().get(0).lat == 5);
assertTrue(routePath.getRoute().get(0).lng == 6);
assertTrue(routePath.getRoute().get(1).lat == 0);
assertTrue(routePath.getRoute().get(1).lng == 1);
assertTrue(routePath.getRoute().size() == 2);
routePath.addPosition(new Position(3, 4));
assertTrue(routePath.getRoute().size() == 3);
assertTrue(routePath.getRoute().get(2).lat == 3);
assertTrue(routePath.getRoute().get(2).lng == 4);
assertEquals(routePath.toJSONArray(), "[{lat: 5.000000, lng: 6.000000}, {lat: 0.000000, lng: 1.000000}, {lat: 3.000000, lng: 4.000000}, ]");
RoutePath routePath1 = new RoutePath();
assertTrue(routePath1.getRoute().size() == 0);
}
}

@ -1,20 +1,26 @@
package seng202.group9;
import org.junit.rules.ExpectedException;
import javafx.scene.chart.PieChart;
import org.junit.Test;
import junit.framework.TestCase;
import seng202.group9.Controller.DataException;
import seng202.group9.Core.Airline;
import seng202.group9.Core.Airport;
import seng202.group9.Core.Route;
import seng202.group9.Core.RoutePath;
import static junit.framework.TestCase.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
/**
*
* Route tests
* @author Fan-Wu Yang
*
*/
public class RouteTest extends TestCase {
//exception checker
public ExpectedException thrown = ExpectedException.none();
public class RouteTest{
@Test
public void testRouteGetSet(){
@ -36,6 +42,7 @@ public class RouteTest extends TestCase {
///////////////
//test setters
///////////////
route.setID(5);
route.setAirlineName("BAH");
route.setArrivalAirport("LEFT-HAND-RULE");
route.setDepartureAirport("SING-SONG");
@ -43,7 +50,12 @@ public class RouteTest extends TestCase {
route.setStops(5);
route.setEquipment("747 840");
assertEquals(route.getDepartureAirport(), "SING-SONG");
try {
assertTrue(route.getID() == 5);
} catch (DataException e) {
fail("ID has been set it shouldn't fail.");
}
assertEquals(route.getDepartureAirport(), "SING-SONG");
assertEquals(route.getArrivalAirport(), "LEFT-HAND-RULE");
assertEquals(route.getAirlineName(), "BAH");
assertEquals(route.getCode(), "Y");
@ -59,23 +71,112 @@ public class RouteTest extends TestCase {
}
}
@Test
public void testRouteIDException() throws DataException{
@Test(expected = DataException.class)
public void testRouteIDException() throws DataException {
//sample entry
//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 route = new Route("BA", "SIN", "LHR", "", 0, "744 777");
/////////////////////////////////////////////////
//test that id is not set and throws an exception
/////////////////////////////////////////////////
thrown.expect(DataException.class);
thrown.expectMessage("ID not set. Error in Database Implementation for adding code.");
try{
route.getID();
}catch (DataException e){
//e.printStackTrace();
}
route.getID();
}
@Test
public void testAirlineAdding(){
//1355,"British Airways",\N,"BA","BAW","SPEEDBIRD","United Kingdom","Y" AIrline
Airline airline = new Airline(1355,"British Airways","\\N","BA","BAW","SPEEDBIRD","United Kingdom","Y");
//sample entry
//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 route = new Route("BA", "SIN", "LHR", "", 0, "744 777");
route.setAirline(airline);
assertEquals(airline, route.getAirline());
try {
assertTrue(airline.getID() == route.getAirlineID());
assertTrue(route.getAirlineID() == 1355);
}catch(DataException e){
fail("The ID is set before it should not fail.");
}
Airport sourceAirport = new Airport(3316,"Changi Intl","Singapore","Singapore","SIN","WSSS",1.350189,103.994433,22);
Airport destAirport = new Airport(507,"Heathrow","London","United Kingdom","LHR","EGLL",51.4775,-0.461389,83);
route.setSourceAirport(sourceAirport);
route.setDestinationAirport(destAirport);
assertEquals(sourceAirport, route.getSourceAirport());
assertEquals(destAirport, route.getDestinationAirport());
try {
assertTrue(route.getSourceID() == 3316);
assertTrue(route.getDestID() == 507);
} catch (DataException e) {
e.printStackTrace();
}
assertEquals(route.getDepartureAirport(), route.getSourceAirport().getIATA_FFA());
assertEquals(route.getArrivalAirport(), route.getDestinationAirport().getIATA_FFA());
}
@Test(expected = DataException.class)
public void testNameDuplicate() throws DataException{
//sample entry
//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
//should only be a duplicate if every entry is the same
Route route = new Route("BA", "SIN", "LHR", "", 0, "744 777");
Route route1 = new Route("BA", "SIN", "LHR", "", 0, "744 777");
Route route2 = new Route("BA", "SII", "LHR", "", 0, "744 777");
Route route3 = new Route("BQ", "SIN", "LHR", "", 0, "744 777");
Route route4 = new Route("BA", "SIN", "RHR", "", 0, "744 777");
Route route5 = new Route("BA", "SIN", "LHR", "Y", 0, "744 777");
Route route6 = new Route("BA", "SIN", "LHR", "", 8, "744 777");
Route route7 = new Route("BA", "SIN", "LHR", "", 0, "745 777");
//this shouldn't throw
try {
route.hasDuplicate(route2);
route.hasDuplicate(route3);
route.hasDuplicate(route4);
route.hasDuplicate(route5);
route.hasDuplicate(route6);
route.hasDuplicate(route7);
} catch (DataException e) {
fail("These two routes are different they should not throw an error");
}
//this should throw an exception.
route.hasDuplicate(route1);
}
@Test
public void testGetPath(){
//sample entry
//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
//should only be a duplicate if every entry is the same
Route route = new Route("BA", "SIN", "LHR", "", 0, "744 777");
Airport sourceAirport = new Airport(3316,"Changi Intl","Singapore","Singapore","SIN","WSSS",1.350189,103.994433,22);
Airport destAirport = new Airport(507,"Heathrow","London","United Kingdom","LHR","EGLL",51.4775,-0.461389,83);
assertTrue(route.getRoutePath().getRoute().size() == 0);
route.setSourceAirport(sourceAirport);
assertTrue(route.getRoutePath().getRoute().size() == 0);
route.setDestinationAirport(destAirport);
assertTrue(route.getRoutePath().getRoute().size() == 2);
}
@Test
public void testToString() {
//sample entry
//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
//should only be a duplicate if every entry is the same
Route route = new Route("BA", "SIN", "LHR", "", 0, "744 777");
assertEquals(route.toString(), "BA flies from SIN to LHR on a 744 777 stopping 0 amount of times");
}
}

@ -0,0 +1,23 @@
package seng202.group9;/**
* Created by Gondr on 19/09/2016.
*/
import static org.junit.Assert.*;
import org.junit.Test;
import seng202.group9.Controller.SceneCode;
import seng202.group9.Controller.Session;
public class SessionTest {
@Test
public void testConstructor(){
Session session = new Session();
assertTrue(session.getSceneDisplayed() == SceneCode.INITIAL);
session.setSceneDisplayed(SceneCode.AIRLINE_RAW_DATA);
assertTrue(session.getSceneDisplayed() == SceneCode.AIRLINE_RAW_DATA);
Session session1 = new Session(SceneCode.ROUTE_RAW_DATA);
assertTrue(session1.getSceneDisplayed() == SceneCode.ROUTE_RAW_DATA);
}
}
Loading…
Cancel
Save