From 49e2e659080f1540f7c53e11777f17408d3aba99 Mon Sep 17 00:00:00 2001 From: Arne Keller Date: Sat, 15 Feb 2020 16:07:49 +0100 Subject: [PATCH] Checkstyle --- src/edu/kit/informatik/Coach.java | 64 +++++++++++-------- src/edu/kit/informatik/CoachType.java | 20 ++++++ src/edu/kit/informatik/EngineType.java | 8 +++ src/edu/kit/informatik/Rail.java | 25 ++++++++ .../kit/informatik/command/ListEngines.java | 8 ++- .../kit/informatik/command/ListTracks.java | 8 ++- .../kit/informatik/command/ListTrainSets.java | 8 ++- .../kit/informatik/command/ListTrains.java | 8 ++- src/edu/kit/informatik/command/PutTrain.java | 15 ++++- src/edu/kit/informatik/command/SetSwitch.java | 11 ++++ src/edu/kit/informatik/command/ShowTrain.java | 10 +++ src/edu/kit/informatik/command/Step.java | 12 +++- 12 files changed, 165 insertions(+), 32 deletions(-) diff --git a/src/edu/kit/informatik/Coach.java b/src/edu/kit/informatik/Coach.java index cb5e397..e8ab561 100644 --- a/src/edu/kit/informatik/Coach.java +++ b/src/edu/kit/informatik/Coach.java @@ -1,10 +1,47 @@ package edu.kit.informatik; +/** + * A coach. + */ public class Coach extends RollingStock { + private static final String[] PASSENGER_TEXT = new String[] { + "____________________", + "| ___ ___ ___ ___ |", + "| |_| |_| |_| |_| |", + "|__________________|", + "|__________________|", + " (O) (O) " + }; + private static final String[] FREIGHT_TEXT = new String[] { + "| |", + "| |", + "| |", + "|__________________|", + " (O) (O) " + }; + private static final String[] SPECIAL_TEXT = new String[] { + " ____", + "/--------------| |", + "\\--------------| |", + " | | | |", + " _|_|__________| |", + "|_________________|", + " (O) (O) " + }; + private CoachType type; private int identifier; - public Coach(final int identifier, final CoachType type, final int length, final boolean couplingFront, final boolean couplingBack) { + /** + * Construct a new coach. + * @param identifier identifier to use + * @param type type of coach + * @param length length of coach + * @param couplingFront whether the coach should have a front coupling + * @param couplingBack whether the coach should have a back coupling + */ + public Coach(final int identifier, final CoachType type, final int length, + final boolean couplingFront, final boolean couplingBack) { this.identifier = identifier; this.type = type; super.length = length; @@ -36,31 +73,6 @@ public class Coach extends RollingStock { return type; } - private static final String[] PASSENGER_TEXT = new String[] { - "____________________", - "| ___ ___ ___ ___ |", - "| |_| |_| |_| |_| |", - "|__________________|", - "|__________________|", - " (O) (O) " - }; - private static final String[] FREIGHT_TEXT = new String[] { - "| |", - "| |", - "| |", - "|__________________|", - " (O) (O) " - }; - private static final String[] SPECIAL_TEXT = new String[] { - " ____", - "/--------------| |", - "\\--------------| |", - " | | | |", - " _|_|__________| |", - "|_________________|", - " (O) (O) " - }; - @Override public String[] textRepresentation() { switch (type) { diff --git a/src/edu/kit/informatik/CoachType.java b/src/edu/kit/informatik/CoachType.java index 317d75e..e084348 100644 --- a/src/edu/kit/informatik/CoachType.java +++ b/src/edu/kit/informatik/CoachType.java @@ -1,10 +1,30 @@ package edu.kit.informatik; +/** + * Type of a coach. + * + * @author Arne Keller + * @version 1.0 + */ public enum CoachType { + /** + * Passenger coach. + */ PASSENGER, + /** + * Freight coach. + */ FREIGHT, + /** + * Special coach used for e.g. firefighting. + */ SPECIAL; + /** + * Parse the textual representation of a coach type into the correct enum value. + * @param value coach type as text + * @return coach type as enum, or null if invalid + */ public static CoachType parse(String value) { switch (value) { case "passenger": diff --git a/src/edu/kit/informatik/EngineType.java b/src/edu/kit/informatik/EngineType.java index 9315555..8e9ddfe 100644 --- a/src/edu/kit/informatik/EngineType.java +++ b/src/edu/kit/informatik/EngineType.java @@ -2,6 +2,9 @@ package edu.kit.informatik; /** * Type of locomotive. Can be either diesel, steam or electrical. + * + * @author Arne Keller + * @version 1.0 */ public enum EngineType { /** @@ -17,6 +20,11 @@ public enum EngineType { */ ELECTRICAL; + /** + * Parse the textual representation of a engine type into the correct enum value. + * @param value engine type as text + * @return engine type as enum, or null if invalid + */ public static EngineType parse(String value) { switch (value) { case "diesel": diff --git a/src/edu/kit/informatik/Rail.java b/src/edu/kit/informatik/Rail.java index d346f15..d50998e 100644 --- a/src/edu/kit/informatik/Rail.java +++ b/src/edu/kit/informatik/Rail.java @@ -1,13 +1,31 @@ package edu.kit.informatik; +/** + * Generic rail that other rails can connect to. + */ public abstract class Rail { protected int id; public int getIdentifier() { return this.id; } + + /** + * @param point point to check for connection + * @return whether the rail currently connects to the point + */ public abstract boolean connectsTo(Point point); + + /** + * @param point point to check for connection + * @return whether the rail can connect to the point + */ public abstract boolean canConnectTo(Point point); + + /** + * @param rail rail to check for connection + * @return whether this rail can connect to the specified rail + */ public abstract boolean canConnectToRail(Rail rail); /** @@ -17,8 +35,15 @@ public abstract class Rail { */ public abstract boolean switchTo(Point position); + /** + * @return whether the rail is ready for trains running on it + */ public abstract boolean isReadyForTrains(); + /** + * @param position the point to check + * @return whether the point is inside this rail (not on the edge) + */ public abstract boolean contains(Point position); public abstract Point getDirectionFrom(Point position); diff --git a/src/edu/kit/informatik/command/ListEngines.java b/src/edu/kit/informatik/command/ListEngines.java index d2f6d38..302594b 100644 --- a/src/edu/kit/informatik/command/ListEngines.java +++ b/src/edu/kit/informatik/command/ListEngines.java @@ -2,9 +2,15 @@ package edu.kit.informatik.command; import edu.kit.informatik.ModelRailwaySimulation; +/** + * Command used to list engines. + * + * @author Arne Keller + * @version 1.0 + */ public class ListEngines extends Command { @Override - public void apply(ModelRailwaySimulation simulation) { + public void apply(final ModelRailwaySimulation simulation) { simulation.printEngines(); } } diff --git a/src/edu/kit/informatik/command/ListTracks.java b/src/edu/kit/informatik/command/ListTracks.java index 8fd2da1..98dbff9 100644 --- a/src/edu/kit/informatik/command/ListTracks.java +++ b/src/edu/kit/informatik/command/ListTracks.java @@ -2,9 +2,15 @@ package edu.kit.informatik.command; import edu.kit.informatik.ModelRailwaySimulation; +/** + * Command used to list tracks and switches. + * + * @author Arne Keller + * @version 1.0 + */ public class ListTracks extends Command { @Override - public void apply(ModelRailwaySimulation simulation) { + public void apply(final ModelRailwaySimulation simulation) { simulation.printTracks(); } } diff --git a/src/edu/kit/informatik/command/ListTrainSets.java b/src/edu/kit/informatik/command/ListTrainSets.java index 65d7c47..9cb6783 100644 --- a/src/edu/kit/informatik/command/ListTrainSets.java +++ b/src/edu/kit/informatik/command/ListTrainSets.java @@ -2,9 +2,15 @@ package edu.kit.informatik.command; import edu.kit.informatik.ModelRailwaySimulation; +/** + * Command used to list train sets. + * + * @author Arne Keller + * @version 1.0 + */ public class ListTrainSets extends Command { @Override - public void apply(ModelRailwaySimulation simulation) { + public void apply(final ModelRailwaySimulation simulation) { simulation.printTrainSets(); } } diff --git a/src/edu/kit/informatik/command/ListTrains.java b/src/edu/kit/informatik/command/ListTrains.java index 1ddb941..8bd08b5 100644 --- a/src/edu/kit/informatik/command/ListTrains.java +++ b/src/edu/kit/informatik/command/ListTrains.java @@ -2,9 +2,15 @@ package edu.kit.informatik.command; import edu.kit.informatik.ModelRailwaySimulation; +/** + * Command used to list trains. + * + * @author Arne Keller + * @version 1.0 + */ public class ListTrains extends Command { @Override - public void apply(ModelRailwaySimulation simulation) { + public void apply(final ModelRailwaySimulation simulation) { simulation.printTrains(); } } diff --git a/src/edu/kit/informatik/command/PutTrain.java b/src/edu/kit/informatik/command/PutTrain.java index d5e54ae..f0be681 100644 --- a/src/edu/kit/informatik/command/PutTrain.java +++ b/src/edu/kit/informatik/command/PutTrain.java @@ -4,12 +4,25 @@ import edu.kit.informatik.ModelRailwaySimulation; import edu.kit.informatik.Point; import edu.kit.informatik.Terminal; +/** + * Command used to put a train on the rail network. + * + * @author Arne Keller + * @version 1.0 + */ public class PutTrain extends Command { private final int id; private final Point point; private final int x; private final int y; + /** + * Construct a new 'put train' command. + * @param id identifier of the train + * @param point where to put the train + * @param x initial x direction + * @param y initial y direction + */ public PutTrain(final int id, final Point point, final int x, final int y) { this.id = id; this.point = point; @@ -18,7 +31,7 @@ public class PutTrain extends Command { } @Override - public void apply(ModelRailwaySimulation simulation) { + public void apply(final ModelRailwaySimulation simulation) { if (simulation.putTrain(id, point, new Point(x, y))) { Terminal.printLine("OK"); } else { diff --git a/src/edu/kit/informatik/command/SetSwitch.java b/src/edu/kit/informatik/command/SetSwitch.java index 8ee7672..1734724 100644 --- a/src/edu/kit/informatik/command/SetSwitch.java +++ b/src/edu/kit/informatik/command/SetSwitch.java @@ -4,10 +4,21 @@ import edu.kit.informatik.ModelRailwaySimulation; import edu.kit.informatik.Point; import edu.kit.informatik.Terminal; +/** + * Command used to set the position a switch is set to. + * + * @author Arne Keller + * @version 1.0 + */ public class SetSwitch extends Command { private final int id; private final Point point; + /** + * Construct a new 'set switch' command. + * @param id identifier of the switch + * @param point position to set the switch to + */ public SetSwitch(final int id, final Point point) { this.id = id; this.point = point; diff --git a/src/edu/kit/informatik/command/ShowTrain.java b/src/edu/kit/informatik/command/ShowTrain.java index 74141ab..e46b74f 100644 --- a/src/edu/kit/informatik/command/ShowTrain.java +++ b/src/edu/kit/informatik/command/ShowTrain.java @@ -2,9 +2,19 @@ package edu.kit.informatik.command; import edu.kit.informatik.ModelRailwaySimulation; +/** + * Command used to print a train as ASCII art. + * + * @author Arne Keller + * @version 1.0 + */ public class ShowTrain extends Command { private final int id; + /** + * Construct a new 'show train' command. + * @param id identifier of the train to show + */ public ShowTrain(final int id) { this.id = id; } diff --git a/src/edu/kit/informatik/command/Step.java b/src/edu/kit/informatik/command/Step.java index e8c20bd..b40c438 100644 --- a/src/edu/kit/informatik/command/Step.java +++ b/src/edu/kit/informatik/command/Step.java @@ -2,15 +2,25 @@ package edu.kit.informatik.command; import edu.kit.informatik.ModelRailwaySimulation; +/** + * Command used to run the simulation. + * + * @author Arne Keller + * @version 1.0 + */ public class Step extends Command { private final short speed; + /** + * Construct a new 'step' command. + * @param speed the amount of steps to perform + */ public Step(final short speed) { this.speed = speed; } @Override - public void apply(ModelRailwaySimulation simulation) { + public void apply(final ModelRailwaySimulation simulation) { simulation.step(speed); } }