Step 2 - Finishing touches

This commit is contained in:
2025-10-22 23:36:41 +01:00
parent fc46b9b83b
commit 211ea25ca5
3 changed files with 16 additions and 33 deletions

View File

@@ -31,7 +31,7 @@ public class SimulationConfig {
* (por exemplo quando executado a partir do classpath/jar),
* faz fallback para carregar a partir do classpath usando o ClassLoader.
*/
IOException lastException = null;
IOException lastException = null; //FIXME: melhorar esta parte para reportar erros de forma mais clara
try {
try (InputStream input = new FileInputStream(filePath)) {

View File

@@ -264,32 +264,19 @@ public class SimulationEngine {
*/
private void processEvent(Event event) {
switch (event.getType()) {
case VEHICLE_GENERATION:
handleVehicleGeneration();
break;
case VEHICLE_GENERATION -> handleVehicleGeneration();
case VEHICLE_ARRIVAL:
handleVehicleArrival(event);
break;
case VEHICLE_ARRIVAL -> handleVehicleArrival(event);
case TRAFFIC_LIGHT_CHANGE:
handleTrafficLightChange(event);
break;
case TRAFFIC_LIGHT_CHANGE -> handleTrafficLightChange(event);
case CROSSING_START:
handleCrossingStart(event);
break;
case CROSSING_START -> handleCrossingStart(event);
case CROSSING_END:
handleCrossingEnd(event);
break;
case CROSSING_END -> handleCrossingEnd(event);
case STATISTICS_UPDATE:
handleStatisticsUpdate();
break;
case STATISTICS_UPDATE -> handleStatisticsUpdate();
default:
System.err.println("Unknown event type: " + event.getType());
default -> System.err.println("Unknown event type: " + event.getType());
}
}
@@ -386,7 +373,7 @@ public class SimulationEngine {
* @param vehicle The vehicle to process.
* @param intersection The intersection where the vehicle is.
*/
private void tryProcessVehicle(Vehicle vehicle, Intersection intersection) {
private void tryProcessVehicle(Vehicle vehicle, Intersection intersection) { //FIXME
// Find the direction (and light) this vehicle is queued at
// This logic is a bit flawed: it just finds the *first* non-empty queue
// A better approach would be to get the light from the vehicle's route
@@ -591,16 +578,12 @@ public class SimulationEngine {
* @return The crossing time in seconds.
*/
private double getCrossingTime(VehicleType type) {
switch (type) {
case BIKE:
return config.getBikeVehicleCrossingTime();
case LIGHT:
return config.getLightVehicleCrossingTime();
case HEAVY:
return config.getHeavyVehicleCrossingTime();
default:
return 2.0; // Default fallback
}
return switch (type) {
case BIKE -> config.getBikeVehicleCrossingTime();
case LIGHT -> config.getLightVehicleCrossingTime();
case HEAVY -> config.getHeavyVehicleCrossingTime();
default -> 2.0;
}; // Default fallback
}
/**

View File

@@ -43,7 +43,7 @@ class SimulationTest {
assertEquals("TEST1", vehicle.getId());
assertNotNull(vehicle.getType());
assertNotNull(vehicle.getRoute());
assertTrue(vehicle.getRoute().size() > 0);
assertTrue(!vehicle.getRoute().isEmpty());
}
@Test