mirror of
https://gitlab.com/arnekeller/kit-programmieren-ws1920-final1.git
synced 2024-11-09 02:10:40 +00:00
Checkstyle
This commit is contained in:
parent
931ff805a9
commit
c40e635cb8
@ -50,7 +50,9 @@ public abstract class Rail {
|
||||
* @param position point to connect to
|
||||
* @return whether rail could be successfully set
|
||||
*/
|
||||
public abstract boolean switchTo(Vector2D position);
|
||||
public boolean switchTo(Vector2D position) {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return whether the rail is ready for trains running on it
|
||||
|
@ -51,11 +51,6 @@ public final class Track extends Rail {
|
||||
return rail != null && (rail.canConnectTo(start) || rail.canConnectTo(end));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean switchTo(Vector2D position) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isReadyForTrains() {
|
||||
return true;
|
||||
|
@ -37,18 +37,4 @@ public enum CoachType {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
switch (this) {
|
||||
case PASSENGER:
|
||||
return "p";
|
||||
case FREIGHT:
|
||||
return "f";
|
||||
case SPECIAL:
|
||||
return "s";
|
||||
default:
|
||||
throw new IllegalStateException();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -36,6 +36,9 @@ public class AddSwitch extends Command {
|
||||
|
||||
@Override
|
||||
public void apply(final ModelRailwaySimulation simulation) throws InvalidInputException {
|
||||
if (start == null) {
|
||||
throw new IllegalStateException("command not initialized");
|
||||
}
|
||||
int id = simulation.addSwitch(start, end1, end2);
|
||||
if (id == -1) {
|
||||
Terminal.printError("switch not connected to existing rails");
|
||||
|
@ -32,6 +32,9 @@ public class AddTrack extends Command {
|
||||
|
||||
@Override
|
||||
public void apply(final ModelRailwaySimulation simulation) throws InvalidInputException {
|
||||
if (start == null) {
|
||||
throw new IllegalStateException("command not initialized");
|
||||
}
|
||||
int id = simulation.addTrack(start, end);
|
||||
if (id == -1) {
|
||||
Terminal.printError("id space exhausted");
|
||||
|
@ -33,6 +33,9 @@ public class AddTrain extends Command {
|
||||
|
||||
@Override
|
||||
public void apply(final ModelRailwaySimulation simulation) throws InvalidInputException {
|
||||
if (rollingStockId == null) {
|
||||
throw new IllegalStateException("command not initialized");
|
||||
}
|
||||
simulation.addTrain(trainId, rollingStockId);
|
||||
RollingStock rollingStock = simulation.getRollingStock(rollingStockId);
|
||||
Terminal.printLine(String.format("%s %s added to train %d",
|
||||
|
@ -5,7 +5,7 @@ import edu.kit.informatik.ui.InvalidInputException;
|
||||
|
||||
/**
|
||||
* 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 for easy modification and expansion.
|
||||
*
|
||||
* @author Arne Keller
|
||||
* @version 1.0
|
||||
@ -15,11 +15,12 @@ public abstract class Command {
|
||||
* Apply this command to a model railway simulation.
|
||||
* @param simulation simulation to use
|
||||
* @throws InvalidInputException on invalid user input
|
||||
* @throws IllegalStateException if the command is not yet initialized
|
||||
*/
|
||||
public abstract void apply(ModelRailwaySimulation simulation) throws InvalidInputException;
|
||||
public abstract void apply(ModelRailwaySimulation simulation) throws InvalidInputException, IllegalStateException;
|
||||
|
||||
/**
|
||||
* Parse user input into the command object.
|
||||
* Parse user input into this command object.
|
||||
* @param input one line of user input
|
||||
* @throws InvalidInputException if user input is in any way invalid
|
||||
*/
|
||||
|
@ -107,6 +107,7 @@ public final class CommandFactory {
|
||||
private static final Map<String, Supplier<Command>> COMMANDS = new HashMap<>();
|
||||
|
||||
static {
|
||||
// initialize registered commands
|
||||
COMMANDS.put(ADD_TRACK, AddTrack::new);
|
||||
COMMANDS.put(ADD_SWITCH, AddSwitch::new);
|
||||
COMMANDS.put(DELETE_TRACK, DeleteTrack::new);
|
||||
|
@ -40,6 +40,9 @@ public class CreateCoach extends Command {
|
||||
|
||||
@Override
|
||||
public void apply(final ModelRailwaySimulation simulation) throws InvalidInputException {
|
||||
if (type == null) {
|
||||
throw new IllegalStateException("command not initialized");
|
||||
}
|
||||
int id = simulation.createCoach(type, length, couplingFront, couplingBack);
|
||||
if (id == -1) {
|
||||
Terminal.printError("id space exhausted");
|
||||
|
@ -54,6 +54,9 @@ public class CreateEngine extends Command {
|
||||
|
||||
@Override
|
||||
public void apply(final ModelRailwaySimulation simulation) throws InvalidInputException {
|
||||
if (type == null) {
|
||||
throw new IllegalStateException("command not initialized");
|
||||
}
|
||||
Engine engine;
|
||||
switch (type) {
|
||||
case ELECTRICAL:
|
||||
|
@ -46,6 +46,9 @@ public class CreateTrainSet extends Command {
|
||||
|
||||
@Override
|
||||
public void apply(final ModelRailwaySimulation simulation) throws InvalidInputException {
|
||||
if (name == null) {
|
||||
throw new IllegalStateException("command not initialized");
|
||||
}
|
||||
TrainSet trainSet = new TrainSet(series, name, length, couplingFront, couplingBack);
|
||||
simulation.createTrainSet(trainSet);
|
||||
Terminal.printLine(trainSet.getIdentifier());
|
||||
|
@ -27,6 +27,9 @@ public class DeleteRollingStock extends Command {
|
||||
|
||||
@Override
|
||||
public void apply(final ModelRailwaySimulation simulation) {
|
||||
if (id == null) {
|
||||
throw new IllegalStateException("command not initialized");
|
||||
}
|
||||
if (simulation.deleteRollingStock(id)) {
|
||||
Terminal.printLine("OK");
|
||||
} else {
|
||||
|
@ -37,6 +37,9 @@ public class PutTrain extends Command {
|
||||
|
||||
@Override
|
||||
public void apply(final ModelRailwaySimulation simulation) throws InvalidInputException {
|
||||
if (point == null) {
|
||||
throw new IllegalStateException("command not initialized");
|
||||
}
|
||||
if (simulation.putTrain(id, point, direction)) {
|
||||
Terminal.printLine("OK");
|
||||
} else {
|
||||
|
@ -33,6 +33,9 @@ public class SetSwitch extends Command {
|
||||
|
||||
@Override
|
||||
public void apply(final ModelRailwaySimulation simulation) {
|
||||
if (point == null) {
|
||||
throw new IllegalStateException("command not initialized");
|
||||
}
|
||||
if (simulation.setSwitch(id, point)) {
|
||||
Terminal.printLine("OK");
|
||||
} else {
|
||||
|
Loading…
Reference in New Issue
Block a user