Checkstyle

This commit is contained in:
Arne Keller 2020-02-19 23:18:14 +01:00
parent 931ff805a9
commit c40e635cb8
14 changed files with 36 additions and 24 deletions

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -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",

View File

@ -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
*/

View File

@ -103,10 +103,11 @@ public final class CommandFactory {
* Name of the step command.
*/
public static final String STEP = "step";
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);

View File

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

View File

@ -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:

View File

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

View File

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

View File

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

View File

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