]> Git Server - tankstelle.git/commitdiff
Added sorting mechanic in FuelStation
authorRobin Cheney <cheneyr@eternal.ddnss.de>
Sun, 16 Nov 2025 08:55:05 +0000 (09:55 +0100)
committerRobin Cheney <cheneyr@eternal.ddnss.de>
Sun, 16 Nov 2025 08:55:05 +0000 (09:55 +0100)
src/main/java/de/diejungsvondertanke/tankstelle/FuelStation.java

index 8de2dd6428cac2f14cdddd9ba7595201e198bac4..3702c6e799d84e7d18ae1f6e53624dd833e31790 100644 (file)
@@ -1,5 +1,7 @@
 package de.diejungsvondertanke.tankstelle;
 
+import java.util.ArrayList;
+
 import de.diejungsvondertanke.tankstelle.error.NoSuchFuelTypeError;
 
 /**
@@ -148,11 +150,37 @@ abstract class FuelStation {
     }
 
     /**
-     * Set a new number of employees for this fuel station
+     * Sort the fuel stations by size in a descending order (largest stations first)
      * 
-     * @param number_of_employees new number of employees for this fuel station
+     * @param stations Array of {@link FuelStation}s
+     * @return an ordered array of {@link FuelStation}s
      */
-    public void setNumber_of_employees(byte number_of_employees) {
-        this.number_of_employees = number_of_employees;
+    public static FuelStation[] sort(FuelStation[] stations) {
+        ArrayList<FuelStation> result = new ArrayList<>();
+        ArrayList<FuelStation> large = new ArrayList<>();
+        ArrayList<FuelStation> medium = new ArrayList<>();
+        ArrayList<FuelStation> small = new ArrayList<>();
+
+        for (FuelStation station : stations) {
+            switch (station.size) {
+                case SMALL:
+                    small.add(station);
+                    break;
+                case MEDIUM:
+                    medium.add(station);
+                    break;
+                case LARGE:
+                    large.add(station);
+                    break;
+                default:
+                    System.out.println("Unknown FuelStation size for object: " + station.toString());
+                    break;
+            }
+
+        }
+        result.addAll(large);
+        result.addAll(medium);
+        result.addAll(small);
+        return result.toArray(new FuelStation[0]);
     }
-}
+}
\ No newline at end of file