Added some index checks and relavent Tests for them

This commit is contained in:
YaFedImYaEatIm
2016-09-19 00:11:57 +12:00
parent a0959e8de6
commit b232dcd7e6
6 changed files with 114 additions and 19 deletions
@@ -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.");
}
}
/**
+13 -4
View File
@@ -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,12 @@ 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
@@ -378,8 +383,12 @@ public class Airport {
* deletes a member of departure routes by index
* @param index
*/
public void delDepartureRoutes(int index){
departureRoutes.remove(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.");
}
}
/**
+6 -2
View File
@@ -1,5 +1,7 @@
package seng202.group9.Core;
import seng202.group9.Controller.DataException;
import java.util.ArrayList;
public class City {
@@ -137,9 +139,11 @@ public class City {
* Deletes an Airport by Index from this City.
* @param index
*/
public void delAirport(int index) {
if (airports.size() > 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