mirror of
https://gitlab.com/arnekeller/kit-programmieren-ws1920-final1.git
synced 2024-11-14 12:43:07 +00:00
Checkstyle
This commit is contained in:
parent
b17e8db22f
commit
e8a2a28aa8
@ -34,8 +34,8 @@ public class RailwayNetwork {
|
|||||||
if (start.distanceTo(end) == 0) {
|
if (start.distanceTo(end) == 0) {
|
||||||
throw new InvalidInputException("track has length zero");
|
throw new InvalidInputException("track has length zero");
|
||||||
}
|
}
|
||||||
long startPossibleConnections = rails.values().stream().filter((rail) -> rail.canConnectTo(start)).count();
|
long startPossibleConnections = rails.values().stream().filter(rail -> rail.canConnectTo(start)).count();
|
||||||
long endPossibleConnections = rails.values().stream().filter((rail) -> rail.canConnectTo(end)).count();
|
long endPossibleConnections = rails.values().stream().filter(rail -> rail.canConnectTo(end)).count();
|
||||||
if (startPossibleConnections == 2 || endPossibleConnections == 2) {
|
if (startPossibleConnections == 2 || endPossibleConnections == 2) {
|
||||||
throw new InvalidInputException("track would connect to two other rails");
|
throw new InvalidInputException("track would connect to two other rails");
|
||||||
}
|
}
|
||||||
@ -76,9 +76,9 @@ public class RailwayNetwork {
|
|||||||
rails.put(1, newSwitch);
|
rails.put(1, newSwitch);
|
||||||
return newSwitch.getIdentifier();
|
return newSwitch.getIdentifier();
|
||||||
} else {
|
} else {
|
||||||
long startPossibleConnections = rails.values().stream().filter((rail) -> rail.canConnectTo(start)).count();
|
long startPossibleConnections = rails.values().stream().filter(rail -> rail.canConnectTo(start)).count();
|
||||||
long end1PossibleConnections = rails.values().stream().filter((rail) -> rail.canConnectTo(end1)).count();
|
long end1PossibleConnections = rails.values().stream().filter(rail -> rail.canConnectTo(end1)).count();
|
||||||
long end2PossibleConnections = rails.values().stream().filter((rail) -> rail.canConnectTo(end2)).count();
|
long end2PossibleConnections = rails.values().stream().filter(rail -> rail.canConnectTo(end2)).count();
|
||||||
if (startPossibleConnections == 2 || end1PossibleConnections == 2 || end2PossibleConnections == 2) {
|
if (startPossibleConnections == 2 || end1PossibleConnections == 2 || end2PossibleConnections == 2) {
|
||||||
throw new InvalidInputException("switch endpoint would connect to two other rails");
|
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
|
* @return the rail(s) that touch this position
|
||||||
*/
|
*/
|
||||||
public Rail[] findTouchingRails(final Vector2D 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);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -48,7 +48,7 @@ public final class Track extends Rail {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean canConnectToRail(Rail rail) {
|
public boolean canConnectToRail(Rail rail) {
|
||||||
return rail != null && rail.canConnectTo(start) || rail.canConnectTo(end);
|
return rail != null && (rail.canConnectTo(start) || rail.canConnectTo(end));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -143,7 +143,7 @@ public final class Train {
|
|||||||
*/
|
*/
|
||||||
public boolean placeOn(final RailwayNetwork railNetwork, final Vector2D position, final Vector2D rawDirection)
|
public boolean placeOn(final RailwayNetwork railNetwork, final Vector2D position, final Vector2D rawDirection)
|
||||||
throws InvalidInputException {
|
throws InvalidInputException {
|
||||||
Vector2D direction = rawDirection.normalized();
|
Vector2D positioningDirection = rawDirection.normalized().negated();
|
||||||
long length = getLength();
|
long length = getLength();
|
||||||
if (length > Integer.MAX_VALUE) {
|
if (length > Integer.MAX_VALUE) {
|
||||||
// TODO: implement this case
|
// TODO: implement this case
|
||||||
@ -152,7 +152,6 @@ public final class Train {
|
|||||||
|
|
||||||
LinkedList<Vector2D> positions = new LinkedList<>();
|
LinkedList<Vector2D> positions = new LinkedList<>();
|
||||||
positions.addLast(position);
|
positions.addLast(position);
|
||||||
Vector2D positioningDirection = direction.negated();
|
|
||||||
Vector2D rollingStockPosition = position;
|
Vector2D rollingStockPosition = position;
|
||||||
if (length > 10000) {
|
if (length > 10000) {
|
||||||
return false; // TODO: remove!
|
return false; // TODO: remove!
|
||||||
@ -167,12 +166,12 @@ public final class Train {
|
|||||||
}
|
}
|
||||||
positions.addLast(rollingStockPosition);
|
positions.addLast(rollingStockPosition);
|
||||||
}
|
}
|
||||||
Set<Rail> occupiedRails = new HashSet<>();
|
Set<Rail> occupiedRailsSet = new HashSet<>();
|
||||||
for (int i = 0; i < positions.size(); i++) {
|
for (int i = 0; i < positions.size(); i++) {
|
||||||
Vector2D point = positions.get(i);
|
Vector2D point = positions.get(i);
|
||||||
Rail containingRail = railNetwork.findContainingRail(point);
|
Rail containingRail = railNetwork.findContainingRail(point);
|
||||||
if (containingRail != null) {
|
if (containingRail != null) {
|
||||||
occupiedRails.add(containingRail);
|
occupiedRailsSet.add(containingRail);
|
||||||
} else if (i > 0) {
|
} else if (i > 0) {
|
||||||
Rail[] touchingRails = railNetwork.findTouchingRails(point);
|
Rail[] touchingRails = railNetwork.findTouchingRails(point);
|
||||||
for (Rail rail : touchingRails) {
|
for (Rail rail : touchingRails) {
|
||||||
@ -180,14 +179,14 @@ public final class Train {
|
|||||||
// ONLY add this rail if we actually occupy it fully
|
// ONLY add this rail if we actually occupy it fully
|
||||||
// note that this edge case only happens with rails of length one:
|
// 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)
|
// otherwise at least one position will be contained in the rail (see above)
|
||||||
occupiedRails.add(rail);
|
occupiedRailsSet.add(rail);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
this.position = positions;
|
this.position = positions;
|
||||||
this.direction = direction;
|
this.direction = direction;
|
||||||
this.occupiedRails = occupiedRails;
|
this.occupiedRails = occupiedRailsSet;
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user