Checkstyle

This commit is contained in:
Arne Keller 2020-02-15 16:38:54 +01:00
parent 7af35ef2b0
commit 972000204f
16 changed files with 119 additions and 59 deletions

View File

@ -2,6 +2,9 @@ package edu.kit.informatik;
/**
* A coach.
*
* @author Arne Keller
* @version 1.0
*/
public class Coach extends RollingStock {
private static final String[] PASSENGER_TEXT = new String[] {

View File

@ -3,8 +3,14 @@ package edu.kit.informatik;
import edu.kit.informatik.command.Command;
import edu.kit.informatik.command.CommandFactory;
/**
* Interactive simulation runner, gets user inputs and processes commands specified.
*
* @author Arne Keller
* @version 1.0
*/
public class CommandLine {
public static final String EXIT = "exit";
private static final String EXIT = "exit";
public static void startInteractive() {
ModelRailwaySimulation simulation = new ModelRailwaySimulation();

View File

@ -26,7 +26,8 @@ public class ElectricalEngine extends Engine {
* @param couplingFront whether the engine should have a front coupling
* @param couplingBack whether the engine should have a back coupling
*/
public ElectricalEngine(final String series, final String name, final int length, final boolean couplingFront, final boolean couplingBack) {
public ElectricalEngine(final String series, final String name, final int length,
final boolean couplingFront, final boolean couplingBack) {
super.name = name;
super.series = series;
super.length = length;

View File

@ -1,7 +1,13 @@
package edu.kit.informatik;
public abstract class Engine extends RollingStock {
/**
* Series/class of this engine.
*/
protected String series;
/**
* Name of this engine.
*/
protected String name;
public String getName() {

View File

@ -9,6 +9,7 @@ public class ModelRailwaySimulation {
private List<TrainSet> trainSets = new ArrayList<>();
private List<Coach> coaches = new ArrayList<>();
private List<Train> trains = new ArrayList<>();
/**
* Identifier if success, -1 if fail
* @param start

View File

@ -20,6 +20,7 @@ public abstract class RollingStock {
}
public abstract boolean canCoupleFrontTo(RollingStock rollingStock);
public abstract boolean canCoupleToTrainSetSeries(String series);
public abstract String[] textRepresentation();

View File

@ -83,7 +83,8 @@ public final class Switch extends Rail {
if (selection == null) {
return String.format("s %d %s -> %s,%s", getIdentifier(), start, end1, end2);
} else {
return String.format("s %d %s -> %s,%s %d", getIdentifier(), start, end1, end2, start.distanceTo(selection));
return String.format("s %d %s -> %s,%s %d", getIdentifier(),
start, end1, end2, start.distanceTo(selection));
}
}

View File

@ -2,6 +2,12 @@ package edu.kit.informatik;
import java.util.Objects;
/**
* Straight track.
*
* @author Arne Keller
* @version 1.0
*/
public final class Track extends Rail {
public final Point start;
public final Point end;

View File

@ -3,12 +3,23 @@ package edu.kit.informatik;
import java.util.ArrayList;
import java.util.List;
/**
* Train.
*
* @author Arne Keller
* @version 1.0
*/
public final class Train {
private final int identifier; // start at 1
private final int identifier;
private final List<RollingStock> rollingStocks = new ArrayList<>();
private List<Point> position;
private Point direction;
/**
* Construct a new train.
* @param identifier identifier to use
* @param rollingStock initial rolling stock
*/
public Train(final int identifier, final RollingStock rollingStock) {
this.identifier = identifier;
this.rollingStocks.add(rollingStock);

View File

@ -1,10 +1,36 @@
package edu.kit.informatik;
/**
* Train set.
*
* @author Arne Keller
* @version 1.0
*/
public class TrainSet extends RollingStock {
private static final String[] TRAIN_SET_TEXT = new String[] {
" ++ ",
" || ",
"_________||_________",
"| ___ ___ ___ ___ |",
"| |_| |_| |_| |_| |",
"|__________________|",
"|__________________|",
" (O) (O) "
};
private String series;
private String name;
public TrainSet(final String series, final String name, final int length, final boolean couplingFront, final boolean couplingBack) {
/**
* Construct a new train set.
* @param series series/class of train set
* @param name name of train set
* @param length length of train set
* @param couplingFront whether the train set should have a front coupling
* @param couplingBack whether the train set should have a back coupling
*/
public TrainSet(final String series, final String name, final int length,
final boolean couplingFront, final boolean couplingBack) {
this.name = name;
this.series = series;
super.length = length;
@ -32,17 +58,6 @@ public class TrainSet extends RollingStock {
return this.series.equals(series);
}
private static final String[] TRAIN_SET_TEXT = new String[] {
" ++ ",
" || ",
"_________||_________",
"| ___ ___ ___ ___ |",
"| |_| |_| |_| |_| |",
"|__________________|",
"|__________________|",
" (O) (O) "
};
@Override
public String[] textRepresentation() {
return TRAIN_SET_TEXT;

View File

@ -16,8 +16,8 @@ public class AddTrack extends Command {
/**
* Construct a new 'add track' command.
* @param start
* @param end
* @param start position of the start of the track
* @param end position of the end of the track
*/
public AddTrack(final Point start, final Point end) {
this.start = start;
@ -25,7 +25,7 @@ public class AddTrack extends Command {
}
@Override
public void apply(ModelRailwaySimulation simulation) {
public void apply(final ModelRailwaySimulation simulation) {
if (start.equals(end)) {
Terminal.printError("track has length 0");
return;

View File

@ -15,43 +15,43 @@ import java.util.regex.Pattern;
* @version 1.0
*/
public class CommandFactory {
public static final String ADD_TRACK = "add track";
public static final Pattern ADD_TRACK_ARGUMENTS
private static final String ADD_TRACK = "add track";
private static final Pattern ADD_TRACK_ARGUMENTS
= Pattern.compile(" \\(([+-]?\\d+,[+-]?\\d+)\\) -> \\(([+-]?\\d+,[+-]?\\d+)\\)");
public static final String ADD_SWITCH = "add switch";
public static final Pattern ADD_SWITCH_ARGUMENTS
private static final String ADD_SWITCH = "add switch";
private static final Pattern ADD_SWITCH_ARGUMENTS
= Pattern.compile(" \\(([+-]?\\d+,[+-]?\\d+)\\) -> \\(([+-]?\\d+,[+-]?\\d+)\\),\\(([+-]?\\d+,[+-]?\\d+)\\)");
public static final String DELETE_TRACK = "delete track";
public static final String LIST_TRACKS = "list tracks";
public static final String SET_SWITCH = "set switch";
public static final Pattern SET_SWITCH_ARGUMENTS
private static final String DELETE_TRACK = "delete track";
private static final String LIST_TRACKS = "list tracks";
private static final String SET_SWITCH = "set switch";
private static final Pattern SET_SWITCH_ARGUMENTS
= Pattern.compile(" \\+?(\\d+) position \\(([+-]?\\d+,[+-]?\\d+)\\)");
public static final String CREATE_ENGINE = "create engine";
public static final Pattern CREATE_ENGINE_ARGUMENTS
private static final String CREATE_ENGINE = "create engine";
private static final Pattern CREATE_ENGINE_ARGUMENTS
= Pattern.compile(" (electrical|diesel|steam) (\\w+) (\\w+) \\+?(\\d+) (true|false) (true|false)");
public static final String LIST_ENGINES = "list engines";
public static final String CREATE_COACH = "create coach";
public static final Pattern CREATE_COACH_ARGUMENTS
private static final String LIST_ENGINES = "list engines";
private static final String CREATE_COACH = "create coach";
private static final Pattern CREATE_COACH_ARGUMENTS
= Pattern.compile(" (passenger|freight|special) \\+?(\\d+) (true|false) (true|false)");
public static final String LIST_COACHES = "list coaches";
public static final String CREATE_TRAIN_SET = "create train-set";
public static final Pattern CREATE_TRAIN_SET_ARGUMENTS
private static final String LIST_COACHES = "list coaches";
private static final String CREATE_TRAIN_SET = "create train-set";
private static final Pattern CREATE_TRAIN_SET_ARGUMENTS
= Pattern.compile(" (\\w+) (\\w+) \\+?(\\d+) (true|false) (true|false)");
public static final String LIST_TRAIN_SETS = "list train-sets";
public static final String DELETE_ROLLING_STOCK = "delete rolling stock";
public static final Pattern DELETE_ROLLING_STOCK_ARGUMENT
private static final String LIST_TRAIN_SETS = "list train-sets";
private static final String DELETE_ROLLING_STOCK = "delete rolling stock";
private static final Pattern DELETE_ROLLING_STOCK_ARGUMENT
= Pattern.compile(" (\\w+(-\\w*)?)");
public static final String ADD_TRAIN = "add train";
public static final Pattern ADD_TRAIN_ARGUMENTS
private static final String ADD_TRAIN = "add train";
private static final Pattern ADD_TRAIN_ARGUMENTS
= Pattern.compile(" \\+?(\\d+) ((\\w+-\\w+)|(W\\+?\\d+))");
public static final String DELETE_TRAIN = "delete train";
public static final String LIST_TRAINS = "list trains";
public static final String SHOW_TRAIN = "show train";
public static final String PUT_TRAIN = "put train";
public static final Pattern PUT_TRAIN_ARGUMENTS
private static final String DELETE_TRAIN = "delete train";
private static final String LIST_TRAINS = "list trains";
private static final String SHOW_TRAIN = "show train";
private static final String PUT_TRAIN = "put train";
private static final Pattern PUT_TRAIN_ARGUMENTS
= Pattern.compile(" \\+?(\\d+) at \\(([+-]?\\d+,[+-]?\\d+)\\) in direction ([+-]?\\d+),([+-]?\\d+)");
public static final String STEP = "step";
public static final String POSITIVE_NUMBER = " \\+?\\d+";
private static final String STEP = "step";
private static final String POSITIVE_NUMBER = " \\+?\\d+";
/**
* Parse a single line of user input into one command.

View File

@ -23,7 +23,8 @@ public class CreateCoach extends Command {
* @param couplingFront whether the coach should have a front coupling
* @param couplingBack whether the coach should have a back coupling
*/
public CreateCoach(final CoachType type, final int length, final boolean couplingFront, final boolean couplingBack) {
public CreateCoach(final CoachType type, final int length,
final boolean couplingFront, final boolean couplingBack) {
this.type = type;
this.length = length;
this.couplingFront = couplingFront;

View File

@ -25,7 +25,8 @@ public class CreateEngine extends Command {
* @param couplingFront whether the new engine should have a front coupling
* @param couplingBack whether the new engine should have a back coupling
*/
public CreateEngine(final EngineType type, final String series, final String name, final int length, final boolean couplingFront, final boolean couplingBack) {
public CreateEngine(final EngineType type, final String series, final String name, final int length,
final boolean couplingFront, final boolean couplingBack) {
this.type = type;
this.series = series;
this.name = name;

View File

@ -6,6 +6,9 @@ import edu.kit.informatik.TrainSet;
/**
* Command used to add a new train set.
*
* @author Arne Keller
* @version Arne Keller
*/
public class CreateTrainSet extends Command {
private final String series;
@ -22,7 +25,8 @@ public class CreateTrainSet extends Command {
* @param couplingFront whether the train set should have a front coupling
* @param couplingBack whether the train set should have a back coupling
*/
public CreateTrainSet(final String series, final String name, final int length, final boolean couplingFront, final boolean couplingBack) {
public CreateTrainSet(final String series, final String name, final int length,
final boolean couplingFront, final boolean couplingBack) {
this.series = series;
this.name = name;
this.length = length;

View File

@ -5,6 +5,9 @@ import edu.kit.informatik.Terminal;
/**
* Command used to delete rolling stock.
*
* @author Arne Keller
* @version 1.0
*/
public class DeleteRollingStock extends Command {
private final String id;