Make Command an abstract class

This commit is contained in:
Arne Keller 2020-02-17 12:33:26 +01:00
parent fbf80103be
commit efcd3a721b
19 changed files with 39 additions and 21 deletions

View File

@ -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) {

View File

@ -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");

View File

@ -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);

View File

@ -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);
}

View File

@ -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) {

View File

@ -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) {

View File

@ -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)) {

View File

@ -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");

View File

@ -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");

View File

@ -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");

View File

@ -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();
}

View File

@ -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();
}

View File

@ -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();
}

View File

@ -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();
}

View File

@ -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();
}

View File

@ -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");

View File

@ -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");

View File

@ -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);
}

View File

@ -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);
}