# Conflicts:
#	res/userdb.db
This commit is contained in:
Liam Beckett
2016-09-16 16:38:31 +12:00
25 changed files with 1077 additions and 182 deletions
@@ -0,0 +1,131 @@
package seng202.group9.Controller;
import seng202.group9.Core.Airline;
import java.util.ArrayList;
/**
* Created by fwy13 on 16/09/16.
*/
public class AirlineFilter extends Filter{
private ArrayList<Airline> baseArray;
private ArrayList<Airline> filteredList;
public AirlineFilter(ArrayList<Airline> baseList){
filteredList = new ArrayList<Airline>();
baseArray = new ArrayList<Airline>();
for (Airline airline: baseList){
baseArray.add(airline);
filteredList.add(airline);
}
}
public void filterName(String name){
String regexCode = "(?i).*"+name+".*";
int index = 0;
while(index < filteredList.size()){
if (!filteredList.get(index).getName().matches(regexCode)){
filteredList.remove(index);
}else{
index++;
}
}
}
public void filterAlias(String alias){
String regexCode = "(?i).*"+alias+".*";
int index = 0;
while(index < filteredList.size()){
if (!filteredList.get(index).getAlias().matches(regexCode)){
filteredList.remove(index);
}else{
index++;
}
}
}
public void filterIATA(String IATA){
String regexCode = "(?i).*"+IATA+".*";
int index = 0;
while(index < filteredList.size()){
if (!filteredList.get(index).getIATA().matches(regexCode)){
filteredList.remove(index);
}else{
index++;
}
}
}
public void filterICAO(String ICAO){
String regexCode = "(?i).*"+ICAO+".*";
int index = 0;
while(index < filteredList.size()){
if (!filteredList.get(index).getICAO().matches(regexCode)){
filteredList.remove(index);
}else{
index++;
}
}
}
public void filterCallsign(String callsign){
String regexCode = "(?i).*"+callsign+".*";
int index = 0;
while(index < filteredList.size()){
if (!filteredList.get(index).getCallSign().matches(regexCode)){
filteredList.remove(index);
}else{
index++;
}
}
}
public void filterCountry(String country){
String regexCode = "(?i).*"+country+".*";
int index = 0;
while(index < filteredList.size()){
if (!filteredList.get(index).getCountryName().matches(regexCode)){
filteredList.remove(index);
}else{
index++;
}
}
}
public void filterActive(String active){
String regexCode = "(?i).*"+active+".*";
int index = 0;
while(index < filteredList.size()){
if (!filteredList.get(index).getActive().matches(regexCode)){
filteredList.remove(index);
}else{
index++;
}
}
}
public void reset() {
filteredList = new ArrayList<Airline>();
for (Airline airline: filteredList){
filteredList.add(airline);
}
}
public ArrayList getFilteredData() {
return filteredList;
}
public void setBaseList(ArrayList<Airline> arrayList) {
baseArray = new ArrayList<Airline>();
for (Airline airline: arrayList){
baseArray.add(airline);
}
}
public void printFilter(){
for (Airline airline: filteredList){
System.out.println(airline);
}
}
}
@@ -0,0 +1,180 @@
package seng202.group9.Controller;
import seng202.group9.Core.Airline;
import seng202.group9.Core.Airport;
import java.util.ArrayList;
/**
* Created by fwy13 on 16/09/16.
*/
public class AirportFilter extends Filter{
private ArrayList<Airport> baseArray;
private ArrayList<Airport> filteredList;
public AirportFilter(ArrayList<Airport> baseList){
filteredList = new ArrayList<Airport>();
baseArray = new ArrayList<Airport>();
for (Airport airport: baseList){
baseArray.add(airport);
filteredList.add(airport);
}
}
public void filterName(String name){
String regexCode = "(?i).*"+name+".*";
int index = 0;
while(index < filteredList.size()){
if (!filteredList.get(index).getName().matches(regexCode)){
filteredList.remove(index);
}else{
index++;
}
}
}
public void filterCity(String city){
String regexCode = "(?i).*"+city+".*";
int index = 0;
while(index < filteredList.size()){
if (!filteredList.get(index).getCityName().matches(regexCode)){
filteredList.remove(index);
}else{
index++;
}
}
}
public void filterCountry(String country){
String regexCode = "(?i).*"+country+".*";
int index = 0;
while(index < filteredList.size()){
if (!filteredList.get(index).getCountryName().matches(regexCode)){
filteredList.remove(index);
}else{
index++;
}
}
}
public void filterIATA_FFA(String IATA_FFA){
String regexCode = "(?i).*"+IATA_FFA+".*";
int index = 0;
while(index < filteredList.size()){
if (!filteredList.get(index).getIATA_FFA().matches(regexCode)){
filteredList.remove(index);
}else{
index++;
}
}
}
public void filterICAO(String ICAO){
String regexCode = "(?i).*"+ICAO+".*";
int index = 0;
while(index < filteredList.size()){
if (!filteredList.get(index).getICAO().matches(regexCode)){
filteredList.remove(index);
}else{
index++;
}
}
}
public void filterLatitude(String latitude){
String regexCode = "(?i).*"+latitude+".*";
int index = 0;
while(index < filteredList.size()){
if (!String.valueOf(filteredList.get(index).getLatitude()).matches(regexCode)){
filteredList.remove(index);
}else{
index++;
}
}
}
public void filterLongitude(String longitude){
String regexCode = "(?i).*"+longitude+".*";
int index = 0;
while(index < filteredList.size()){
if (!String.valueOf(filteredList.get(index).getLongitude()).matches(regexCode)){
filteredList.remove(index);
}else{
index++;
}
}
}
public void filterAltitude(String altitude){
String regexCode = "(?i).*"+altitude+".*";
int index = 0;
while(index < filteredList.size()){
if (!String.valueOf(filteredList.get(index).getAltitude()).matches(regexCode)){
filteredList.remove(index);
}else{
index++;
}
}
}
public void filterTimezone(String timezone){
String regexCode = "(?i).*"+timezone+".*";
int index = 0;
while(index < filteredList.size()){
if (!String.valueOf(filteredList.get(index).getCity(). getTimezone()).matches(regexCode)){
filteredList.remove(index);
}else{
index++;
}
}
}
public void filterOlson(String olson){
String regexCode = "(?i).*"+olson+".*";
int index = 0;
while(index < filteredList.size()){
if (!filteredList.get(index).getCity().getTimeOlson().matches(regexCode)){
filteredList.remove(index);
}else{
index++;
}
}
}
public void filterDST(String DST){
String regexCode = "(?i).*"+DST+".*";
int index = 0;
while(index < filteredList.size()){
if (!filteredList.get(index).getCountry().getDST().matches(regexCode)){
filteredList.remove(index);
}else{
index++;
}
}
}
public void reset() {
filteredList = new ArrayList<Airport>();
for (Airport airport: filteredList){
filteredList.add(airport);
}
}
public ArrayList getFilteredData() {
return filteredList;
}
public void setBaseList(ArrayList<Airport> arrayList) {
baseArray = new ArrayList<Airport>();
for (Airport airport: arrayList){
baseArray.add(airport);
}
}
public void printFilter(){
for (Airport airport: filteredList){
System.out.println(airport);
}
}
}
@@ -23,7 +23,7 @@ import seng202.group9.GUI.MenuController;
*/
public class App extends Application
{
private ArrayList<Dataset> Datasets = new ArrayList<Dataset>();
private ArrayList<Dataset> datasets = new ArrayList<Dataset>();
private Dataset currentDataset = null;
private Stage primaryStage = null;
private VBox mainContainer;
@@ -62,6 +62,10 @@ public class App extends Application
e.printStackTrace();
}
AirlineFilter filter = new AirlineFilter(currentDataset.getAirlines());
filter.filterName("NZ");
filter.filterAlias("flight");
filter.printFilter();
/*
//testout single route adding
try {
@@ -75,14 +79,12 @@ public class App extends Application
}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"));
@@ -136,4 +138,9 @@ public class App extends Application
public Dataset getCurrentDataset(){
return currentDataset;
}
public void deleteDataset(Dataset dataset){
dataset.deleteDataset();
datasets.remove(dataset);
}
}
@@ -96,7 +96,7 @@ public class Dataset {
String airCallsign = rs.getString("CallSign");
String airCountry = rs.getString("Country");
String airActive = rs.getString("Active");
Airline airlineToAdd = new Airline(airID, airName, airIATA, airICAO, airAlias, airCallsign, airCountry, airActive);
Airline airlineToAdd = new Airline(airID, airName, airAlias, airIATA, airICAO, airCallsign, airCountry, airActive);
//assuming that all names will be unique
airlineDictionary.put(airName, airlineToAdd);
airlines.add(airlineToAdd);
@@ -239,6 +239,7 @@ public class Dataset {
System.err.println( e.getClass().getName() + ": " + e.getMessage() );
System.exit(0);
}
createDataLinks();
}
/**
@@ -739,14 +740,18 @@ 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>();
//create Airline country link
for (Airline airline: airlines){
airlineByIATA.put(airline.getAlias(), airline);
//System.out.println(airline.getAlias());
airline.setCountry(countryDictionary.get(airline.getCountryName()));
}
//create Airport City and Country Link
HashMap<String, Airport> airportsByIATA = new HashMap<String, Airport>(); //this is used later for connecting the routes
HashMap<String, Airport> airportsByICAO = new HashMap<String, Airport>(); //this is used later for connecting the routes
for (Airport airport: airports){
//System.out.println(airport.getIATA_FFA());
airportsByIATA.put(airport.getIATA_FFA(), airport);
airportsByICAO.put(airport.getICAO(), airport);
airport.setCountry(countryDictionary.get(airport.getCountryName()));
@@ -766,7 +771,7 @@ public class Dataset {
}else{
route.setDestinationAirport(airportsByIATA.get(route.getArrivalAirport()));
}
route.setAirline(airlineDictionary.get(route.getAirlineName()));
route.setAirline(airlineByIATA.get(route.getAirlineName()));
}
System.out.println("Links Made");
}
@@ -1081,9 +1086,6 @@ public class Dataset {
stmt.close();
} catch ( Exception e ) {
System.err.println( e.getClass().getName() + ": " + e.getMessage() );
System.exit(0);
@@ -1095,6 +1097,242 @@ public class Dataset {
}
/**
* This is called in conjunction to the App deleteDataset DO NOT CALL UNLESS THROUGH APP.DELETEDATASET
*/
public void deleteDataset(){
//drop the tables
Connection c = null;
Statement stmt = null;
try {
Class.forName("org.sqlite.JDBC");
c = DriverManager.getConnection("jdbc:sqlite:res/userdb.db");
String[] tablesToDrop = {"_Airline", "_Airport", "_City", "_Country", "_Routes", "_Flight_Path", "_Flight_Points"};
for (int i = 0; i < tablesToDrop.length; i++){
stmt = c.createStatement();
String dropTableStatment = "DROP TABLE `"+this.name+tablesToDrop[i]+"`";
stmt.execute(dropTableStatment);
stmt.close();
}
stmt = c.createStatement();
String deleteDatasetEntry = "DELETE FROM `Datasets` WHERE `Dataset_Name` = \""+this.name+"\"";
stmt.execute(deleteDatasetEntry);
stmt.close();
c.close();
} catch ( Exception e ) {
System.err.println( e.getClass().getName() + ": " + e.getMessage() );
System.exit(0);
}
}
/**
* deletes an airline from the dataset.
* @param airline
*/
public void deleteAirline(Airline airline){
//drop the entries
Connection c = null;
Statement stmt = null;
try {
Class.forName("org.sqlite.JDBC");
c = DriverManager.getConnection("jdbc:sqlite:res/userdb.db");
String deleteQuery = "DELETE FROM `"+this.name+"_Airline` WHERE `Airline_ID` = " + airline.getID() + ";";
stmt = c.createStatement();
stmt.execute(deleteQuery);
stmt.close();
stmt = c.createStatement();
//check if number of countries that contain airlines > 0 else delete the country
String countCountry = "SELECT COUNT(*) FROM `"+this.name+"_Airline` JOIN `"+this.name+"_Country` ON" +
" `"+this.name+"_Country`.`Country_Name` = `"+this.name+"_Airline`.`Country`" +
" WHERE `"+this.name+"_Airline`.`Country` = \""+airline.getCountry().getName().replace("\"", "\"\"")+"\"";
ResultSet countCountryRes = stmt.executeQuery(countCountry);
int countryCount = 0;
while (countCountryRes.next()){
countryCount += countCountryRes.getInt("COUNT(*)");
}
countCountryRes.close();
stmt.close();
//check if number of counties that contain airports > 0 else delete the country
String countCountryA = "SELECT COUNT(*) FROM `"+this.name+"_Airport` JOIN `"+this.name+"_Country` ON" +
" `"+this.name+"_Country`.`Country_Name` = `"+this.name+"_Airport`.`Country`" +
" WHERE `"+this.name+"_Airport`.`Country` = \""+airline.getCountry().getName().replace("\"", "\"\"")+"\"";
countCountryRes = stmt.executeQuery(countCountryA);
while (countCountryRes.next()){
countryCount += countCountryRes.getInt("COUNT(*)");
}
countCountryRes.close();
stmt.close();
//delete country if there are no matches
if (countryCount == 0){
stmt = c.createStatement();
String deleteCountry = "DELETE FROM `"+this.name+"_Country` WHERE `Country_Name` = \""+airline.getCountry().getName()+"\"";
stmt.execute(deleteCountry);
stmt.close();
}
c.close();
} catch ( Exception e ) {
System.err.println( e.getClass().getName() + ": " + e.getMessage() );
System.exit(0);
}
airlines.remove(airline);
}
public void deleteAirline(int index){
deleteAirline(airlines.get(index));
}
/**
* deletes an airport from the dataset.
* @param airport
*/
public void deleteAirport(Airport airport){
//drop the entries
Connection c = null;
Statement stmt = null;
try {
Class.forName("org.sqlite.JDBC");
c = DriverManager.getConnection("jdbc:sqlite:res/userdb.db");
String deleteQuery = "DELETE FROM `"+this.name+"_Airport` WHERE `Airport_ID` = " + airport.getID() + ";";
stmt = c.createStatement();
stmt.execute(deleteQuery);
stmt.close();
//check if number of countries that contain airports and airlines > 0 else delete the country
String countCountry = "SELECT COUNT(*) FROM `"+this.name+"_Airport` JOIN `"+this.name+"_Country` ON" +
" `"+this.name+"_Country`.`Country_Name` = `"+this.name+"_Airport`.`Country`" +
" WHERE `"+this.name+"_Airport`.`Country` = \""+airport.getCountry().getName().replace("\"", "\"\"")+"\"";
ResultSet countCountryRes = stmt.executeQuery(countCountry);
int countryCount = 0;
while (countCountryRes.next()){
countryCount = countCountryRes.getInt("COUNT(*)");
}
countCountryRes.close();
stmt.close();
//check if number of countries that contain airlines > 0 else delete the country
String countCountryA = "SELECT COUNT(*) FROM `"+this.name+"_Airline` JOIN `"+this.name+"_Country` ON" +
" `"+this.name+"_Country`.`Country_Name` = `"+this.name+"_Airline`.`Country`" +
" WHERE `"+this.name+"_Airline`.`Country` = \""+airport.getCountry().getName().replace("\"", "\"\"")+"\"";
ResultSet countCountryResA = stmt.executeQuery(countCountry);
while (countCountryResA.next()){
countryCount += countCountryResA.getInt("COUNT(*)");
}
countCountryResA.close();
stmt.close();
//delete country if no matches
if (countryCount == 0){
stmt = c.createStatement();
String deleteCountry = "DELETE FROM `"+this.name+"_Country` WHERE `Country_Name` = \""+airport.getCountry().getName()+"\"";
stmt.execute(deleteCountry);
stmt.close();
}
//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" +
" `"+this.name+"_City`.`City_Name` = `"+this.name+"_Airport`.`City`" +
" WHERE `"+this.name+"_Airport`.`City` = \""+airport.getCityName().replace("\"", "\"\"")+"\"";
ResultSet countCityRes = stmt.executeQuery(countCity);
int cityCount = 0;
while (countCityRes.next()){
cityCount = countCityRes.getInt("COUNT(*)");
}
countCountryRes.close();
stmt.close();
//delete country if no matches
if (cityCount == 0){
stmt = c.createStatement();
String deleteCity = "DELETE FROM `"+this.name+"_City` WHERE `City_Name` = \""+airport.getCityName()+"\"";
stmt.execute(deleteCity);
stmt.close();
}
c.close();
} catch ( Exception e ) {
System.err.println( e.getClass().getName() + ": " + e.getMessage() );
System.exit(0);
}
airports.remove(airport);
}
public void deleteAirport(int index){
deleteAirport(airports.get(index));
}
/**
* deletes an route from the dataset.
* @param route
*/
public void deleteRoute(Route route){
//drop the entries
Connection c = null;
Statement stmt = null;
try {
Class.forName("org.sqlite.JDBC");
c = DriverManager.getConnection("jdbc:sqlite:res/userdb.db");
String deleteQuery = "DELETE FROM `"+this.name+"_Routes` WHERE `Route_ID` = " + route.getID() + ";";
stmt = c.createStatement();
stmt.execute(deleteQuery);
c.close();
} catch ( Exception e ) {
System.err.println( e.getClass().getName() + ": " + e.getMessage() );
System.exit(0);
}
routes.remove(route);
}
public void deleteRoute(int index){
deleteRoute(routes.get(index));
}
/**
* deletes an airline from the dataset.
* @param flightPath
*/
public void deleteFlightPath(FlightPath flightPath){
//delete all flight points with the id
while(flightPath.getFlightPoints().size() > 0){
deleteFlightPoint(flightPath.getFlightPoints().get(0), flightPath);
}
//drop the entries
Connection c = null;
Statement stmt = null;
try {
Class.forName("org.sqlite.JDBC");
c = DriverManager.getConnection("jdbc:sqlite:res/userdb.db");
String deleteQuery = "DELETE FROM `"+this.name+"_Flight_Path` WHERE `Path_ID` = " + flightPath.getID() + ";";
stmt = c.createStatement();
stmt.execute(deleteQuery);
c.close();
} catch ( Exception e ) {
System.err.println( e.getClass().getName() + ": " + e.getMessage() );
System.exit(0);
}
flightPaths.remove(flightPath);
}
public void deleteFlightPath(int index){
deleteFlightPath(flightPaths.get(index));
}
/**
* deletes an airline from the dataset.
* @param flightPoint
*/
public void deleteFlightPoint(FlightPoint flightPoint, FlightPath flightPath){
//drop the tables
Connection c = null;
Statement stmt = null;
try {
Class.forName("org.sqlite.JDBC");
c = DriverManager.getConnection("jdbc:sqlite:res/userdb.db");
String deleteQuery = "DELETE FROM `"+this.name+"_Flight_Points` WHERE `Point_ID` = " + flightPoint.getID() + ";";
stmt = c.createStatement();
stmt.execute(deleteQuery);
c.close();
} catch ( Exception e ) {
System.err.println( e.getClass().getName() + ": " + e.getMessage() );
System.exit(0);
}
flightPath.getFlightPoints().remove(flightPoint);
}
public void deleteFlightPoint(int pathIndex, int pointIndex){
deleteFlightPoint(flightPaths.get(pathIndex).getFlightPoints().get(pointIndex), flightPaths.get(pathIndex));
}
public ArrayList<Airline> getAirlines() {
return airlines;
@@ -0,0 +1,11 @@
package seng202.group9.Controller;
import java.util.ArrayList;
/**
* Created by fwy13 on 16/09/16.
*/
public abstract class Filter {
abstract void reset();
abstract ArrayList getFilteredData();
}
@@ -0,0 +1,119 @@
package seng202.group9.Controller;
import seng202.group9.Core.Route;
import java.util.ArrayList;
/**
* Created by fwy13 on 16/09/16.
*/
public class RouteFilter extends Filter{
private ArrayList<Route> baseArray;
private ArrayList<Route> filteredList;
public RouteFilter(ArrayList<Route> baseList){
filteredList = new ArrayList<Route>();
baseArray = new ArrayList<Route>();
for (Route route: baseList){
baseArray.add(route);
filteredList.add(route);
}
}
public void filterAirline(String airline){
String regexCode = "(?i).*"+airline+".*";
int index = 0;
while(index < filteredList.size()){
if (!filteredList.get(index).getAirlineName().matches(regexCode)){
filteredList.remove(index);
}else{
index++;
}
}
}
public void filterSourceAirport(String airport){
String regexCode = "(?i).*"+airport+".*";
int index = 0;
while(index < filteredList.size()){
if (!filteredList.get(index).getDepartureAirport().matches(regexCode)){
filteredList.remove(index);
}else{
index++;
}
}
}
public void filterDestinationAirport(String airport){
String regexCode = "(?i).*"+airport+".*";
int index = 0;
while(index < filteredList.size()){
if (!filteredList.get(index).getArrivalAirport().matches(regexCode)){
filteredList.remove(index);
}else{
index++;
}
}
}
public void filterCodeshare(String code){
String regexCode = "(?i).*"+code+".*";
int index = 0;
while(index < filteredList.size()){
if (!filteredList.get(index).getCode().matches(regexCode)){
filteredList.remove(index);
}else{
index++;
}
}
}
public void filterDestinationStops(String stops){
String regexCode = "(?i).*"+stops+".*";
int index = 0;
while(index < filteredList.size()){
if (!filteredList.get(index).getArrivalAirport().matches(regexCode)){
filteredList.remove(index);
}else{
index++;
}
}
}
public void filterEquipment(String equipment){
String regexCode = "(?i).*"+equipment+".*";
int index = 0;
while(index < filteredList.size()){
if (!filteredList.get(index).getEquipment().matches(regexCode)){
filteredList.remove(index);
}else{
index++;
}
}
}
public void reset() {
filteredList = new ArrayList<Route>();
for (Route airline: filteredList){
filteredList.add(airline);
}
}
public ArrayList getFilteredData() {
return filteredList;
}
public void setBaseList(ArrayList<Route> arrayList) {
baseArray = new ArrayList<Route>();
for (Route route: arrayList){
baseArray.add(route);
}
}
public void printFilter(){
for (Route route: filteredList){
System.out.println(route);
}
}
}