mirror of
https://github.com/davidalves04/Trabalho-Pratico-SD.git
synced 2025-12-07 20:16:36 +00:00
Step 2 - Finishing touches
This commit is contained in:
@@ -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)) {
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user