From 4fd72ebe43c26f90e000d1396b06ed90a8dd1cbc Mon Sep 17 00:00:00 2001 From: Arne Keller Date: Sat, 7 Mar 2020 13:20:29 +0100 Subject: [PATCH] Checkstyle --- src/edu/kit/informatik/Main.java | 4 ++-- src/edu/kit/informatik/model/Coach.java | 18 +++++++++++---- .../kit/informatik/model/DieselEngine.java | 8 +++---- .../informatik/model/ElectricalEngine.java | 12 +++++----- src/edu/kit/informatik/model/Engine.java | 22 +++++++++++++++++- .../kit/informatik/model/FreightCoach.java | 13 ++++++----- .../model/ModelRailwaySimulation.java | 12 +++++++++- .../kit/informatik/model/PassengerCoach.java | 13 ++++++----- src/edu/kit/informatik/model/Rail.java | 4 +++- .../kit/informatik/model/RailwayNetwork.java | 23 ++++++++++++------- .../kit/informatik/model/RollingStock.java | 13 ++++++----- .../kit/informatik/model/SpecialCoach.java | 13 ++++++----- src/edu/kit/informatik/model/SteamEngine.java | 8 +++---- src/edu/kit/informatik/model/Switch.java | 20 +++++++++++++++- src/edu/kit/informatik/model/Train.java | 23 ++++++++++--------- .../kit/informatik/model/TrainManager.java | 14 +++++------ src/edu/kit/informatik/model/TrainSet.java | 3 ++- src/edu/kit/informatik/model/Vector2D.java | 7 ++++-- src/edu/kit/informatik/ui/CoachType.java | 1 + src/edu/kit/informatik/ui/CommandLine.java | 2 +- src/edu/kit/informatik/ui/EngineType.java | 1 + .../informatik/ui/InvalidInputException.java | 1 + .../kit/informatik/ui/command/Command.java | 2 ++ .../informatik/ui/command/CommandFactory.java | 11 +++++---- .../informatik/ui/command/CreateEngine.java | 2 +- .../informatik/ui/command/CreateTrainSet.java | 2 +- src/edu/kit/informatik/ui/command/Step.java | 6 ++--- 27 files changed, 170 insertions(+), 88 deletions(-) diff --git a/src/edu/kit/informatik/Main.java b/src/edu/kit/informatik/Main.java index 49fbcab..3b41b40 100644 --- a/src/edu/kit/informatik/Main.java +++ b/src/edu/kit/informatik/Main.java @@ -4,7 +4,7 @@ import edu.kit.informatik.ui.CommandLine; /** * The main class. - * + * * @author Arne Keller * @version 1.0 */ @@ -13,7 +13,7 @@ public final class Main { * Utility class -> private constructor. */ private Main() { - + } /** diff --git a/src/edu/kit/informatik/model/Coach.java b/src/edu/kit/informatik/model/Coach.java index c25af05..8064483 100644 --- a/src/edu/kit/informatik/model/Coach.java +++ b/src/edu/kit/informatik/model/Coach.java @@ -4,6 +4,8 @@ import edu.kit.informatik.ui.InvalidInputException; import java.util.regex.Pattern; +import static edu.kit.informatik.ui.command.CommandFactory.NUMBER; + /** * A coach. * @@ -16,21 +18,22 @@ public abstract class Coach extends RollingStock { */ public static final String IDENTIFIER_PREFIX = "W"; /** - * Regex pattern to match coach identifiers. + * Pattern to match a single coach identifier. */ - public static final Pattern IDENTIFIER_PATTERN = Pattern.compile(IDENTIFIER_PREFIX + "\\+?\\d+"); + public static final Pattern IDENTIFIER_PATTERN = Pattern.compile(IDENTIFIER_PREFIX + NUMBER); /** - * Regex pattern to match coach type (passenger, freight, or special). + * Pattern to match coach type (passenger, freight, or special). */ public static final String COACH_TYPE = "passenger|freight|special"; /** - * The unique identifier of this coach. + * The (unique) identifier of this coach. */ private final int identifier; /** * Construct a new coach. + * * @param identifier identifier to use * @param length length of coach * @param couplingFront whether the coach should have a front coupling @@ -42,6 +45,11 @@ public abstract class Coach extends RollingStock { this.identifier = identifier; } + /** + * Get the textual identifier of this coach in this format: [PREFIX][NUMERICAL_IDENTIFIER]. + * + * @return the textual identifier of this coach + */ @Override public String getIdentifier() { return String.format("%s%d", IDENTIFIER_PREFIX, identifier); @@ -70,6 +78,8 @@ public abstract class Coach extends RollingStock { } /** + * Get the type of this coach ("p" for passenger, "f" for freight, "s" for special). + * * @return abbreviation of the type of this coach */ public abstract String getType(); diff --git a/src/edu/kit/informatik/model/DieselEngine.java b/src/edu/kit/informatik/model/DieselEngine.java index 806fdc5..8e8cf9a 100644 --- a/src/edu/kit/informatik/model/DieselEngine.java +++ b/src/edu/kit/informatik/model/DieselEngine.java @@ -12,7 +12,7 @@ public class DieselEngine extends Engine { /** * ASCII art representation of a diesel engine. */ - private static final String[] DIESEL_ENGINE_TEXT = new String[] { + private static final String[] DIESEL_ENGINE_TEXT = new String[]{ " _____________|____ ", " /_| ____________ |_\\ ", "/ |____________| \\", @@ -23,6 +23,7 @@ public class DieselEngine extends Engine { /** * Construct a new diesel engine. + * * @param series series/class of engine * @param name name of engine * @param length length of engine @@ -36,9 +37,8 @@ public class DieselEngine extends Engine { } @Override - public String toString() { - return String.format("d %s %s %d %b %b", getSeries(), getName(), getLength(), - hasCouplingFront(), hasCouplingBack()); + public String getType() { + return "d"; } @Override diff --git a/src/edu/kit/informatik/model/ElectricalEngine.java b/src/edu/kit/informatik/model/ElectricalEngine.java index 52d7da1..88fbcd9 100644 --- a/src/edu/kit/informatik/model/ElectricalEngine.java +++ b/src/edu/kit/informatik/model/ElectricalEngine.java @@ -12,7 +12,7 @@ public class ElectricalEngine extends Engine { /** * ASCII art of an electrical engine. */ - private static final String[] ELECTRICAL_ENGINE_TEXT = new String[] { + private static final String[] ELECTRICAL_ENGINE_TEXT = new String[]{ " ___ ", " \\ ", " _______________/__ ", @@ -25,6 +25,7 @@ public class ElectricalEngine extends Engine { /** * Construct a new electrical engine. + * * @param series series/class of engine * @param name name of engine * @param length length of engine @@ -32,15 +33,14 @@ public class ElectricalEngine extends Engine { * @param couplingBack whether the engine should have a back coupling * @throws InvalidInputException on invalid user input (e.g. zero-sized engine) */ - public ElectricalEngine(String series, String name, int length, - boolean couplingFront, boolean couplingBack) throws InvalidInputException { + public ElectricalEngine(String series, String name, int length, boolean couplingFront, boolean couplingBack) + throws InvalidInputException { super(series, name, length, couplingFront, couplingBack); } @Override - public String toString() { - return String.format("e %s %s %d %b %b", getSeries(), getName(), getLength(), - hasCouplingFront(), hasCouplingBack()); + public String getType() { + return "e"; } @Override diff --git a/src/edu/kit/informatik/model/Engine.java b/src/edu/kit/informatik/model/Engine.java index 11aba84..4fd1b5e 100644 --- a/src/edu/kit/informatik/model/Engine.java +++ b/src/edu/kit/informatik/model/Engine.java @@ -20,6 +20,7 @@ public abstract class Engine extends RollingStock { /** * Initialize an engine. + * * @param series series/class of this engine * @param name name of this engine * @param length length of this engine @@ -27,7 +28,7 @@ public abstract class Engine extends RollingStock { * @param couplingBack whether this engine should have a back coupling * @throws InvalidInputException on invalid user input (zero-sized coach) */ - protected Engine(String series, String name, int length, + protected Engine(String series, String name, int length, boolean couplingFront, boolean couplingBack) throws InvalidInputException { super(length, couplingFront, couplingBack); this.series = series; @@ -67,4 +68,23 @@ public abstract class Engine extends RollingStock { public boolean usefulAtBackOfTrain() { return true; } + + /** + * Get the type of this engine ("s" for steam, "d" for diesel, "e" for electrical). + * + * @return abbreviation of the type of this engine + */ + public abstract String getType(); + + /** + * Get the textual representation of this engine in the format: + * [type] [series] [name] [length] [couplingFront] [couplingBack] + * + * @return textual representation of the engine + */ + @Override + public String toString() { + return String.format("%s %s %s %d %b %b", getType(), getSeries(), getName(), getLength(), + hasCouplingFront(), hasCouplingBack()); + } } diff --git a/src/edu/kit/informatik/model/FreightCoach.java b/src/edu/kit/informatik/model/FreightCoach.java index efc3fe5..07475c1 100644 --- a/src/edu/kit/informatik/model/FreightCoach.java +++ b/src/edu/kit/informatik/model/FreightCoach.java @@ -4,7 +4,7 @@ import edu.kit.informatik.ui.InvalidInputException; /** * A freight coach. - * + * * @author Arne Keller * @version 1.0 */ @@ -12,7 +12,7 @@ public class FreightCoach extends Coach { /** * ASCII art representation of a freight coach. */ - private static final String[] FREIGHT_TEXT = new String[] { + private static final String[] FREIGHT_TEXT = new String[]{ "| |", "| |", "| |", @@ -22,11 +22,12 @@ public class FreightCoach extends Coach { /** * Construct a new freight coach. - * @param identifier identifier to use - * @param length length of coach + * + * @param identifier identifier to use + * @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 - * @throws InvalidInputException on invalid user input (zero-sized coach) + * @param couplingBack whether the coach should have a back coupling + * @throws InvalidInputException on invalid user input (e.g. zero-sized coach) */ public FreightCoach(int identifier, int length, boolean couplingFront, boolean couplingBack) throws InvalidInputException { diff --git a/src/edu/kit/informatik/model/ModelRailwaySimulation.java b/src/edu/kit/informatik/model/ModelRailwaySimulation.java index 5fc5e2b..61f5a3a 100644 --- a/src/edu/kit/informatik/model/ModelRailwaySimulation.java +++ b/src/edu/kit/informatik/model/ModelRailwaySimulation.java @@ -45,6 +45,7 @@ public class ModelRailwaySimulation { /** * Add a new track to the rail network of this simulation. + * * @param start start position of the new track * @param end end position of the new track * @return the positive identifier of the new track if successful, -1 if none available @@ -56,6 +57,7 @@ public class ModelRailwaySimulation { /** * Add a switch to the rail network of this simulation. + * * @param start start point of the switch * @param end1 end position 1 of the switch * @param end2 end position 2 of the switch @@ -90,6 +92,7 @@ public class ModelRailwaySimulation { /** * Change the setting of a switch in the rail network. + * * @param id identifier of the switch * @param position position to set the switch to * @return whether the switch could be set @@ -132,6 +135,7 @@ public class ModelRailwaySimulation { /** * Add a new coach to the simulation. + * * @param coachType type of the coach * @param length length of the coach * @param couplingFront whether the coach should have a front coupling @@ -163,6 +167,7 @@ public class ModelRailwaySimulation { /** * Calculate the next coach identifier. + * * @return the next coach identifier, or -1 if none available */ private int getNextCoachIdentifier() { @@ -172,7 +177,7 @@ public class ModelRailwaySimulation { /** * Get a list of coaches (their text representation) added to the simulation. - * + * * @return list of coaches (never null, sometimes empty) */ public List listCoaches() { @@ -189,6 +194,7 @@ public class ModelRailwaySimulation { /** * Add a new train set to the simulation. + * * @param newTrainSet the train set to add * @throws InvalidInputException if the identifier is already used */ @@ -218,6 +224,7 @@ public class ModelRailwaySimulation { /** * Delete a rolling stock. + * * @param id identifier of the rolling stock to remove * @return whether the rolling was successfully removed */ @@ -270,6 +277,7 @@ public class ModelRailwaySimulation { /** * Delete a train. + * * @param id identifier of the train * @return whether the train could be deleted */ @@ -298,6 +306,7 @@ public class ModelRailwaySimulation { /** * Get the ASCII art representation of a train. + * * @param id identifier of the train to show * @return rows of ASCII art representing this train * @throws InvalidInputException if train not found @@ -308,6 +317,7 @@ public class ModelRailwaySimulation { /** * Put a train on the rail network. + * * @param trainId identifier of the train to place * @param position where to place the train * @param direction direction in which the train should initially go diff --git a/src/edu/kit/informatik/model/PassengerCoach.java b/src/edu/kit/informatik/model/PassengerCoach.java index 82f1c17..408f53f 100644 --- a/src/edu/kit/informatik/model/PassengerCoach.java +++ b/src/edu/kit/informatik/model/PassengerCoach.java @@ -4,7 +4,7 @@ import edu.kit.informatik.ui.InvalidInputException; /** * A passenger coach. - * + * * @author Arne Keller * @version 1.0 */ @@ -12,7 +12,7 @@ public class PassengerCoach extends Coach { /** * ASCII art representation of a passenger coach. */ - private static final String[] PASSENGER_TEXT = new String[] { + private static final String[] PASSENGER_TEXT = new String[]{ "____________________", "| ___ ___ ___ ___ |", "| |_| |_| |_| |_| |", @@ -23,11 +23,12 @@ public class PassengerCoach extends Coach { /** * Construct a new passenger coach. - * @param identifier identifier to use - * @param length length of coach + * + * @param identifier identifier to use + * @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 - * @throws InvalidInputException on invalid user input (zero-sized coach) + * @param couplingBack whether the coach should have a back coupling + * @throws InvalidInputException on invalid user input (e.g. zero-sized coach) */ public PassengerCoach(int identifier, int length, boolean couplingFront, boolean couplingBack) throws InvalidInputException { diff --git a/src/edu/kit/informatik/model/Rail.java b/src/edu/kit/informatik/model/Rail.java index e065d65..6a70bfd 100644 --- a/src/edu/kit/informatik/model/Rail.java +++ b/src/edu/kit/informatik/model/Rail.java @@ -14,6 +14,7 @@ public abstract class Rail { /** * Initialize a new rail with the specified identifier. + * * @param id the identifier of this rail */ protected Rail(int id) { @@ -47,7 +48,7 @@ public abstract class Rail { public abstract boolean canConnectTo(Vector2D point); /** - * @param rail rail to check for connection + * @param rail rail to check for possible connection * @return whether this rail can connect to the specified rail */ public abstract boolean canConnectToRail(Rail rail); @@ -60,6 +61,7 @@ public abstract class Rail { /** * Try to set the rail to connect to this position. Obviously only makes sense for switches and similar rails. + * * @param position point to connect to * @return whether rail could be successfully set */ diff --git a/src/edu/kit/informatik/model/RailwayNetwork.java b/src/edu/kit/informatik/model/RailwayNetwork.java index 5ce9a99..5f0dde2 100644 --- a/src/edu/kit/informatik/model/RailwayNetwork.java +++ b/src/edu/kit/informatik/model/RailwayNetwork.java @@ -27,6 +27,7 @@ public class RailwayNetwork { /** * Add a new track to the rail network. + * * @param start start position of the new track * @param end end position of the new track * @return the positive identifier of the new track if successful, -1 if none available @@ -63,6 +64,7 @@ public class RailwayNetwork { /** * Add a switch to the rail network. + * * @param start start point of the switch * @param end1 end position 1 of the switch * @param end2 end position 2 of the switch @@ -101,6 +103,7 @@ public class RailwayNetwork { /** * Get the rail with the specified identifier. + * * @param id rail identifier to get * @return the rail */ @@ -110,6 +113,7 @@ public class RailwayNetwork { /** * Remove the specified rail from the rail network. + * * @param id identifier of the rail to remove * @return whether the rail could be successfully removed */ @@ -162,6 +166,7 @@ public class RailwayNetwork { /** * Change the setting of a switch in the rail network. + * * @param id identifier of the switch * @param position position to set the switch to * @return whether the switch could be set @@ -215,13 +220,13 @@ public class RailwayNetwork { final Vector2D onRailOne = touchingRails[0].move(position, new Vector2D(direction), steps); final Vector2D onRailTwo = touchingRails[1].move(position, new Vector2D(direction), steps); if (position.equals(onRailOne) || onRailOne == null - || onRailTwo != null && onRailTwo.subtract(position).directionEquals(direction)) { + || onRailTwo != null && onRailTwo.subtract(position).directionEquals(direction)) { // we are moving on rail two final Vector2D newDirection = touchingRails[1].getDirectionFrom(position); direction.copyFrom(newDirection); return onRailTwo; } else if (position.equals(onRailTwo) || onRailTwo == null - || onRailOne.subtract(position).directionEquals(direction)) { + || onRailOne.subtract(position).directionEquals(direction)) { final Vector2D newDirection = touchingRails[0].getDirectionFrom(position); direction.copyFrom(newDirection); return onRailOne; @@ -245,16 +250,16 @@ public class RailwayNetwork { final Rail[] touchingRails = findTouchingRails(position); if (touchingRails.length == 0) { return findContainingRail(position) - .map(rail -> rail.allowsPlacement(position, direction)) - .orElse(false); // containing rail is orthogonal to the requested direction + .map(rail -> rail.allowsPlacement(position, direction)) + .orElse(false); // containing rail is orthogonal to the requested direction } else if (touchingRails.length == 1) { // rail should not be orthogonal to the requested direction return touchingRails[0].allowsPlacement(position, direction) - || touchingRails[0].allowsMovement(position, direction); + || touchingRails[0].allowsMovement(position, direction); } else if (!touchingRails[0].allowsPlacement(position, direction) - && !touchingRails[1].allowsPlacement(position, direction) - && !(touchingRails[0].allowsMovement(position, direction) - || touchingRails[1].allowsMovement(position, direction))) { + && !touchingRails[1].allowsPlacement(position, direction) + && !(touchingRails[0].allowsMovement(position, direction) + || touchingRails[1].allowsMovement(position, direction))) { // rail network does not allow this direction according to // https://ilias.studium.kit.edu/goto.php?client_id=produktiv&target=frm_996924_139143_534378 return false; @@ -288,6 +293,7 @@ public class RailwayNetwork { /** * Find all rails that *touch* (not contain) this position. + * * @param position the position to check * @return the rail(s) that touch this position */ @@ -297,6 +303,7 @@ public class RailwayNetwork { /** * Check whether the rail network is ready for trains (all switches set, etc.). + * * @return whether the rail network is ready */ public boolean isReadyForTrains() { diff --git a/src/edu/kit/informatik/model/RollingStock.java b/src/edu/kit/informatik/model/RollingStock.java index 125846b..9c908fc 100644 --- a/src/edu/kit/informatik/model/RollingStock.java +++ b/src/edu/kit/informatik/model/RollingStock.java @@ -4,7 +4,7 @@ import edu.kit.informatik.ui.InvalidInputException; /** * A rolling stock with a specific integer length and couplings. Is usually an engine, train set or coach. - * + * * @author Arne Keller * @version 1.0 */ @@ -24,7 +24,7 @@ public abstract class RollingStock { /** * Initialize a rolling stock. - * + * * @param length length of this rolling stock * @param couplingFront whether this rolling stock should have a front coupling * @param couplingBack whether this rolling stock should have a back coupling @@ -43,8 +43,6 @@ public abstract class RollingStock { } /** - * Get the identifier of this rolling stock. - * * @return identifier of this rolling stock */ public abstract String getIdentifier(); @@ -71,18 +69,21 @@ public abstract class RollingStock { } /** + * Check whether this rolling stock can theoretically couple to another rolling stock. This method will not check + * whether the other rolling stock has special coupling requirements. + * * @param rollingStock other rolling stock * @return whether this rolling stock can couple to the other rolling stock */ public abstract boolean canCoupleTo(RollingStock rollingStock); /** - * @return whether this rolling stock is useful at the front end of a train + * @return whether this rolling stock is useful at the front of a train */ public abstract boolean usefulAtFrontOfTrain(); /** - * @return whether this rolling stock is useful at the rear end of a train + * @return whether this rolling stock is useful at the back of a train */ public abstract boolean usefulAtBackOfTrain(); diff --git a/src/edu/kit/informatik/model/SpecialCoach.java b/src/edu/kit/informatik/model/SpecialCoach.java index 53815f0..69cf62d 100644 --- a/src/edu/kit/informatik/model/SpecialCoach.java +++ b/src/edu/kit/informatik/model/SpecialCoach.java @@ -4,7 +4,7 @@ import edu.kit.informatik.ui.InvalidInputException; /** * A special coach, used for e.g. firefighting. - * + * * @author Arne Keller * @version 1.0 */ @@ -12,7 +12,7 @@ public class SpecialCoach extends Coach { /** * ASCII art representation of a special coach. */ - private static final String[] SPECIAL_TEXT = new String[] { + private static final String[] SPECIAL_TEXT = new String[]{ " ____", "/--------------| |", "\\--------------| |", @@ -24,11 +24,12 @@ public class SpecialCoach extends Coach { /** * Construct a new special coach. - * @param identifier identifier to use - * @param length length of coach + * + * @param identifier identifier to use + * @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 - * @throws InvalidInputException on invalid user input (zero-sized coach) + * @param couplingBack whether the coach should have a back coupling + * @throws InvalidInputException on invalid user input (e.g. zero-sized coach) */ public SpecialCoach(int identifier, int length, boolean couplingFront, boolean couplingBack) throws InvalidInputException { diff --git a/src/edu/kit/informatik/model/SteamEngine.java b/src/edu/kit/informatik/model/SteamEngine.java index fd1bb0d..cc780c6 100644 --- a/src/edu/kit/informatik/model/SteamEngine.java +++ b/src/edu/kit/informatik/model/SteamEngine.java @@ -12,7 +12,7 @@ public class SteamEngine extends Engine { /** * ASCII art representation of a steam engine. */ - private static final String[] STEAM_ENGINE_TEXT = new String[] { + private static final String[] STEAM_ENGINE_TEXT = new String[]{ " ++ +------", " || |+-+ | ", " /---------|| | | ", @@ -23,6 +23,7 @@ public class SteamEngine extends Engine { /** * Construct a new steam engine. + * * @param series series/class of engine * @param name name of engine * @param length length of engine @@ -36,9 +37,8 @@ public class SteamEngine extends Engine { } @Override - public String toString() { - return String.format("s %s %s %d %b %b", getSeries(), getName(), getLength(), - hasCouplingFront(), hasCouplingBack()); + public String getType() { + return "s"; } @Override diff --git a/src/edu/kit/informatik/model/Switch.java b/src/edu/kit/informatik/model/Switch.java index f92f836..53c8b7c 100644 --- a/src/edu/kit/informatik/model/Switch.java +++ b/src/edu/kit/informatik/model/Switch.java @@ -20,7 +20,7 @@ public final class Switch extends Rail { */ private final Track positionTwo; /** - * Currently selected position (either one or two). + * Currently selected position (either {@link #positionOne} or {@link #positionTwo}). */ private Track selection; @@ -44,11 +44,19 @@ public final class Switch extends Rail { return positionOne.canConnectTo(point) || positionTwo.canConnectTo(point); } + /** + * @param point point to check for connection + * @return whether the currently active configuration connects to the position + */ @Override public boolean connectsTo(Vector2D point) { return selection != null && selection.canConnectTo(point); } + /** + * @param rail rail to check for possible connection + * @return whether any of the configurations can connect to the position + */ @Override public boolean canConnectToRail(Rail rail) { return rail.canConnectToRail(positionOne) || rail.canConnectToRail(positionTwo); @@ -66,11 +74,18 @@ public final class Switch extends Rail { return false; } + /** + * @return whether this switch is set + */ @Override public boolean isReadyForTrains() { return selection != null; } + /** + * @param position the point to check + * @return whether the active switch configuration contains that position + */ @Override public boolean contains(Vector2D position) { return selection != null && selection.contains(position); @@ -101,6 +116,9 @@ public final class Switch extends Rail { || positionTwo.allowsMovement(position, direction); } + /** + * @return length of the current configuration + */ @Override public long getLength() { return selection.getLength(); diff --git a/src/edu/kit/informatik/model/Train.java b/src/edu/kit/informatik/model/Train.java index 3212324..0f5f91b 100644 --- a/src/edu/kit/informatik/model/Train.java +++ b/src/edu/kit/informatik/model/Train.java @@ -33,7 +33,7 @@ public final class Train implements Comparable { /** * List of positions this train occupies. More specifically, it only contains: * the position of the front of the train, any positions on rail connections, the position of the back of the train - * + *

* This is a linked list because we only have to update * the positions at the start and end of the list when moving the train. */ @@ -71,6 +71,7 @@ public final class Train implements Comparable { /** * Add a rolling stock to this train. + * * @param rollingStock the rolling stack to add * @throws InvalidInputException if the rolling stock could not be added to the train */ @@ -92,7 +93,7 @@ public final class Train implements Comparable { */ public boolean isOnRail(Rail rail) { return isPlaced() - && (occupiedRails.stream().anyMatch(blockedRail -> blockedRail == rail) + && (occupiedRails.stream().anyMatch(blockedRail -> blockedRail == rail) || positions.stream().anyMatch(rail::canConnectTo)); } @@ -228,7 +229,7 @@ public final class Train implements Comparable { positions.getLast().subtractInPlace(getRearDirection()); if (positions.getLast().equals(positions.get(positions.size() - 2))) { if (!railNetwork.findContainingRail(nextPosition).equals(railUnderBackOfTrain) - || nextPosition == null) { + || nextPosition == null) { occupiedRails.remove(railUnderBackOfTrain.orElse(null)); } positions.removeLast(); @@ -254,7 +255,7 @@ public final class Train implements Comparable { positions.getFirst().subtractInPlace(getDirection()); if (positions.getFirst().equals(positions.get(1))) { if (!railNetwork.findContainingRail(backPosition).equals(railUnderFrontOfTrain) - || backPosition == null) { + || backPosition == null) { occupiedRails.remove(railUnderFrontOfTrain.orElse(null)); } positions.removeFirst(); @@ -274,16 +275,16 @@ public final class Train implements Comparable { */ private void simplifyPositions(RailwayNetwork railNetwork) { if (positions.size() >= 3 - && positions.getFirst().subtract(positions.get(1)).normalized() - .equals(positions.get(1).subtract(positions.get(2)).normalized()) - && railNetwork.findTouchingRails(positions.get(1)).length == 0) { + && positions.getFirst().subtract(positions.get(1)).normalized() + .equals(positions.get(1).subtract(positions.get(2)).normalized()) + && railNetwork.findTouchingRails(positions.get(1)).length == 0) { positions.remove(1); } if (positions.size() >= 3 - && positions.getLast().subtract(positions.get(positions.size() - 2)).normalized() - .equals(positions.get(positions.size() - 2) - .subtract(positions.get(positions.size() - 3)).normalized()) - && railNetwork.findTouchingRails(positions.get(positions.size() - 2)).length == 0) { + && positions.getLast().subtract(positions.get(positions.size() - 2)).normalized() + .equals(positions.get(positions.size() - 2) + .subtract(positions.get(positions.size() - 3)).normalized()) + && railNetwork.findTouchingRails(positions.get(positions.size() - 2)).length == 0) { positions.remove(positions.size() - 2); } } diff --git a/src/edu/kit/informatik/model/TrainManager.java b/src/edu/kit/informatik/model/TrainManager.java index 0076d8b..6fb2136 100644 --- a/src/edu/kit/informatik/model/TrainManager.java +++ b/src/edu/kit/informatik/model/TrainManager.java @@ -21,7 +21,7 @@ import java.util.stream.Stream; /** * Train manager, used for processing train placements and movement on a rail network. - * + * * @author Arne Keller * @version 1.0 */ @@ -108,7 +108,7 @@ public final class TrainManager { */ private int getNextTrainIdentifier() { return IntStream.rangeClosed(1, Integer.MAX_VALUE) - .filter(id -> !trains.containsKey(id)).findFirst().orElse(-1); + .filter(id -> !trains.containsKey(id)).findFirst().orElse(-1); } /** @@ -236,7 +236,7 @@ public final class TrainManager { occupiedByTrain2.retainAll(occupiedByTrain1); if (!occupiedByTrain2.isEmpty()) { final SortedSet collision - = Stream.of(train1, train2).collect(Collectors.toCollection(TreeSet::new)); + = Stream.of(train1, train2).collect(Collectors.toCollection(TreeSet::new)); addToSetOrAddNew(collisions, collision); } })); @@ -348,9 +348,9 @@ public final class TrainManager { .mapToObj(step -> speed >= 0 ? getCollisionsOfOneStep() : getCollisionsOfOneReverseStep()) // replace train references with identifiers to prevent modification by caller .flatMap(collisions -> collisions.stream() - .map(collision -> collision.stream().map(Train::getIdentifier) - .collect(Collectors.toCollection(TreeSet::new)))) - .sorted(Comparator.comparing(TreeSet::first)) - .collect(Collectors.toList()); + .map(collision -> collision.stream().map(Train::getIdentifier) + .collect(Collectors.toCollection(TreeSet::new)))) + .sorted(Comparator.comparing(TreeSet::first)) + .collect(Collectors.toList()); } } diff --git a/src/edu/kit/informatik/model/TrainSet.java b/src/edu/kit/informatik/model/TrainSet.java index e610e75..9ea03de 100644 --- a/src/edu/kit/informatik/model/TrainSet.java +++ b/src/edu/kit/informatik/model/TrainSet.java @@ -12,7 +12,7 @@ public class TrainSet extends RollingStock { /** * ASCII art representation of a train set. */ - private static final String[] TRAIN_SET_TEXT = new String[] { + private static final String[] TRAIN_SET_TEXT = new String[]{ " ++ ", " || ", "_________||_________", @@ -34,6 +34,7 @@ public class TrainSet extends RollingStock { /** * Construct a new train set. + * * @param series series/class of train set * @param name name of train set * @param length length of train set diff --git a/src/edu/kit/informatik/model/Vector2D.java b/src/edu/kit/informatik/model/Vector2D.java index 854bfa9..cdafef3 100644 --- a/src/edu/kit/informatik/model/Vector2D.java +++ b/src/edu/kit/informatik/model/Vector2D.java @@ -20,6 +20,7 @@ public class Vector2D { /** * Construct a new vector. + * * @param x first component * @param y second component */ @@ -30,6 +31,7 @@ public class Vector2D { /** * Copy a vector, creating a new object. + * * @param other a vector */ public Vector2D(Vector2D other) { @@ -93,7 +95,7 @@ public class Vector2D { */ public boolean directionEquals(Vector2D other) { return x == 0 && x == other.x && Long.signum(y) == Long.signum(other.y) - || y == 0 && y == other.y && Long.signum(x) == Long.signum(other.x); + || y == 0 && y == other.y && Long.signum(x) == Long.signum(other.x); } @@ -115,7 +117,7 @@ public class Vector2D { } /** - * @return (-1) * this vector + * @return (- 1) * this vector */ public Vector2D negated() { return new Vector2D(-x, -y); @@ -123,6 +125,7 @@ public class Vector2D { /** * Subtract another vector from this one. + * * @param other another vector * @return the difference of this vector and the other vector */ diff --git a/src/edu/kit/informatik/ui/CoachType.java b/src/edu/kit/informatik/ui/CoachType.java index 17e846a..9c1d99e 100644 --- a/src/edu/kit/informatik/ui/CoachType.java +++ b/src/edu/kit/informatik/ui/CoachType.java @@ -22,6 +22,7 @@ public enum CoachType { /** * 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 */ diff --git a/src/edu/kit/informatik/ui/CommandLine.java b/src/edu/kit/informatik/ui/CommandLine.java index 46540ac..67ee8c7 100644 --- a/src/edu/kit/informatik/ui/CommandLine.java +++ b/src/edu/kit/informatik/ui/CommandLine.java @@ -25,7 +25,7 @@ public final class CommandLine { * Utility class -> private constructor. */ private CommandLine() { - + } /** diff --git a/src/edu/kit/informatik/ui/EngineType.java b/src/edu/kit/informatik/ui/EngineType.java index 2bdc623..54ff399 100644 --- a/src/edu/kit/informatik/ui/EngineType.java +++ b/src/edu/kit/informatik/ui/EngineType.java @@ -22,6 +22,7 @@ public enum EngineType { /** * 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 */ diff --git a/src/edu/kit/informatik/ui/InvalidInputException.java b/src/edu/kit/informatik/ui/InvalidInputException.java index 96a8b53..13d1e20 100644 --- a/src/edu/kit/informatik/ui/InvalidInputException.java +++ b/src/edu/kit/informatik/ui/InvalidInputException.java @@ -9,6 +9,7 @@ package edu.kit.informatik.ui; public class InvalidInputException extends Exception { /** * Construct a new invalid input exception with a specific message. + * * @param message the error message */ public InvalidInputException(String message) { diff --git a/src/edu/kit/informatik/ui/command/Command.java b/src/edu/kit/informatik/ui/command/Command.java index 0fd3159..44c8389 100644 --- a/src/edu/kit/informatik/ui/command/Command.java +++ b/src/edu/kit/informatik/ui/command/Command.java @@ -13,6 +13,7 @@ import edu.kit.informatik.ui.InvalidInputException; public abstract class Command { /** * Apply this command to a model railway simulation. + * * @param simulation simulation to use * @throws InvalidInputException on invalid user input */ @@ -20,6 +21,7 @@ public abstract class Command { /** * Parse user input into this command object. + * * @param input one line of user input * @throws InvalidInputException if user input is in any way invalid */ diff --git a/src/edu/kit/informatik/ui/command/CommandFactory.java b/src/edu/kit/informatik/ui/command/CommandFactory.java index dccf4df..071bc3e 100644 --- a/src/edu/kit/informatik/ui/command/CommandFactory.java +++ b/src/edu/kit/informatik/ui/command/CommandFactory.java @@ -14,6 +14,10 @@ import java.util.function.Supplier; * @version 1.0 */ public final class CommandFactory { + /** + * Regex to accept one boolean (true or false). + */ + public static final String BOOL = "true|false"; /** * Regex to match a number, accepting leading plus sign and zeros. */ @@ -31,10 +35,6 @@ public final class CommandFactory { */ public static final String ROLLING_STOCK_IDENTIFIER = "(" + ALPHANUMERIC_WORD + "-" + ALPHANUMERIC_WORD + ")|" + Coach.IDENTIFIER_PATTERN; - /** - * Regex to accept one boolean (true or false). - */ - public static final String BOOL = "true|false"; /** * Name of the add track command. @@ -137,11 +137,12 @@ public final class CommandFactory { * Utility class -> private constructor. */ private CommandFactory() { - + } /** * Parse a single line of user input into one command. + * * @param input user input line * @return a fully specified command object * @throws InvalidInputException if user input is invalid diff --git a/src/edu/kit/informatik/ui/command/CreateEngine.java b/src/edu/kit/informatik/ui/command/CreateEngine.java index 4351151..9a43ae8 100644 --- a/src/edu/kit/informatik/ui/command/CreateEngine.java +++ b/src/edu/kit/informatik/ui/command/CreateEngine.java @@ -26,7 +26,7 @@ import static edu.kit.informatik.ui.command.CommandFactory.NUMBER; */ public class CreateEngine extends Command { private static final Pattern CREATE_ENGINE_ARGUMENTS - = Pattern.compile(" (electrical|diesel|steam) (" + ALPHANUMERIC_WORD + ") (" + ALPHANUMERIC_WORD + ") (" + = Pattern.compile(" (electrical|diesel|steam) (" + ALPHANUMERIC_WORD + ") (" + ALPHANUMERIC_WORD + ") (" + NUMBER + ") (" + BOOL + ") (" + BOOL + ")"); /** diff --git a/src/edu/kit/informatik/ui/command/CreateTrainSet.java b/src/edu/kit/informatik/ui/command/CreateTrainSet.java index 57cb818..084114b 100644 --- a/src/edu/kit/informatik/ui/command/CreateTrainSet.java +++ b/src/edu/kit/informatik/ui/command/CreateTrainSet.java @@ -22,7 +22,7 @@ import static edu.kit.informatik.ui.command.CommandFactory.NUMBER; */ public class CreateTrainSet extends Command { private static final Pattern CREATE_TRAIN_SET_ARGUMENTS - = Pattern.compile(" (" + ALPHANUMERIC_WORD + ") (" + ALPHANUMERIC_WORD + ") (" + = Pattern.compile(" (" + ALPHANUMERIC_WORD + ") (" + ALPHANUMERIC_WORD + ") (" + NUMBER + ") (" + BOOL + ") (" + BOOL + ")"); /** diff --git a/src/edu/kit/informatik/ui/command/Step.java b/src/edu/kit/informatik/ui/command/Step.java index 1f5673d..22b6ef5 100644 --- a/src/edu/kit/informatik/ui/command/Step.java +++ b/src/edu/kit/informatik/ui/command/Step.java @@ -32,11 +32,11 @@ public class Step extends Command { } else { for (final int id : simulation.getTrains().keySet()) { final SortedSet collisionSet = collisions.stream() - .filter(collision -> collision.first() == id) - .findFirst().orElse(null); + .filter(collision -> collision.first() == id) + .findFirst().orElse(null); if (collisionSet != null) { // print collision Terminal.printLine("Crash of train " + String.join(",", - collisionSet.stream().map(Object::toString).toArray(String[]::new))); + collisionSet.stream().map(Object::toString).toArray(String[]::new))); } else { // or position, if not in collision final Vector2D position = simulation.getTrainPosition(id); if (position != null) { // only print placed trains