From: Robin Cheney Date: Wed, 3 Dec 2025 10:07:05 +0000 (+0100) Subject: refactoring X-Git-Url: https://git.eternal.ddnss.de/?a=commitdiff_plain;h=refs%2Fheads%2Fjavafx-test;p=tankstelle.git refactoring --- diff --git a/src/main/java/de/diejungsvondertanke/tankstelle/controllers/PriceTabController.java b/src/main/java/de/diejungsvondertanke/tankstelle/controllers/PriceTabController.java index 8405c73..a18f7a6 100644 --- a/src/main/java/de/diejungsvondertanke/tankstelle/controllers/PriceTabController.java +++ b/src/main/java/de/diejungsvondertanke/tankstelle/controllers/PriceTabController.java @@ -2,7 +2,7 @@ package de.diejungsvondertanke.tankstelle.controllers; import de.diejungsvondertanke.tankstelle.core.FuelStation; import de.diejungsvondertanke.tankstelle.core.FuelType; -import de.diejungsvondertanke.tankstelle.error.NoSuchFuelTypeError; +import de.diejungsvondertanke.tankstelle.exception.NoSuchFuelTypeException; import javafx.fxml.FXML; import javafx.scene.control.TextField; @@ -60,7 +60,7 @@ public class PriceTabController { } catch (NumberFormatException e) { parentController.showError("Invalid number."); - } catch (NoSuchFuelTypeError e) { + } catch (NoSuchFuelTypeException e) { parentController.showError(e.getMessage()); } } diff --git a/src/main/java/de/diejungsvondertanke/tankstelle/controllers/ResultTabController.java b/src/main/java/de/diejungsvondertanke/tankstelle/controllers/ResultTabController.java index 950242c..14dd544 100644 --- a/src/main/java/de/diejungsvondertanke/tankstelle/controllers/ResultTabController.java +++ b/src/main/java/de/diejungsvondertanke/tankstelle/controllers/ResultTabController.java @@ -3,9 +3,9 @@ package de.diejungsvondertanke.tankstelle.controllers; import de.diejungsvondertanke.tankstelle.core.FuelStation; import de.diejungsvondertanke.tankstelle.core.FuelType; import de.diejungsvondertanke.tankstelle.core.Main; -import de.diejungsvondertanke.tankstelle.error.FuelTypeException; -import de.diejungsvondertanke.tankstelle.error.NoFuelTypeSelectedError; -import de.diejungsvondertanke.tankstelle.error.NoSuchFuelTypeError; +import de.diejungsvondertanke.tankstelle.exception.FuelTypeException; +import de.diejungsvondertanke.tankstelle.exception.NoFuelTypeSelectedException; +import de.diejungsvondertanke.tankstelle.exception.NoSuchFuelTypeException; import javafx.fxml.FXML; import javafx.scene.control.ListView; import javafx.scene.control.SelectionMode; @@ -84,7 +84,7 @@ public class ResultTabController { try { FuelStation fs = Main.getHighestAccumulatedValue(); parentController.appendOutput("Highest total value: " + parentController.getDisplayName(fs)); - } catch (NoSuchFuelTypeError e) { + } catch (NoSuchFuelTypeException e) { parentController.showError(e.getMessage()); } } @@ -127,7 +127,7 @@ public class ResultTabController { try { total = Main.getTotalStockLevelOfFuel(type, stations); parentController.appendOutput("Total for %s: %.2f L".formatted(type, total)); - } catch (NoFuelTypeSelectedError e) { + } catch (NoFuelTypeSelectedException e) { parentController.showError(e.getMessage()); } } diff --git a/src/main/java/de/diejungsvondertanke/tankstelle/controllers/SearchTabController.java b/src/main/java/de/diejungsvondertanke/tankstelle/controllers/SearchTabController.java index 2a192b1..be562a3 100644 --- a/src/main/java/de/diejungsvondertanke/tankstelle/controllers/SearchTabController.java +++ b/src/main/java/de/diejungsvondertanke/tankstelle/controllers/SearchTabController.java @@ -3,7 +3,7 @@ package de.diejungsvondertanke.tankstelle.controllers; import de.diejungsvondertanke.tankstelle.core.FuelStation; import de.diejungsvondertanke.tankstelle.core.FuelType; import de.diejungsvondertanke.tankstelle.core.Main; -import de.diejungsvondertanke.tankstelle.error.NoSuchFuelTypeError; +import de.diejungsvondertanke.tankstelle.exception.NoSuchFuelTypeException; import javafx.fxml.FXML; /** @@ -43,7 +43,7 @@ public class SearchTabController { try { station.getStored_amount(type); sb.append(" - ").append(parentController.getDisplayName(station)).append("\n"); - } catch (NoSuchFuelTypeError ignore) { + } catch (NoSuchFuelTypeException ignore) { } } diff --git a/src/main/java/de/diejungsvondertanke/tankstelle/controllers/StockTabController.java b/src/main/java/de/diejungsvondertanke/tankstelle/controllers/StockTabController.java index eaddaa4..f5bb275 100644 --- a/src/main/java/de/diejungsvondertanke/tankstelle/controllers/StockTabController.java +++ b/src/main/java/de/diejungsvondertanke/tankstelle/controllers/StockTabController.java @@ -3,7 +3,7 @@ package de.diejungsvondertanke.tankstelle.controllers; import de.diejungsvondertanke.tankstelle.core.Fuel; import de.diejungsvondertanke.tankstelle.core.FuelStation; import de.diejungsvondertanke.tankstelle.core.FuelType; -import de.diejungsvondertanke.tankstelle.error.NoSuchFuelTypeError; +import de.diejungsvondertanke.tankstelle.exception.NoSuchFuelTypeException; import javafx.fxml.FXML; import javafx.scene.control.RadioButton; import javafx.scene.control.TextField; @@ -42,12 +42,12 @@ public class StockTabController { this.parentController = parent; } - private int getCapacity(FuelStation station, FuelType type) throws NoSuchFuelTypeError { + private int getCapacity(FuelStation station, FuelType type) throws NoSuchFuelTypeException { for (Fuel f : station.fuels) { if (f.FUEL_TYPE == type) return f.CAPACITY; } - throw new NoSuchFuelTypeError("This fuel station does not have this type of fuel"); + throw new NoSuchFuelTypeException("This fuel station does not have this type of fuel"); } /** diff --git a/src/main/java/de/diejungsvondertanke/tankstelle/core/FuelStation.java b/src/main/java/de/diejungsvondertanke/tankstelle/core/FuelStation.java index 93ffab3..3ff85f5 100644 --- a/src/main/java/de/diejungsvondertanke/tankstelle/core/FuelStation.java +++ b/src/main/java/de/diejungsvondertanke/tankstelle/core/FuelStation.java @@ -2,7 +2,7 @@ package de.diejungsvondertanke.tankstelle.core; import java.util.ArrayList; -import de.diejungsvondertanke.tankstelle.error.NoSuchFuelTypeError; +import de.diejungsvondertanke.tankstelle.exception.NoSuchFuelTypeException; /** * Abstract class. @@ -61,19 +61,20 @@ public abstract class FuelStation { * * @param type The {@link FuelType FuelType} to change * @param new_amount The new fuel amount - * @throws NoSuchFuelTypeError This Error is thrown on the attempt to choose a - * fuel type from a fuel station - * which the fuel station does not have + * @throws NoSuchFuelTypeException This Error is thrown on the attempt to choose + * a + * fuel type from a fuel station + * which the fuel station does not have * * @author Nils Göbbert */ - public void set_stored_amount(double new_amount, FuelType type) throws NoSuchFuelTypeError { + public void set_stored_amount(double new_amount, FuelType type) throws NoSuchFuelTypeException { for (Fuel i : fuels) { if (i.FUEL_TYPE == type) { i.setStored_amount(new_amount); return; } - throw new NoSuchFuelTypeError("This fuel station does not have fuel of the given type"); + throw new NoSuchFuelTypeException("This fuel station does not have fuel of the given type"); } } @@ -83,13 +84,15 @@ public abstract class FuelStation { * * @param type The {@link FuelType FuelType} to change * @param new_amount The amount of fuel that is added or subtracted - * @throws NoSuchFuelTypeError This Error is thrown on the attempt to choose a - * fuel type from a fuel station - * which the fuel station does not have + * @throws NoSuchFuelTypeException This Error is thrown on the attempt to choose + * a + * fuel type from a fuel station + * which the fuel station does not have * * @author Nils Göbbert */ - public void add_stored_amount(double new_amount, FuelType type) throws NoSuchFuelTypeError, ArithmeticException { + public void add_stored_amount(double new_amount, FuelType type) + throws NoSuchFuelTypeException, ArithmeticException { for (Fuel i : fuels) { if (i.FUEL_TYPE == type) { if (new_amount + i.getStored_amount() < 0) { @@ -99,7 +102,7 @@ public abstract class FuelStation { return; } } - throw new NoSuchFuelTypeError("This fuel station does not have fuel of the given type"); + throw new NoSuchFuelTypeException("This fuel station does not have fuel of the given type"); } /** @@ -107,20 +110,21 @@ public abstract class FuelStation { * * @param fuel_type The {@link FuelType FuelTypes} to change * @param price The new price per litre - * @throws NoSuchFuelTypeError This Error is thrown on the attempt to choose a - * fuel type from a fuel station - * which the fuel station does not have + * @throws NoSuchFuelTypeException This Error is thrown on the attempt to choose + * a + * fuel type from a fuel station + * which the fuel station does not have * * @author Robin Cheney */ - public void set_price(FuelType fuel_type, float price) throws NoSuchFuelTypeError { + public void set_price(FuelType fuel_type, float price) throws NoSuchFuelTypeException { for (Fuel i : fuels) { if (i.FUEL_TYPE == fuel_type) { i.setPrice(price); return; } } - throw new NoSuchFuelTypeError("This fuel station does not have fuel of the given type"); + throw new NoSuchFuelTypeException("This fuel station does not have fuel of the given type"); } /** @@ -128,19 +132,20 @@ public abstract class FuelStation { * * @param fuel_type The {@link FuelType FuelType} to get * @return The price for a specific type of fuel for this fuel station - * @throws NoSuchFuelTypeError This Error is thrown on the attempt to choose a - * fuel type from a fuel station - * which the fuel station does not have + * @throws NoSuchFuelTypeException This Error is thrown on the attempt to choose + * a + * fuel type from a fuel station + * which the fuel station does not have * * @author Robin Cheney */ - public float get_price(FuelType fuel_type) throws NoSuchFuelTypeError { + public float get_price(FuelType fuel_type) throws NoSuchFuelTypeException { for (Fuel i : fuels) { if (i.FUEL_TYPE == fuel_type) { return i.getPrice(); } } - throw new NoSuchFuelTypeError("This fuel station does not have fuel of the given type"); + throw new NoSuchFuelTypeException("This fuel station does not have fuel of the given type"); } /** @@ -252,19 +257,20 @@ public abstract class FuelStation { * * @param fuel_type The {@link FuelType FuelType} to get * @return The fuel amount for a specific type of fuel for this fuel station - * @throws NoSuchFuelTypeError This Error is thrown on the attempt to choose a - * fuel type from a fuel station - * which the fuel station does not have + * @throws NoSuchFuelTypeException This Error is thrown on the attempt to choose + * a + * fuel type from a fuel station + * which the fuel station does not have * * @author Nils Göbbert */ - public double getStored_amount(FuelType fuel_type) throws NoSuchFuelTypeError { + public double getStored_amount(FuelType fuel_type) throws NoSuchFuelTypeException { for (Fuel i : fuels) { if (i.FUEL_TYPE == fuel_type) { return i.getStored_amount(); } } - throw new NoSuchFuelTypeError("This fuel station does not have fuel of the given type"); + throw new NoSuchFuelTypeException("This fuel station does not have fuel of the given type"); } /** diff --git a/src/main/java/de/diejungsvondertanke/tankstelle/core/Main.java b/src/main/java/de/diejungsvondertanke/tankstelle/core/Main.java index d1a58e6..c02ad3f 100644 --- a/src/main/java/de/diejungsvondertanke/tankstelle/core/Main.java +++ b/src/main/java/de/diejungsvondertanke/tankstelle/core/Main.java @@ -6,8 +6,8 @@ import java.io.InputStreamReader; import java.util.ArrayList; import java.util.Arrays; -import de.diejungsvondertanke.tankstelle.error.NoFuelTypeSelectedError; -import de.diejungsvondertanke.tankstelle.error.NoSuchFuelTypeError; +import de.diejungsvondertanke.tankstelle.exception.NoFuelTypeSelectedException; +import de.diejungsvondertanke.tankstelle.exception.NoSuchFuelTypeException; /** * Main Class @@ -100,18 +100,20 @@ public class Main { * @param fuelType Select the type of fuel * * @return a FuelStation (all of type {@link FuelStation}) - * @throws NoSuchFuelTypeError This Error is thrown on the attempt to choose a - * fuel type from a fuel station which the fuel - * station does not have + * @throws NoSuchFuelTypeException This Error is thrown on the attempt to choose + * a + * fuel type from a fuel station which the fuel + * station does not have * * @author Nils Göbbert */ - public static FuelStation getHighestPrice(FuelType fuelType) throws NoSuchFuelTypeError, NoFuelTypeSelectedError { + public static FuelStation getHighestPrice(FuelType fuelType) + throws NoSuchFuelTypeException, NoFuelTypeSelectedException { FuelStation highestStation = null; float highestPrice = Float.NEGATIVE_INFINITY; if (fuelType == null) - throw new NoFuelTypeSelectedError(); + throw new NoFuelTypeSelectedException(); for (FuelStation fuelStation : fuelStations) { try { @@ -120,12 +122,12 @@ public class Main { highestPrice = price; highestStation = fuelStation; } - } catch (NoSuchFuelTypeError e) { + } catch (NoSuchFuelTypeException e) { } } if (highestStation == null) { - throw new NoSuchFuelTypeError("No fuel station with " + fuelType + " found"); + throw new NoSuchFuelTypeException("No fuel station with " + fuelType + " found"); } return highestStation; } @@ -135,13 +137,14 @@ public class Main { * * * @return a FuelStation (all of type {@link FuelStation}) - * @throws NoSuchFuelTypeError This Error is thrown on the attempt to choose a - * fuel type from a fuel station which the fuel - * station does not have + * @throws NoSuchFuelTypeException This Error is thrown on the attempt to choose + * a + * fuel type from a fuel station which the fuel + * station does not have * * @author Nils Göbbert */ - public static FuelStation getHighestAccumulatedValue() throws NoSuchFuelTypeError { + public static FuelStation getHighestAccumulatedValue() throws NoSuchFuelTypeException { float highestValue = fuelStations.get(0).get_cumulative_retail_price(); FuelStation highestStation = fuelStations.get(0); for (FuelStation fuelStation : fuelStations) { @@ -160,18 +163,19 @@ public class Main { * @param fuelType Select the type of fuel * * @return a FuelStation (all of type {@link FuelStation}) - * @throws NoSuchFuelTypeError This Error is thrown on the attempt to choose a - * fuel type from a fuel station which the fuel - * station does not have + * @throws NoSuchFuelTypeException This Error is thrown on the attempt to choose + * a + * fuel type from a fuel station which the fuel + * station does not have * * @author Nils Göbbert */ public static FuelStation getHighestStoredAmount(FuelType fuelType) - throws NoSuchFuelTypeError, NoFuelTypeSelectedError { + throws NoSuchFuelTypeException, NoFuelTypeSelectedException { FuelStation highestStation = null; double highestAmount = Double.NEGATIVE_INFINITY; if (fuelType == null) - throw new NoFuelTypeSelectedError(); + throw new NoFuelTypeSelectedException(); for (FuelStation fuelStation : fuelStations) { try { double amount = fuelStation.getStored_amount(fuelType); @@ -179,13 +183,13 @@ public class Main { highestAmount = amount; highestStation = fuelStation; } - } catch (NoSuchFuelTypeError e) { + } catch (NoSuchFuelTypeException e) { } } if (highestStation == null) { - throw new NoSuchFuelTypeError("No fuel station with " + fuelType + " found"); + throw new NoSuchFuelTypeException("No fuel station with " + fuelType + " found"); } return highestStation; } @@ -197,18 +201,19 @@ public class Main { * @param fuelType Select the type of fuel * * @return a FuelStation (all of type {@link FuelStation}) - * @throws NoSuchFuelTypeError This Error is thrown on the attempt to choose a - * fuel type from a fuel station which the fuel - * station does not have + * @throws NoSuchFuelTypeException This Error is thrown on the attempt to choose + * a + * fuel type from a fuel station which the fuel + * station does not have * * @author Nils Göbbert */ public static FuelStation getLowestStoredAmount(FuelType fuelType) - throws NoSuchFuelTypeError, NoFuelTypeSelectedError { + throws NoSuchFuelTypeException, NoFuelTypeSelectedException { FuelStation lowestStation = null; double lowestAmount = Double.POSITIVE_INFINITY; if (fuelType == null) - throw new NoFuelTypeSelectedError(); + throw new NoFuelTypeSelectedException(); for (FuelStation fuelStation : fuelStations) { try { @@ -217,13 +222,13 @@ public class Main { lowestAmount = amount; lowestStation = fuelStation; } - } catch (NoSuchFuelTypeError e) { + } catch (NoSuchFuelTypeException e) { } } if (lowestStation == null) { - throw new NoSuchFuelTypeError("No fuel station with " + fuelType + " found"); + throw new NoSuchFuelTypeException("No fuel station with " + fuelType + " found"); } return lowestStation; } @@ -341,10 +346,10 @@ public class Main { * @author Leander Schnurrer */ public static float getTotalStockLevelOfFuel(FuelType fuelType, FuelStation[] fuelStations) - throws NoFuelTypeSelectedError { + throws NoFuelTypeSelectedException { float sum = 0f; if (fuelType == null) - throw new NoFuelTypeSelectedError(); + throw new NoFuelTypeSelectedException(); for (FuelStation fuelStation : fuelStations) { for (Fuel fuel : fuelStation.fuels) { if (fuel.FUEL_TYPE == fuelType) { diff --git a/src/main/java/de/diejungsvondertanke/tankstelle/error/NoFuelTypeSelectedError.java b/src/main/java/de/diejungsvondertanke/tankstelle/error/NoFuelTypeSelectedError.java deleted file mode 100644 index 002befc..0000000 --- a/src/main/java/de/diejungsvondertanke/tankstelle/error/NoFuelTypeSelectedError.java +++ /dev/null @@ -1,29 +0,0 @@ -package de.diejungsvondertanke.tankstelle.error; - -/** - * This Error is thrown on the attempt to get the selected fuel type whenever - * there is none selected - * - * @author Robin Cheney - */ -public class NoFuelTypeSelectedError extends FuelTypeException { - /** - * Throws a {@link NoFuelTypeSelectedError} - * - * @param message Message to throw with this error - * - * @author Robin Cheney - */ - public NoFuelTypeSelectedError(String message) { - super(message); - } - - /** - * Throws a {@link NoFuelTypeSelectedError} - * - * @author Robin Cheney - */ - public NoFuelTypeSelectedError() { - super("No fuel type selected"); - } -} diff --git a/src/main/java/de/diejungsvondertanke/tankstelle/error/FuelTypeException.java b/src/main/java/de/diejungsvondertanke/tankstelle/exception/FuelTypeException.java similarity index 89% rename from src/main/java/de/diejungsvondertanke/tankstelle/error/FuelTypeException.java rename to src/main/java/de/diejungsvondertanke/tankstelle/exception/FuelTypeException.java index 22b6885..73da9d2 100644 --- a/src/main/java/de/diejungsvondertanke/tankstelle/error/FuelTypeException.java +++ b/src/main/java/de/diejungsvondertanke/tankstelle/exception/FuelTypeException.java @@ -1,4 +1,4 @@ -package de.diejungsvondertanke.tankstelle.error; +package de.diejungsvondertanke.tankstelle.exception; import de.diejungsvondertanke.tankstelle.core.FuelType; diff --git a/src/main/java/de/diejungsvondertanke/tankstelle/exception/NoFuelTypeSelectedException.java b/src/main/java/de/diejungsvondertanke/tankstelle/exception/NoFuelTypeSelectedException.java new file mode 100644 index 0000000..1e324c1 --- /dev/null +++ b/src/main/java/de/diejungsvondertanke/tankstelle/exception/NoFuelTypeSelectedException.java @@ -0,0 +1,30 @@ +package de.diejungsvondertanke.tankstelle.exception; + +/** + * This Exception is thrown on the attempt to get the selected fuel type + * whenever + * there is none selected + * + * @author Robin Cheney + */ +public class NoFuelTypeSelectedException extends FuelTypeException { + /** + * Throws a {@link NoFuelTypeSelectedException} + * + * @param message Message to throw with this Exception + * + * @author Robin Cheney + */ + public NoFuelTypeSelectedException(String message) { + super(message); + } + + /** + * Throws a {@link NoFuelTypeSelectedException} + * + * @author Robin Cheney + */ + public NoFuelTypeSelectedException() { + super("No fuel type selected"); + } +} diff --git a/src/main/java/de/diejungsvondertanke/tankstelle/error/NoSuchFuelTypeError.java b/src/main/java/de/diejungsvondertanke/tankstelle/exception/NoSuchFuelTypeException.java similarity index 58% rename from src/main/java/de/diejungsvondertanke/tankstelle/error/NoSuchFuelTypeError.java rename to src/main/java/de/diejungsvondertanke/tankstelle/exception/NoSuchFuelTypeException.java index 935272c..477ae29 100644 --- a/src/main/java/de/diejungsvondertanke/tankstelle/error/NoSuchFuelTypeError.java +++ b/src/main/java/de/diejungsvondertanke/tankstelle/exception/NoSuchFuelTypeException.java @@ -1,4 +1,4 @@ -package de.diejungsvondertanke.tankstelle.error; +package de.diejungsvondertanke.tankstelle.exception; /** * This Error is thrown on the attempt to choose a fuel type from a fuel station @@ -6,24 +6,24 @@ package de.diejungsvondertanke.tankstelle.error; * * @author Robin Cheney */ -public class NoSuchFuelTypeError extends FuelTypeException { +public class NoSuchFuelTypeException extends FuelTypeException { /** - * Throws a {@link NoSuchFuelTypeError} + * Throws a {@link NoSuchFuelTypeException} * * @param message Message to throw with this error * * @author Robin Cheney */ - public NoSuchFuelTypeError(String message) { + public NoSuchFuelTypeException(String message) { super(message); } /** - * Throws a {@link NoSuchFuelTypeError} + * Throws a {@link NoSuchFuelTypeException} * * @author Robin Cheney */ - public NoSuchFuelTypeError() { + public NoSuchFuelTypeException() { super("This fuel station does not have this type of fuel"); } }