From e8a2a28aa85ee1d66c664daaaa1e0507dfe3483e Mon Sep 17 00:00:00 2001 From: Arne Keller Date: Wed, 19 Feb 2020 18:30:40 +0100 Subject: [PATCH] Checkstyle --- src/edu/kit/informatik/model/RailwayNetwork.java | 12 ++++++------ src/edu/kit/informatik/model/Track.java | 2 +- src/edu/kit/informatik/model/Train.java | 11 +++++------ 3 files changed, 12 insertions(+), 13 deletions(-) diff --git a/src/edu/kit/informatik/model/RailwayNetwork.java b/src/edu/kit/informatik/model/RailwayNetwork.java index aca5062..4c4fead 100644 --- a/src/edu/kit/informatik/model/RailwayNetwork.java +++ b/src/edu/kit/informatik/model/RailwayNetwork.java @@ -34,8 +34,8 @@ public class RailwayNetwork { if (start.distanceTo(end) == 0) { throw new InvalidInputException("track has length zero"); } - long startPossibleConnections = rails.values().stream().filter((rail) -> rail.canConnectTo(start)).count(); - long endPossibleConnections = rails.values().stream().filter((rail) -> rail.canConnectTo(end)).count(); + long startPossibleConnections = rails.values().stream().filter(rail -> rail.canConnectTo(start)).count(); + long endPossibleConnections = rails.values().stream().filter(rail -> rail.canConnectTo(end)).count(); if (startPossibleConnections == 2 || endPossibleConnections == 2) { throw new InvalidInputException("track would connect to two other rails"); } @@ -76,9 +76,9 @@ public class RailwayNetwork { rails.put(1, newSwitch); return newSwitch.getIdentifier(); } else { - long startPossibleConnections = rails.values().stream().filter((rail) -> rail.canConnectTo(start)).count(); - long end1PossibleConnections = rails.values().stream().filter((rail) -> rail.canConnectTo(end1)).count(); - long end2PossibleConnections = rails.values().stream().filter((rail) -> rail.canConnectTo(end2)).count(); + long startPossibleConnections = rails.values().stream().filter(rail -> rail.canConnectTo(start)).count(); + long end1PossibleConnections = rails.values().stream().filter(rail -> rail.canConnectTo(end1)).count(); + long end2PossibleConnections = rails.values().stream().filter(rail -> rail.canConnectTo(end2)).count(); if (startPossibleConnections == 2 || end1PossibleConnections == 2 || end2PossibleConnections == 2) { throw new InvalidInputException("switch endpoint would connect to two other rails"); } @@ -250,7 +250,7 @@ public class RailwayNetwork { * @return the rail(s) that touch this position */ public Rail[] findTouchingRails(final Vector2D position) { - return rails.values().stream().filter((rail) -> rail.canConnectTo(position)).toArray(Rail[]::new); + return rails.values().stream().filter(rail -> rail.canConnectTo(position)).toArray(Rail[]::new); } /** diff --git a/src/edu/kit/informatik/model/Track.java b/src/edu/kit/informatik/model/Track.java index e784b1d..1a7d14f 100644 --- a/src/edu/kit/informatik/model/Track.java +++ b/src/edu/kit/informatik/model/Track.java @@ -48,7 +48,7 @@ public final class Track extends Rail { @Override public boolean canConnectToRail(Rail rail) { - return rail != null && rail.canConnectTo(start) || rail.canConnectTo(end); + return rail != null && (rail.canConnectTo(start) || rail.canConnectTo(end)); } @Override diff --git a/src/edu/kit/informatik/model/Train.java b/src/edu/kit/informatik/model/Train.java index 128436d..eae2eed 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(final RailwayNetwork railNetwork, final Vector2D position, final Vector2D rawDirection) throws InvalidInputException { - Vector2D direction = rawDirection.normalized(); + Vector2D positioningDirection = rawDirection.normalized().negated(); long length = getLength(); if (length > Integer.MAX_VALUE) { // TODO: implement this case @@ -152,7 +152,6 @@ public final class Train { LinkedList positions = new LinkedList<>(); positions.addLast(position); - Vector2D positioningDirection = direction.negated(); Vector2D rollingStockPosition = position; if (length > 10000) { return false; // TODO: remove! @@ -167,12 +166,12 @@ public final class Train { } positions.addLast(rollingStockPosition); } - Set occupiedRails = new HashSet<>(); + Set occupiedRailsSet = new HashSet<>(); for (int i = 0; i < positions.size(); i++) { Vector2D point = positions.get(i); Rail containingRail = railNetwork.findContainingRail(point); if (containingRail != null) { - occupiedRails.add(containingRail); + occupiedRailsSet.add(containingRail); } else if (i > 0) { Rail[] touchingRails = railNetwork.findTouchingRails(point); for (Rail rail : touchingRails) { @@ -180,14 +179,14 @@ public final class Train { // ONLY add this rail if we actually occupy it fully // note that this edge case only happens with rails of length one: // otherwise at least one position will be contained in the rail (see above) - occupiedRails.add(rail); + occupiedRailsSet.add(rail); } } } } this.position = positions; this.direction = direction; - this.occupiedRails = occupiedRails; + this.occupiedRails = occupiedRailsSet; return true; }