/**
* Sort the fuel stations by size in a descending order (largest stations first)
*
- * @param stations Array of {@link FuelStation}s
+ * @param stations ArrayList of {@link FuelStation}s
* @return an ordered array of {@link FuelStation}s
*
* @author Robin Cheney
*/
- public static FuelStation[] sortDescending(FuelStation[] stations) {
+ public static ArrayList<FuelStation> sortDescending(ArrayList<FuelStation> stations) {
ArrayList<FuelStation> result = new ArrayList<>();
ArrayList<FuelStation> large = new ArrayList<>();
ArrayList<FuelStation> medium = new ArrayList<>();
result.addAll(large);
result.addAll(medium);
result.addAll(small);
- return result.toArray(new FuelStation[0]);
+ return result;
+ // return result.toArray(new FuelStation[0]);
}
/**
* Sort the fuel stations by size in a ascending order (smallest stations first)
*
- * @param stations Array of {@link FuelStation}s
+ * @param stations ArrayList of {@link FuelStation}s
* @return an ordered array of {@link FuelStation}s
*
* @author Robin Cheney
*/
- public static FuelStation[] sortAscending(FuelStation[] stations) {
+ public static ArrayList<FuelStation> sortAscending(ArrayList<FuelStation> stations) {
ArrayList<FuelStation> result = new ArrayList<>();
ArrayList<FuelStation> large = new ArrayList<>();
ArrayList<FuelStation> medium = new ArrayList<>();
result.addAll(large);
result.addAll(medium);
result.addAll(small);
- return result.toArray(new FuelStation[0]);
+ return result;
}
/**
*
* @author Robin Cheney
*/
- public static FuelStation[] getFuelStations(short number_of_vending_machines) {
+ public static ArrayList<FuelStation> getFuelStations(short number_of_vending_machines) {
ArrayList<FuelStation> result = new ArrayList<FuelStation>();
for (FuelStation fuelStation : fuelStations) {
if (fuelStation instanceof SmallFuelStation
&& ((SmallFuelStation) fuelStation).getNumber_of_vending_machines() == number_of_vending_machines)
result.add(fuelStation);
}
- return result.toArray(new FuelStation[0]); // Change to SmallFuelStation if required
+ return result; // Change to SmallFuelStation if required
}
/**
*
* @author Robin Cheney
*/
- public static FuelStation[] getFuelStations(float retail_space) {
+ public static ArrayList<FuelStation> getFuelStations(float retail_space) {
ArrayList<FuelStation> result = new ArrayList<FuelStation>();
for (FuelStation fuelStation : fuelStations) {
if (fuelStation instanceof MediumFuelStation
&& ((MediumFuelStation) fuelStation).getRetail_space() == retail_space)
result.add(fuelStation);
}
- return result.toArray(new FuelStation[0]); // Change to MediumFuelStation if required
+ return result; // Change to MediumFuelStation if required
}
/**
*
* @author Robin Cheney
*/
- public static FuelStation[] getFuelStations(String supermarket_company) {
+ public static ArrayList<FuelStation> getFuelStations(String supermarket_company) {
ArrayList<FuelStation> result = new ArrayList<FuelStation>();
for (FuelStation fuelStation : fuelStations) {
if (fuelStation instanceof LargeFuelStation
&& ((LargeFuelStation) fuelStation).getSupermarket_company().equals(supermarket_company))
result.add(fuelStation);
}
- return result.toArray(new FuelStation[0]); // Change to LargeFuelStation if required
+ return result; // Change to LargeFuelStation if required
}
/**
*
* @author Robin Cheney
*/
- public static FuelStation[] getFuelStationListWhenUnderstaffed(short available_employees) {
+ public static ArrayList<FuelStation> getFuelStationListWhenUnderstaffed(short available_employees) {
ArrayList<FuelStation> result = new ArrayList<>();
- FuelStation[] fuelStationsLocalCopy = FuelStation.sortDescending(fuelStations.toArray(new FuelStation[0]));
+ ArrayList<FuelStation> fuelStationsLocalCopy = FuelStation.sortDescending(fuelStations);
for (FuelStation station : fuelStationsLocalCopy) {
if (Math.floorDiv(available_employees, station.getNumber_of_employees()) >= 1) {
available_employees -= station.getNumber_of_employees();
result.add(station);
}
}
- return result.toArray(new FuelStation[0]);
+ return result;
}
/**
*
* @author Leander Schnurrer
*/
- public static float getTotalStockLevelOfFuel(FuelType fuelType, FuelStation[] fuelStations) {
+ public static float getTotalStockLevelOfFuel(FuelType fuelType, ArrayList<FuelStation> fuelStations) {
float sum = 0f;
for (FuelStation fuelStation : fuelStations) {
for (Fuel fuel : fuelStation.fuels) {