From ea15f218cb391f0e8bfaf42a5232f8fa5d64fb8b Mon Sep 17 00:00:00 2001 From: Arne Keller Date: Thu, 5 Mar 2020 21:45:12 +0100 Subject: [PATCH] Checkstyle --- src/edu/kit/informatik/model/Switch.java | 12 ++++-------- src/edu/kit/informatik/model/Train.java | 15 ++++++++------- 2 files changed, 12 insertions(+), 15 deletions(-) diff --git a/src/edu/kit/informatik/model/Switch.java b/src/edu/kit/informatik/model/Switch.java index fded548..d94e706 100644 --- a/src/edu/kit/informatik/model/Switch.java +++ b/src/edu/kit/informatik/model/Switch.java @@ -28,8 +28,8 @@ public final class Switch extends Rail { * Construct a new switch. * * @param start start position - * @param end1 end position 1 - * @param end2 end position 2 + * @param end1 first end position + * @param end2 second end position * @param id identifier of this switch * @throws InvalidInputException if the switch is not composed of straight lines */ @@ -46,8 +46,7 @@ public final class Switch extends Rail { @Override public boolean connectsTo(Vector2D point) { - return (positionOne.canConnectTo(point) && positionTwo.canConnectTo(point)) - || (selection != null && selection.canConnectTo(point)); + return selection != null && selection.canConnectTo(point); } @Override @@ -74,10 +73,7 @@ public final class Switch extends Rail { @Override public boolean contains(Vector2D position) { - if (selection == null) { - return false; - } - return selection.contains(position); + return selection != null && selection.contains(position); } @Override diff --git a/src/edu/kit/informatik/model/Train.java b/src/edu/kit/informatik/model/Train.java index d958459..3cf0e47 100644 --- a/src/edu/kit/informatik/model/Train.java +++ b/src/edu/kit/informatik/model/Train.java @@ -143,7 +143,7 @@ public final class Train { */ public boolean placeOn(RailwayNetwork railNetwork, Vector2D position, Vector2D rawDirection) { if (isPlaced()) { - return false; + return false; // do not place a train that is already placed } final Vector2D direction = rawDirection.normalized(); final Vector2D positioningDirection = direction.negated(); @@ -159,22 +159,23 @@ public final class Train { if (!railNetwork.findContainingRail(position) .map(rail -> rail.allowsPlacement(position, direction)) .orElse(false)) { - return false; + return 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; + return false; // rail is orthogonal to the requested direction } - } else if (touchingRails.length == 2 - && !touchingRails[0].allowsPlacement(position, direction) + } else if (!touchingRails[0].allowsPlacement(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; } final Set occupiedRailsSet = new HashSet<>(); - while (length > 0) { + while (length > 0) { // while part of the train still needs to be placed rollingStockPosition = railNetwork.move(rollingStockPosition, positioningDirection, length); if (rollingStockPosition == null) { // derailed @@ -182,7 +183,7 @@ public final class Train { } final long distanceToLastPosition = positionList.getLast().distanceTo(rollingStockPosition); if (distanceToLastPosition == 0) { - // stuck + // stuck at end of rail return false; }