diff --git a/fed/mosaic-application/src/main/java/org/eclipse/mosaic/fed/application/ambassador/simulation/TrafficManagementCenterUnit.java b/fed/mosaic-application/src/main/java/org/eclipse/mosaic/fed/application/ambassador/simulation/TrafficManagementCenterUnit.java index f11738fb..371ac939 100644 --- a/fed/mosaic-application/src/main/java/org/eclipse/mosaic/fed/application/ambassador/simulation/TrafficManagementCenterUnit.java +++ b/fed/mosaic-application/src/main/java/org/eclipse/mosaic/fed/application/ambassador/simulation/TrafficManagementCenterUnit.java @@ -178,17 +178,32 @@ private boolean handleEventResource(Object resource) { return false; } - private static class ChangeLaneStateImpl implements ChangeLaneState { + private static class ChangeLaneStateBaseImpl { - private final AbstractSimulationUnit unit; + final AbstractSimulationUnit unit; + + private ChangeLaneStateBaseImpl(AbstractSimulationUnit unit) { + this.unit = unit; + } + + void sendInteractionQuietly(Interaction interaction) { + try { + unit.sendInteractionToRti(interaction); + } catch (RuntimeException e) { + unit.getOsLog().error("Could not send interaction", e); + } + } + } + + private static class ChangeLaneStateImpl extends ChangeLaneStateBaseImpl implements ChangeLaneState { private final String edgeId; private final int laneIndex; private ChangeLaneStateImpl(String edgeId, int laneIndex, AbstractSimulationUnit unit) { + super(unit); this.edgeId = edgeId; this.laneIndex = laneIndex; - this.unit = unit; } @Override @@ -217,42 +232,22 @@ public ChangeLaneState closeOnlyForVehicleClasses(VehicleClass... disallowVehicl return this; } - @Override - public ChangeLaneState closeForAll() { - return closeOnlyForVehicleClasses(VehicleClass.values()); - } - - @Override - public ChangeLaneState openForAll() { - return openOnlyForVehicleClasses(VehicleClass.values()); - } - @Override public ChangeLaneState setMaxSpeed(double maxSpeedMs) { sendInteractionQuietly(new LanePropertyChange(unit.getSimulationTime(), edgeId, laneIndex, null, null, maxSpeedMs)); return this; } - - private void sendInteractionQuietly(Interaction interaction) { - try { - unit.sendInteractionToRti(interaction); - } catch (RuntimeException e) { - unit.getOsLog().error("Could not send interaction", e); - } - } } - private static class ChangeVariableMessageSignStateImpl implements ChangeLaneState { - - private final AbstractSimulationUnit unit; + private static class ChangeVariableMessageSignStateImpl extends ChangeLaneStateBaseImpl implements ChangeLaneState { private final String signId; private final int laneIndex; private ChangeVariableMessageSignStateImpl(String signId, int laneIndex, AbstractSimulationUnit unit) { + super(unit); this.signId = signId; this.laneIndex = laneIndex; - this.unit = unit; } @Override @@ -279,16 +274,6 @@ public ChangeLaneState closeOnlyForVehicleClasses(VehicleClass... disallowVehicl return openOnlyForVehicleClasses(remaining.toArray(new VehicleClass[remaining.size()])); } - @Override - public ChangeLaneState closeForAll() { - return closeOnlyForVehicleClasses(VehicleClass.values()); - } - - @Override - public ChangeLaneState openForAll() { - return openOnlyForVehicleClasses(VehicleClass.values()); - } - @Override public ChangeLaneState setMaxSpeed(double maxSpeedMs) { if (laneIndex < 0) { @@ -312,12 +297,5 @@ public ChangeLaneState setMaxSpeed(double maxSpeedMs) { return this; } - private void sendInteractionQuietly(Interaction interaction) { - try { - unit.sendInteractionToRti(interaction); - } catch (RuntimeException e) { - unit.getOsLog().error("Could not send interaction", e); - } - } } } \ No newline at end of file diff --git a/fed/mosaic-application/src/main/java/org/eclipse/mosaic/fed/application/app/api/os/TrafficManagementCenterOperatingSystem.java b/fed/mosaic-application/src/main/java/org/eclipse/mosaic/fed/application/app/api/os/TrafficManagementCenterOperatingSystem.java index a92d1715..e5e54712 100644 --- a/fed/mosaic-application/src/main/java/org/eclipse/mosaic/fed/application/app/api/os/TrafficManagementCenterOperatingSystem.java +++ b/fed/mosaic-application/src/main/java/org/eclipse/mosaic/fed/application/app/api/os/TrafficManagementCenterOperatingSystem.java @@ -90,13 +90,17 @@ interface ChangeLaneState { * Closes the lane for all vehicle classes. */ @SuppressWarnings("UnusedReturnValue") - ChangeLaneState closeForAll(); + default ChangeLaneState closeForAll(){ + return closeOnlyForVehicleClasses(VehicleClass.values()); + } /** * Opens the lane for all vehicle classes. */ @SuppressWarnings("UnusedReturnValue") - ChangeLaneState openForAll(); + default ChangeLaneState openForAll() { + return openOnlyForVehicleClasses(VehicleClass.values()); + } /** * Sets the maximum allowed speed of the lane to the given value.