diff --git a/src/edu/kit/informatik/Main.java b/src/edu/kit/informatik/Main.java index d3b16c5..49fbcab 100644 --- a/src/edu/kit/informatik/Main.java +++ b/src/edu/kit/informatik/Main.java @@ -18,6 +18,7 @@ public final class Main { /** * Program entry point. + * * @param args command-line arguments */ public static void main(String[] args) { diff --git a/src/edu/kit/informatik/MainTest.java b/src/edu/kit/informatik/MainTest.java index 9d100b5..67061cb 100644 --- a/src/edu/kit/informatik/MainTest.java +++ b/src/edu/kit/informatik/MainTest.java @@ -7,6 +7,7 @@ import java.nio.file.Files; import static org.junit.jupiter.api.Assertions.*; +@SuppressWarnings("ALL") class MainTest { @Test void basics() throws IOException { diff --git a/src/edu/kit/informatik/Terminal.java b/src/edu/kit/informatik/Terminal.java index eac6c3a..de2d024 100644 --- a/src/edu/kit/informatik/Terminal.java +++ b/src/edu/kit/informatik/Terminal.java @@ -17,6 +17,7 @@ import java.io.InputStreamReader; * @author IPD, SDQ Group * @version 5.03, 2016/05/07 */ +@SuppressWarnings("ALL") public final class Terminal { /** diff --git a/src/edu/kit/informatik/model/Rail.java b/src/edu/kit/informatik/model/Rail.java index f3b0a73..e065d65 100644 --- a/src/edu/kit/informatik/model/Rail.java +++ b/src/edu/kit/informatik/model/Rail.java @@ -58,12 +58,6 @@ public abstract class Rail { */ public abstract boolean contains(Vector2D position); - /** - * @param position the point to check - * @return whether the point can be inside this rail (not on the edge) - */ - public abstract boolean canContain(Vector2D position); - /** * 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 diff --git a/src/edu/kit/informatik/model/RailwayNetwork.java b/src/edu/kit/informatik/model/RailwayNetwork.java index b1fb5d3..5ce9a99 100644 --- a/src/edu/kit/informatik/model/RailwayNetwork.java +++ b/src/edu/kit/informatik/model/RailwayNetwork.java @@ -215,7 +215,7 @@ 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); @@ -244,16 +244,13 @@ public class RailwayNetwork { // check that the requested direction is equal to the direction of one the tracks final Rail[] touchingRails = findTouchingRails(position); if (touchingRails.length == 0) { - if (!findContainingRail(position) + return findContainingRail(position) .map(rail -> rail.allowsPlacement(position, direction)) - .orElse(false)) { - return false; // containing rail is orthogonal to the requested direction - } + .orElse(false); // containing rail is orthogonal to the requested direction } else if (touchingRails.length == 1) { - if (!(touchingRails[0].allowsPlacement(position, direction) - || touchingRails[0].allowsMovement(position, direction))) { - return false; // rail is orthogonal to the requested direction - } + // rail should not be orthogonal to the requested direction + return touchingRails[0].allowsPlacement(position, direction) + || touchingRails[0].allowsMovement(position, direction); } else if (!touchingRails[0].allowsPlacement(position, direction) && !touchingRails[1].allowsPlacement(position, direction) && !(touchingRails[0].allowsMovement(position, direction) diff --git a/src/edu/kit/informatik/model/SpecialCoach.java b/src/edu/kit/informatik/model/SpecialCoach.java index 76c39f9..53815f0 100644 --- a/src/edu/kit/informatik/model/SpecialCoach.java +++ b/src/edu/kit/informatik/model/SpecialCoach.java @@ -10,7 +10,7 @@ import edu.kit.informatik.ui.InvalidInputException; */ public class SpecialCoach extends Coach { /** - * ASCII art represantation of a special coach. + * ASCII art representation of a special coach. */ private static final String[] SPECIAL_TEXT = new String[] { " ____", diff --git a/src/edu/kit/informatik/model/Switch.java b/src/edu/kit/informatik/model/Switch.java index d94e706..f92f836 100644 --- a/src/edu/kit/informatik/model/Switch.java +++ b/src/edu/kit/informatik/model/Switch.java @@ -76,11 +76,6 @@ public final class Switch extends Rail { return selection != null && selection.contains(position); } - @Override - public boolean canContain(Vector2D position) { - return positionOne.contains(position) || positionTwo.contains(position); - } - @Override public Vector2D move(Vector2D position, Vector2D direction, long steps) { if (contains(position) || connectsTo(position)) { diff --git a/src/edu/kit/informatik/model/Track.java b/src/edu/kit/informatik/model/Track.java index 28a6733..69749f5 100644 --- a/src/edu/kit/informatik/model/Track.java +++ b/src/edu/kit/informatik/model/Track.java @@ -72,11 +72,6 @@ public final class Track extends Rail { return false; } - @Override - public boolean canContain(Vector2D position) { - return contains(position); - } - @Override public Vector2D move(Vector2D position, Vector2D direction, long steps) { final Vector2D nextPosition = position.add(direction.scale(steps)); diff --git a/src/edu/kit/informatik/model/TrainManager.java b/src/edu/kit/informatik/model/TrainManager.java index 1202eba..73aa75c 100644 --- a/src/edu/kit/informatik/model/TrainManager.java +++ b/src/edu/kit/informatik/model/TrainManager.java @@ -18,6 +18,8 @@ import java.util.stream.Collectors; import java.util.stream.IntStream; import java.util.stream.Stream; +import static edu.kit.informatik.ui.CommandLine.OK; + /** * Train manager, used for processing train placements and movement on a rail network. * @@ -177,7 +179,7 @@ public final class TrainManager { /** * Calculate the next train identifier. - * @return the next train identfier, or -1 if none available + * @return the next train identifier, or -1 if none available */ private int getNextTrainIdentifier() { return IntStream.rangeClosed(1, Integer.MAX_VALUE) @@ -323,7 +325,7 @@ public final class TrainManager { throw new InvalidInputException("rail tracks/switches not set up"); } if (trains.values().stream().noneMatch(Train::isPlaced)) { - Terminal.printLine("OK"); + Terminal.printLine(OK); return; } diff --git a/src/edu/kit/informatik/ui/CommandLine.java b/src/edu/kit/informatik/ui/CommandLine.java index b359d8f..46540ac 100644 --- a/src/edu/kit/informatik/ui/CommandLine.java +++ b/src/edu/kit/informatik/ui/CommandLine.java @@ -11,6 +11,11 @@ import edu.kit.informatik.ui.command.CommandFactory; * @version 1.0 */ public final class CommandLine { + /** + * Text used to indicate that an operation was successful. + */ + public static final String OK = "OK"; + /** * Command used to exit the simulation and terminate the program. */ diff --git a/src/edu/kit/informatik/ui/command/DeleteRollingStock.java b/src/edu/kit/informatik/ui/command/DeleteRollingStock.java index 76d3402..24d4ba1 100644 --- a/src/edu/kit/informatik/ui/command/DeleteRollingStock.java +++ b/src/edu/kit/informatik/ui/command/DeleteRollingStock.java @@ -7,6 +7,7 @@ import edu.kit.informatik.ui.InvalidInputException; import java.util.regex.Matcher; import java.util.regex.Pattern; +import static edu.kit.informatik.ui.CommandLine.OK; import static edu.kit.informatik.ui.command.CommandFactory.DELETE_ROLLING_STOCK; import static edu.kit.informatik.ui.command.CommandFactory.ROLLING_STOCK_IDENTIFIER; @@ -30,7 +31,7 @@ public class DeleteRollingStock extends Command { throw new IllegalStateException("command not initialized"); } if (simulation.deleteRollingStock(id)) { - Terminal.printLine("OK"); + Terminal.printLine(OK); } else { Terminal.printError("could not delete rolling stock"); } diff --git a/src/edu/kit/informatik/ui/command/DeleteTrack.java b/src/edu/kit/informatik/ui/command/DeleteTrack.java index 17aa117..bc695c6 100644 --- a/src/edu/kit/informatik/ui/command/DeleteTrack.java +++ b/src/edu/kit/informatik/ui/command/DeleteTrack.java @@ -4,6 +4,7 @@ import edu.kit.informatik.model.ModelRailwaySimulation; import edu.kit.informatik.Terminal; import edu.kit.informatik.ui.InvalidInputException; +import static edu.kit.informatik.ui.CommandLine.OK; import static edu.kit.informatik.ui.command.CommandFactory.DELETE_TRACK; import static edu.kit.informatik.ui.command.CommandFactory.NUMBER; @@ -22,7 +23,7 @@ public class DeleteTrack extends Command { @Override public void apply(ModelRailwaySimulation simulation) { if (simulation.removeRail(id)) { - Terminal.printLine("OK"); + Terminal.printLine(OK); } else { Terminal.printError("could not delete rail segment"); } diff --git a/src/edu/kit/informatik/ui/command/DeleteTrain.java b/src/edu/kit/informatik/ui/command/DeleteTrain.java index b6f0339..325cf87 100644 --- a/src/edu/kit/informatik/ui/command/DeleteTrain.java +++ b/src/edu/kit/informatik/ui/command/DeleteTrain.java @@ -4,6 +4,7 @@ import edu.kit.informatik.model.ModelRailwaySimulation; import edu.kit.informatik.Terminal; import edu.kit.informatik.ui.InvalidInputException; +import static edu.kit.informatik.ui.CommandLine.OK; import static edu.kit.informatik.ui.command.CommandFactory.DELETE_TRAIN; import static edu.kit.informatik.ui.command.CommandFactory.NUMBER; @@ -22,7 +23,7 @@ public class DeleteTrain extends Command { @Override public void apply(ModelRailwaySimulation simulation) { if (simulation.deleteTrain(id)) { - Terminal.printLine("OK"); + Terminal.printLine(OK); } else { Terminal.printError("could not remove train"); } diff --git a/src/edu/kit/informatik/ui/command/PutTrain.java b/src/edu/kit/informatik/ui/command/PutTrain.java index 3e0a73e..3a5c576 100644 --- a/src/edu/kit/informatik/ui/command/PutTrain.java +++ b/src/edu/kit/informatik/ui/command/PutTrain.java @@ -8,6 +8,7 @@ import edu.kit.informatik.ui.InvalidInputException; import java.util.regex.Matcher; import java.util.regex.Pattern; +import static edu.kit.informatik.ui.CommandLine.OK; import static edu.kit.informatik.ui.command.CommandFactory.NUMBER; import static edu.kit.informatik.ui.command.CommandFactory.PUT_TRAIN; import static edu.kit.informatik.ui.command.CommandFactory.VECTOR; @@ -41,7 +42,7 @@ public class PutTrain extends Command { throw new IllegalStateException("command not initialized"); } if (simulation.putTrain(id, point, direction)) { - Terminal.printLine("OK"); + Terminal.printLine(OK); } else { Terminal.printError("could not place train"); } diff --git a/src/edu/kit/informatik/ui/command/SetSwitch.java b/src/edu/kit/informatik/ui/command/SetSwitch.java index c0b335b..22fed32 100644 --- a/src/edu/kit/informatik/ui/command/SetSwitch.java +++ b/src/edu/kit/informatik/ui/command/SetSwitch.java @@ -8,6 +8,7 @@ import edu.kit.informatik.ui.InvalidInputException; import java.util.regex.Matcher; import java.util.regex.Pattern; +import static edu.kit.informatik.ui.CommandLine.OK; import static edu.kit.informatik.ui.command.CommandFactory.NUMBER; import static edu.kit.informatik.ui.command.CommandFactory.SET_SWITCH; import static edu.kit.informatik.ui.command.CommandFactory.VECTOR; @@ -37,7 +38,7 @@ public class SetSwitch extends Command { throw new IllegalStateException("command not initialized"); } if (simulation.setSwitch(id, point)) { - Terminal.printLine("OK"); + Terminal.printLine(OK); } else { Terminal.printError("could not set switch"); }