]> Git Server - tankstelle.git/commitdiff
refactoring javafx-test
authorRobin Cheney <cheneyr@eternal.ddnss.de>
Wed, 3 Dec 2025 10:07:05 +0000 (11:07 +0100)
committerRobin Cheney <cheneyr@eternal.ddnss.de>
Wed, 3 Dec 2025 10:07:05 +0000 (11:07 +0100)
src/main/java/de/diejungsvondertanke/tankstelle/controllers/PriceTabController.java
src/main/java/de/diejungsvondertanke/tankstelle/controllers/ResultTabController.java
src/main/java/de/diejungsvondertanke/tankstelle/controllers/SearchTabController.java
src/main/java/de/diejungsvondertanke/tankstelle/controllers/StockTabController.java
src/main/java/de/diejungsvondertanke/tankstelle/core/FuelStation.java
src/main/java/de/diejungsvondertanke/tankstelle/core/Main.java
src/main/java/de/diejungsvondertanke/tankstelle/error/NoFuelTypeSelectedError.java [deleted file]
src/main/java/de/diejungsvondertanke/tankstelle/exception/FuelTypeException.java [moved from src/main/java/de/diejungsvondertanke/tankstelle/error/FuelTypeException.java with 89% similarity]
src/main/java/de/diejungsvondertanke/tankstelle/exception/NoFuelTypeSelectedException.java [new file with mode: 0644]
src/main/java/de/diejungsvondertanke/tankstelle/exception/NoSuchFuelTypeException.java [moved from src/main/java/de/diejungsvondertanke/tankstelle/error/NoSuchFuelTypeError.java with 58% similarity]

index 8405c73f65cc3e16155e8bf092cc2ccbfb7fa73a..a18f7a67d01f69c3608099fe69f88fa6a5d7a4cd 100644 (file)
@@ -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());
         }
     }
index 950242c05dc45a51876d104956440f7d950507e7..14dd54483cc2054a1b6a5addd9ebab7cfd6aea46 100644 (file)
@@ -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());
         }
     }
index 2a192b137a17a8021f32d013af10933411253870..be562a3c745d9737241582386d3344fc1d4cb8a6 100644 (file)
@@ -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) {
             }
         }
 
index eaddaa438a4fdcd6f33c4b3557a83bfaa07cce39..f5bb2754ca59196637617b3836e79e64e1d80101 100644 (file)
@@ -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");
     }
 
     /**
index 93ffab33d8b6d140e6593f06b66a907c95f420ab..3ff85f557bd63e93317da74d1d688bdbc8173330 100644 (file)
@@ -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");
     }
 
     /**
index d1a58e61e8ce43cb95b283948c10d062ad8367f4..c02ad3f9cdaa5e6f828cba0b0df751f29d0da2e5 100644 (file)
@@ -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 (file)
index 002befc..0000000
+++ /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");
-    }
-}
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 22b68857eea5f88979d99fa6675c94b33b9cb698..73da9d2f16417e6e9cd356682d327a08e1a676d8 100644 (file)
@@ -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 (file)
index 0000000..1e324c1
--- /dev/null
@@ -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");
+    }
+}
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 935272c435a025f698170fb650ae5c21ae87d589..477ae29b201b83ebf1041c9316e66eac9b49592f 100644 (file)
@@ -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");
     }
 }