From efcd3a721b4f6404160f80ab039d7ad6b004d855 Mon Sep 17 00:00:00 2001 From: Arne Keller Date: Mon, 17 Feb 2020 12:33:26 +0100 Subject: [PATCH] Make Command an abstract class --- src/edu/kit/informatik/ui/command/AddSwitch.java | 3 ++- src/edu/kit/informatik/ui/command/AddTrack.java | 3 ++- src/edu/kit/informatik/ui/command/AddTrain.java | 3 ++- src/edu/kit/informatik/ui/command/Command.java | 6 +++--- src/edu/kit/informatik/ui/command/CreateCoach.java | 3 ++- src/edu/kit/informatik/ui/command/CreateEngine.java | 3 ++- src/edu/kit/informatik/ui/command/CreateTrainSet.java | 3 ++- src/edu/kit/informatik/ui/command/DeleteRollingStock.java | 3 ++- src/edu/kit/informatik/ui/command/DeleteTrack.java | 3 ++- src/edu/kit/informatik/ui/command/DeleteTrain.java | 3 ++- src/edu/kit/informatik/ui/command/ListCoaches.java | 3 ++- src/edu/kit/informatik/ui/command/ListEngines.java | 3 ++- src/edu/kit/informatik/ui/command/ListTracks.java | 3 ++- src/edu/kit/informatik/ui/command/ListTrainSets.java | 3 ++- src/edu/kit/informatik/ui/command/ListTrains.java | 3 ++- src/edu/kit/informatik/ui/command/PutTrain.java | 3 ++- src/edu/kit/informatik/ui/command/SetSwitch.java | 3 ++- src/edu/kit/informatik/ui/command/ShowTrain.java | 3 ++- src/edu/kit/informatik/ui/command/Step.java | 3 ++- 19 files changed, 39 insertions(+), 21 deletions(-) diff --git a/src/edu/kit/informatik/ui/command/AddSwitch.java b/src/edu/kit/informatik/ui/command/AddSwitch.java index 4e3eec2..66c9d3a 100644 --- a/src/edu/kit/informatik/ui/command/AddSwitch.java +++ b/src/edu/kit/informatik/ui/command/AddSwitch.java @@ -10,7 +10,7 @@ import edu.kit.informatik.Terminal; * @author Arne Keller * @version 1.0 */ -public class AddSwitch implements Command { +public class AddSwitch extends Command { /** * Start position of the switch to add. */ @@ -37,6 +37,7 @@ public class AddSwitch implements Command { this.end2 = new Vector2D(end2); } + @Override public void apply(final ModelRailwaySimulation simulation) { int id = simulation.addSwitch(start, end1, end2); if (id == -1) { diff --git a/src/edu/kit/informatik/ui/command/AddTrack.java b/src/edu/kit/informatik/ui/command/AddTrack.java index eb2e68f..0fc1cf5 100644 --- a/src/edu/kit/informatik/ui/command/AddTrack.java +++ b/src/edu/kit/informatik/ui/command/AddTrack.java @@ -10,7 +10,7 @@ import edu.kit.informatik.Terminal; * @author Arne Keller * @version 1.0 */ -public class AddTrack implements Command { +public class AddTrack extends Command { /** * Start position of the new track. */ @@ -31,6 +31,7 @@ public class AddTrack implements Command { this.end = new Vector2D(end); } + @Override public void apply(final ModelRailwaySimulation simulation) { if (start.equals(end)) { Terminal.printError("track has length 0"); diff --git a/src/edu/kit/informatik/ui/command/AddTrain.java b/src/edu/kit/informatik/ui/command/AddTrain.java index 21c9b72..d4ace01 100644 --- a/src/edu/kit/informatik/ui/command/AddTrain.java +++ b/src/edu/kit/informatik/ui/command/AddTrain.java @@ -10,7 +10,7 @@ import edu.kit.informatik.Terminal; * @author Arne Keller * @version 1.0 */ -public class AddTrain implements Command { +public class AddTrain extends Command { /** * Identifier of the train to add or modify. */ @@ -30,6 +30,7 @@ public class AddTrain implements Command { this.rollingStockId = rollingStockId; } + @Override public void apply(final ModelRailwaySimulation simulation) { if (simulation.addTrain(trainId, rollingStockId)) { RollingStock rollingStock = simulation.getRollingStock(rollingStockId); diff --git a/src/edu/kit/informatik/ui/command/Command.java b/src/edu/kit/informatik/ui/command/Command.java index bbe7061..a9112ac 100644 --- a/src/edu/kit/informatik/ui/command/Command.java +++ b/src/edu/kit/informatik/ui/command/Command.java @@ -4,15 +4,15 @@ import edu.kit.informatik.model.ModelRailwaySimulation; /** * Command that can be applied to a simulation. - * Commands are implemented as separate classes to avoid a god enum :) + * Commands are implemented as separate classes (to avoid a god enum). * * @author Arne Keller * @version 1.0 */ -public interface Command { +public abstract class Command { /** * Apply this command to a model railway simulation. * @param simulation simulation to use */ - void apply(ModelRailwaySimulation simulation); + public abstract void apply(ModelRailwaySimulation simulation); } diff --git a/src/edu/kit/informatik/ui/command/CreateCoach.java b/src/edu/kit/informatik/ui/command/CreateCoach.java index d92b07f..13cf393 100644 --- a/src/edu/kit/informatik/ui/command/CreateCoach.java +++ b/src/edu/kit/informatik/ui/command/CreateCoach.java @@ -10,7 +10,7 @@ import edu.kit.informatik.Terminal; * @author Arne Keller * @version 1.0 */ -public class CreateCoach implements Command { +public class CreateCoach extends Command { /** * Type of the new coach. */ @@ -46,6 +46,7 @@ public class CreateCoach implements Command { this.couplingBack = couplingBack; } + @Override public void apply(final ModelRailwaySimulation simulation) { int id = simulation.createCoach(type, length, couplingFront, couplingBack); if (id == -1) { diff --git a/src/edu/kit/informatik/ui/command/CreateEngine.java b/src/edu/kit/informatik/ui/command/CreateEngine.java index 5119950..7dc9d9c 100644 --- a/src/edu/kit/informatik/ui/command/CreateEngine.java +++ b/src/edu/kit/informatik/ui/command/CreateEngine.java @@ -14,7 +14,7 @@ import edu.kit.informatik.ui.EngineType; * @author Arne Keller * @version 1.0 */ -public class CreateEngine implements Command { +public class CreateEngine extends Command { /** * Type of the new engine. */ @@ -62,6 +62,7 @@ public class CreateEngine implements Command { this.couplingBack = couplingBack; } + @Override public void apply(final ModelRailwaySimulation simulation) { Engine engine; switch (type) { diff --git a/src/edu/kit/informatik/ui/command/CreateTrainSet.java b/src/edu/kit/informatik/ui/command/CreateTrainSet.java index 19eb6ff..4702e0b 100644 --- a/src/edu/kit/informatik/ui/command/CreateTrainSet.java +++ b/src/edu/kit/informatik/ui/command/CreateTrainSet.java @@ -10,7 +10,7 @@ import edu.kit.informatik.model.TrainSet; * @author Arne Keller * @version Arne Keller */ -public class CreateTrainSet implements Command { +public class CreateTrainSet extends Command { /** * Series (class) of the new train set. */ @@ -49,6 +49,7 @@ public class CreateTrainSet implements Command { this.couplingBack = couplingBack; } + @Override public void apply(final ModelRailwaySimulation simulation) { TrainSet trainSet = new TrainSet(series, name, length, couplingFront, couplingBack); if (simulation.createTrainSet(trainSet)) { diff --git a/src/edu/kit/informatik/ui/command/DeleteRollingStock.java b/src/edu/kit/informatik/ui/command/DeleteRollingStock.java index a1e8f77..1ce3e07 100644 --- a/src/edu/kit/informatik/ui/command/DeleteRollingStock.java +++ b/src/edu/kit/informatik/ui/command/DeleteRollingStock.java @@ -9,7 +9,7 @@ import edu.kit.informatik.Terminal; * @author Arne Keller * @version 1.0 */ -public class DeleteRollingStock implements Command { +public class DeleteRollingStock extends Command { /** * Identifier of the rolling stock to delete. */ @@ -23,6 +23,7 @@ public class DeleteRollingStock implements Command { this.id = id; } + @Override public void apply(final ModelRailwaySimulation simulation) { if (simulation.deleteRollingStock(id)) { Terminal.printLine("OK"); diff --git a/src/edu/kit/informatik/ui/command/DeleteTrack.java b/src/edu/kit/informatik/ui/command/DeleteTrack.java index 2453fd5..12ca58d 100644 --- a/src/edu/kit/informatik/ui/command/DeleteTrack.java +++ b/src/edu/kit/informatik/ui/command/DeleteTrack.java @@ -9,7 +9,7 @@ import edu.kit.informatik.Terminal; * @author Arne Keller * @version 1.0 */ -public class DeleteTrack implements Command { +public class DeleteTrack extends Command { /** * Identifier of the rail to delete. */ @@ -23,6 +23,7 @@ public class DeleteTrack implements Command { this.id = id; } + @Override public void apply(final ModelRailwaySimulation simulation) { if (simulation.removeRail(id)) { Terminal.printLine("OK"); diff --git a/src/edu/kit/informatik/ui/command/DeleteTrain.java b/src/edu/kit/informatik/ui/command/DeleteTrain.java index 86967cd..21150f9 100644 --- a/src/edu/kit/informatik/ui/command/DeleteTrain.java +++ b/src/edu/kit/informatik/ui/command/DeleteTrain.java @@ -9,7 +9,7 @@ import edu.kit.informatik.Terminal; * @author Arne Keller * @version 1.0 */ -public class DeleteTrain implements Command { +public class DeleteTrain extends Command { /** * Identifer of the train to delete. */ @@ -23,6 +23,7 @@ public class DeleteTrain implements Command { this.id = id; } + @Override public void apply(final ModelRailwaySimulation simulation) { if (simulation.deleteTrain(id)) { Terminal.printLine("OK"); diff --git a/src/edu/kit/informatik/ui/command/ListCoaches.java b/src/edu/kit/informatik/ui/command/ListCoaches.java index 357c44d..27100a9 100644 --- a/src/edu/kit/informatik/ui/command/ListCoaches.java +++ b/src/edu/kit/informatik/ui/command/ListCoaches.java @@ -8,7 +8,8 @@ import edu.kit.informatik.model.ModelRailwaySimulation; * @author Arne Keller * @version 1.0 */ -public class ListCoaches implements Command { +public class ListCoaches extends Command { + @Override public void apply(final ModelRailwaySimulation simulation) { simulation.printCoaches(); } diff --git a/src/edu/kit/informatik/ui/command/ListEngines.java b/src/edu/kit/informatik/ui/command/ListEngines.java index 04283f5..9244e3a 100644 --- a/src/edu/kit/informatik/ui/command/ListEngines.java +++ b/src/edu/kit/informatik/ui/command/ListEngines.java @@ -8,7 +8,8 @@ import edu.kit.informatik.model.ModelRailwaySimulation; * @author Arne Keller * @version 1.0 */ -public class ListEngines implements Command { +public class ListEngines extends Command { + @Override public void apply(final ModelRailwaySimulation simulation) { simulation.printEngines(); } diff --git a/src/edu/kit/informatik/ui/command/ListTracks.java b/src/edu/kit/informatik/ui/command/ListTracks.java index fa491bd..32f939a 100644 --- a/src/edu/kit/informatik/ui/command/ListTracks.java +++ b/src/edu/kit/informatik/ui/command/ListTracks.java @@ -8,7 +8,8 @@ import edu.kit.informatik.model.ModelRailwaySimulation; * @author Arne Keller * @version 1.0 */ -public class ListTracks implements Command { +public class ListTracks extends Command { + @Override public void apply(final ModelRailwaySimulation simulation) { simulation.printTracks(); } diff --git a/src/edu/kit/informatik/ui/command/ListTrainSets.java b/src/edu/kit/informatik/ui/command/ListTrainSets.java index 582f5d9..202fffd 100644 --- a/src/edu/kit/informatik/ui/command/ListTrainSets.java +++ b/src/edu/kit/informatik/ui/command/ListTrainSets.java @@ -8,7 +8,8 @@ import edu.kit.informatik.model.ModelRailwaySimulation; * @author Arne Keller * @version 1.0 */ -public class ListTrainSets implements Command { +public class ListTrainSets extends Command { + @Override public void apply(final ModelRailwaySimulation simulation) { simulation.printTrainSets(); } diff --git a/src/edu/kit/informatik/ui/command/ListTrains.java b/src/edu/kit/informatik/ui/command/ListTrains.java index 19273e5..5a1b0c5 100644 --- a/src/edu/kit/informatik/ui/command/ListTrains.java +++ b/src/edu/kit/informatik/ui/command/ListTrains.java @@ -8,7 +8,8 @@ import edu.kit.informatik.model.ModelRailwaySimulation; * @author Arne Keller * @version 1.0 */ -public class ListTrains implements Command { +public class ListTrains extends Command { + @Override public void apply(final ModelRailwaySimulation simulation) { simulation.printTrains(); } diff --git a/src/edu/kit/informatik/ui/command/PutTrain.java b/src/edu/kit/informatik/ui/command/PutTrain.java index 8604744..bfad67d 100644 --- a/src/edu/kit/informatik/ui/command/PutTrain.java +++ b/src/edu/kit/informatik/ui/command/PutTrain.java @@ -10,7 +10,7 @@ import edu.kit.informatik.Terminal; * @author Arne Keller * @version 1.0 */ -public class PutTrain implements Command { +public class PutTrain extends Command { private final int id; private final Vector2D point; private final int x; @@ -30,6 +30,7 @@ public class PutTrain implements Command { this.y = y; } + @Override public void apply(final ModelRailwaySimulation simulation) { if (simulation.putTrain(id, point, new Vector2D(x, y))) { Terminal.printLine("OK"); diff --git a/src/edu/kit/informatik/ui/command/SetSwitch.java b/src/edu/kit/informatik/ui/command/SetSwitch.java index fb6b719..d0126d1 100644 --- a/src/edu/kit/informatik/ui/command/SetSwitch.java +++ b/src/edu/kit/informatik/ui/command/SetSwitch.java @@ -10,7 +10,7 @@ import edu.kit.informatik.Terminal; * @author Arne Keller * @version 1.0 */ -public class SetSwitch implements Command { +public class SetSwitch extends Command { private final int id; private final Vector2D point; @@ -24,6 +24,7 @@ public class SetSwitch implements Command { this.point = point; } + @Override public void apply(final ModelRailwaySimulation simulation) { if (simulation.setSwitch(id, point)) { Terminal.printLine("OK"); diff --git a/src/edu/kit/informatik/ui/command/ShowTrain.java b/src/edu/kit/informatik/ui/command/ShowTrain.java index 5a0586e..d76972c 100644 --- a/src/edu/kit/informatik/ui/command/ShowTrain.java +++ b/src/edu/kit/informatik/ui/command/ShowTrain.java @@ -8,7 +8,7 @@ import edu.kit.informatik.model.ModelRailwaySimulation; * @author Arne Keller * @version 1.0 */ -public class ShowTrain implements Command { +public class ShowTrain extends Command { private final int id; /** @@ -19,6 +19,7 @@ public class ShowTrain implements Command { this.id = id; } + @Override public void apply(final ModelRailwaySimulation simulation) { simulation.printTrain(id); } diff --git a/src/edu/kit/informatik/ui/command/Step.java b/src/edu/kit/informatik/ui/command/Step.java index 23a6a79..dba4ceb 100644 --- a/src/edu/kit/informatik/ui/command/Step.java +++ b/src/edu/kit/informatik/ui/command/Step.java @@ -8,7 +8,7 @@ import edu.kit.informatik.model.ModelRailwaySimulation; * @author Arne Keller * @version 1.0 */ -public class Step implements Command { +public class Step extends Command { private final short speed; /** @@ -19,6 +19,7 @@ public class Step implements Command { this.speed = speed; } + @Override public void apply(final ModelRailwaySimulation simulation) { simulation.step(speed); }