]> Git Server - tankstelle.git/commitdiff
added method to grab all fuel stations that serve a specific type of fuel
authorRobin Cheney <cheneyr@eternal.ddnss.de>
Wed, 19 Nov 2025 09:29:26 +0000 (10:29 +0100)
committerRobin Cheney <cheneyr@eternal.ddnss.de>
Wed, 19 Nov 2025 09:29:26 +0000 (10:29 +0100)
src/main/java/de/diejungsvondertanke/tankstelle/Main.java

index 944e219a122a8d6883b9da074e6da9bcfc27d31a..1924ebfc68f2f225634e8260f74e36e32a95fd95 100644 (file)
@@ -14,6 +14,7 @@ import de.diejungsvondertanke.tankstelle.error.NoSuchFuelTypeError;
  * @author Robin Cheney
  * @author Nils Göbbert
  * @author Leander Schnurrer
+ * @author Jef Bettenworth
  */
 public class Main {
     /**
@@ -323,4 +324,32 @@ public class Main {
         return sum;
     }
 
+    /**
+     * Returns all fuel stations that offer a specific type of fuel. The method
+     * iterates over all existing fuel stations and checks whethertheir internal
+     * fuel array (fuels[]) contains a Fuel object whose{@code FUEL_TYPE} matches
+     * the given {@code wantedType}. Every matching fuel station is added to the
+     * result and returned as an ArrayList.
+     * 
+     * @param wantedType The fuel type to filter for.
+     * 
+     * @return An ArrayList of all fuel stations that offer the specified fuel type.
+     * 
+     * @author Jef Bettenworth
+     */
+    public static ArrayList<FuelStation> getFuelStationsByFuelType(FuelType wantedType) {
+        ArrayList<FuelStation> result = new ArrayList<>();
+
+        for (FuelStation station : fuelStations) {
+            for (Fuel fuel : station.fuels) {
+                if (fuel.FUEL_TYPE == wantedType) {
+                    result.add(station);
+                    break; // keine Duplikate
+                }
+            }
+        }
+
+        return result;
+    }
+
 }
\ No newline at end of file