From 972000204fd30668877cd705d3ebdaa7b1431bf0 Mon Sep 17 00:00:00 2001 From: Arne Keller Date: Sat, 15 Feb 2020 16:38:54 +0100 Subject: [PATCH] Checkstyle --- src/edu/kit/informatik/Coach.java | 3 + src/edu/kit/informatik/CommandLine.java | 8 +- src/edu/kit/informatik/ElectricalEngine.java | 3 +- src/edu/kit/informatik/Engine.java | 6 ++ .../informatik/ModelRailwaySimulation.java | 1 + src/edu/kit/informatik/RollingStock.java | 1 + src/edu/kit/informatik/Switch.java | 3 +- src/edu/kit/informatik/Track.java | 6 ++ src/edu/kit/informatik/Train.java | 13 +++- src/edu/kit/informatik/TrainSet.java | 39 +++++++--- src/edu/kit/informatik/command/AddTrack.java | 6 +- .../informatik/command/CommandFactory.java | 74 +++++++++---------- .../kit/informatik/command/CreateCoach.java | 3 +- .../kit/informatik/command/CreateEngine.java | 3 +- .../informatik/command/CreateTrainSet.java | 6 +- .../command/DeleteRollingStock.java | 3 + 16 files changed, 119 insertions(+), 59 deletions(-) diff --git a/src/edu/kit/informatik/Coach.java b/src/edu/kit/informatik/Coach.java index e8ab561..dfa5ee1 100644 --- a/src/edu/kit/informatik/Coach.java +++ b/src/edu/kit/informatik/Coach.java @@ -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[] { diff --git a/src/edu/kit/informatik/CommandLine.java b/src/edu/kit/informatik/CommandLine.java index 81c6286..f2d9490 100644 --- a/src/edu/kit/informatik/CommandLine.java +++ b/src/edu/kit/informatik/CommandLine.java @@ -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(); diff --git a/src/edu/kit/informatik/ElectricalEngine.java b/src/edu/kit/informatik/ElectricalEngine.java index 242d024..5776a0e 100644 --- a/src/edu/kit/informatik/ElectricalEngine.java +++ b/src/edu/kit/informatik/ElectricalEngine.java @@ -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; diff --git a/src/edu/kit/informatik/Engine.java b/src/edu/kit/informatik/Engine.java index 151a9a2..86d471d 100644 --- a/src/edu/kit/informatik/Engine.java +++ b/src/edu/kit/informatik/Engine.java @@ -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() { diff --git a/src/edu/kit/informatik/ModelRailwaySimulation.java b/src/edu/kit/informatik/ModelRailwaySimulation.java index 2452ae3..94d320c 100644 --- a/src/edu/kit/informatik/ModelRailwaySimulation.java +++ b/src/edu/kit/informatik/ModelRailwaySimulation.java @@ -9,6 +9,7 @@ public class ModelRailwaySimulation { private List trainSets = new ArrayList<>(); private List coaches = new ArrayList<>(); private List trains = new ArrayList<>(); + /** * Identifier if success, -1 if fail * @param start diff --git a/src/edu/kit/informatik/RollingStock.java b/src/edu/kit/informatik/RollingStock.java index 9ddfbe8..0c46988 100644 --- a/src/edu/kit/informatik/RollingStock.java +++ b/src/edu/kit/informatik/RollingStock.java @@ -20,6 +20,7 @@ public abstract class RollingStock { } public abstract boolean canCoupleFrontTo(RollingStock rollingStock); + public abstract boolean canCoupleToTrainSetSeries(String series); public abstract String[] textRepresentation(); diff --git a/src/edu/kit/informatik/Switch.java b/src/edu/kit/informatik/Switch.java index 0ad600a..42fdaaf 100644 --- a/src/edu/kit/informatik/Switch.java +++ b/src/edu/kit/informatik/Switch.java @@ -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)); } } diff --git a/src/edu/kit/informatik/Track.java b/src/edu/kit/informatik/Track.java index cac5369..c486120 100644 --- a/src/edu/kit/informatik/Track.java +++ b/src/edu/kit/informatik/Track.java @@ -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; diff --git a/src/edu/kit/informatik/Train.java b/src/edu/kit/informatik/Train.java index a7e88aa..9c22b59 100644 --- a/src/edu/kit/informatik/Train.java +++ b/src/edu/kit/informatik/Train.java @@ -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 rollingStocks = new ArrayList<>(); private List 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); diff --git a/src/edu/kit/informatik/TrainSet.java b/src/edu/kit/informatik/TrainSet.java index 120a690..4c571ad 100644 --- a/src/edu/kit/informatik/TrainSet.java +++ b/src/edu/kit/informatik/TrainSet.java @@ -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; diff --git a/src/edu/kit/informatik/command/AddTrack.java b/src/edu/kit/informatik/command/AddTrack.java index 75f7bc2..6cc0928 100644 --- a/src/edu/kit/informatik/command/AddTrack.java +++ b/src/edu/kit/informatik/command/AddTrack.java @@ -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; diff --git a/src/edu/kit/informatik/command/CommandFactory.java b/src/edu/kit/informatik/command/CommandFactory.java index 98cdc80..eb3c264 100644 --- a/src/edu/kit/informatik/command/CommandFactory.java +++ b/src/edu/kit/informatik/command/CommandFactory.java @@ -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 - = Pattern.compile(" \\(([+-]?\\d+,[+-]?\\d+)\\) -> \\(([+-]?\\d+,[+-]?\\d+)\\)"); - public static final String ADD_SWITCH = "add switch"; - public 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 - = Pattern.compile(" \\+?(\\d+) position \\(([+-]?\\d+,[+-]?\\d+)\\)"); - public static final String CREATE_ENGINE = "create engine"; - public 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 - = 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 - = 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 - = Pattern.compile(" (\\w+(-\\w*)?)"); - public static final String ADD_TRAIN = "add train"; - public 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 - = 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 ADD_TRACK = "add track"; + private static final Pattern ADD_TRACK_ARGUMENTS + = Pattern.compile(" \\(([+-]?\\d+,[+-]?\\d+)\\) -> \\(([+-]?\\d+,[+-]?\\d+)\\)"); + private static final String ADD_SWITCH = "add switch"; + private static final Pattern ADD_SWITCH_ARGUMENTS + = Pattern.compile(" \\(([+-]?\\d+,[+-]?\\d+)\\) -> \\(([+-]?\\d+,[+-]?\\d+)\\),\\(([+-]?\\d+,[+-]?\\d+)\\)"); + 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+)\\)"); + 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)"); + 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)"); + 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)"); + 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*)?)"); + private static final String ADD_TRAIN = "add train"; + private static final Pattern ADD_TRAIN_ARGUMENTS + = Pattern.compile(" \\+?(\\d+) ((\\w+-\\w+)|(W\\+?\\d+))"); + 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+)"); + private static final String STEP = "step"; + private static final String POSITIVE_NUMBER = " \\+?\\d+"; /** * Parse a single line of user input into one command. diff --git a/src/edu/kit/informatik/command/CreateCoach.java b/src/edu/kit/informatik/command/CreateCoach.java index 0c632de..888364d 100644 --- a/src/edu/kit/informatik/command/CreateCoach.java +++ b/src/edu/kit/informatik/command/CreateCoach.java @@ -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; diff --git a/src/edu/kit/informatik/command/CreateEngine.java b/src/edu/kit/informatik/command/CreateEngine.java index 0d410dd..0fa94eb 100644 --- a/src/edu/kit/informatik/command/CreateEngine.java +++ b/src/edu/kit/informatik/command/CreateEngine.java @@ -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; diff --git a/src/edu/kit/informatik/command/CreateTrainSet.java b/src/edu/kit/informatik/command/CreateTrainSet.java index 562f149..eefac54 100644 --- a/src/edu/kit/informatik/command/CreateTrainSet.java +++ b/src/edu/kit/informatik/command/CreateTrainSet.java @@ -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; diff --git a/src/edu/kit/informatik/command/DeleteRollingStock.java b/src/edu/kit/informatik/command/DeleteRollingStock.java index 5f27e0c..98437a7 100644 --- a/src/edu/kit/informatik/command/DeleteRollingStock.java +++ b/src/edu/kit/informatik/command/DeleteRollingStock.java @@ -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;