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),
|
* (por exemplo quando executado a partir do classpath/jar),
|
||||||
* faz fallback para carregar a partir do classpath usando o ClassLoader.
|
* 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 {
|
||||||
try (InputStream input = new FileInputStream(filePath)) {
|
try (InputStream input = new FileInputStream(filePath)) {
|
||||||
|
|||||||
@@ -264,32 +264,19 @@ public class SimulationEngine {
|
|||||||
*/
|
*/
|
||||||
private void processEvent(Event event) {
|
private void processEvent(Event event) {
|
||||||
switch (event.getType()) {
|
switch (event.getType()) {
|
||||||
case VEHICLE_GENERATION:
|
case VEHICLE_GENERATION -> handleVehicleGeneration();
|
||||||
handleVehicleGeneration();
|
|
||||||
break;
|
|
||||||
|
|
||||||
case VEHICLE_ARRIVAL:
|
case VEHICLE_ARRIVAL -> handleVehicleArrival(event);
|
||||||
handleVehicleArrival(event);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case TRAFFIC_LIGHT_CHANGE:
|
case TRAFFIC_LIGHT_CHANGE -> handleTrafficLightChange(event);
|
||||||
handleTrafficLightChange(event);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case CROSSING_START:
|
case CROSSING_START -> handleCrossingStart(event);
|
||||||
handleCrossingStart(event);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case CROSSING_END:
|
case CROSSING_END -> handleCrossingEnd(event);
|
||||||
handleCrossingEnd(event);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case STATISTICS_UPDATE:
|
case STATISTICS_UPDATE -> handleStatisticsUpdate();
|
||||||
handleStatisticsUpdate();
|
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
default -> System.err.println("Unknown event type: " + event.getType());
|
||||||
System.err.println("Unknown event type: " + event.getType());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -386,7 +373,7 @@ public class SimulationEngine {
|
|||||||
* @param vehicle The vehicle to process.
|
* @param vehicle The vehicle to process.
|
||||||
* @param intersection The intersection where the vehicle is.
|
* @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
|
// Find the direction (and light) this vehicle is queued at
|
||||||
// This logic is a bit flawed: it just finds the *first* non-empty queue
|
// 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
|
// 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.
|
* @return The crossing time in seconds.
|
||||||
*/
|
*/
|
||||||
private double getCrossingTime(VehicleType type) {
|
private double getCrossingTime(VehicleType type) {
|
||||||
switch (type) {
|
return switch (type) {
|
||||||
case BIKE:
|
case BIKE -> config.getBikeVehicleCrossingTime();
|
||||||
return config.getBikeVehicleCrossingTime();
|
case LIGHT -> config.getLightVehicleCrossingTime();
|
||||||
case LIGHT:
|
case HEAVY -> config.getHeavyVehicleCrossingTime();
|
||||||
return config.getLightVehicleCrossingTime();
|
default -> 2.0;
|
||||||
case HEAVY:
|
}; // Default fallback
|
||||||
return config.getHeavyVehicleCrossingTime();
|
|
||||||
default:
|
|
||||||
return 2.0; // Default fallback
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -43,7 +43,7 @@ class SimulationTest {
|
|||||||
assertEquals("TEST1", vehicle.getId());
|
assertEquals("TEST1", vehicle.getId());
|
||||||
assertNotNull(vehicle.getType());
|
assertNotNull(vehicle.getType());
|
||||||
assertNotNull(vehicle.getRoute());
|
assertNotNull(vehicle.getRoute());
|
||||||
assertTrue(vehicle.getRoute().size() > 0);
|
assertTrue(!vehicle.getRoute().isEmpty());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|||||||
Reference in New Issue
Block a user