mirror of
https://gitlab.com/arnekeller/kit-programmieren-ws1920-final1.git
synced 2024-11-27 18:55:55 +00:00
Checkstyle
This commit is contained in:
parent
0f4ad23bdb
commit
c4f2659035
@ -146,12 +146,13 @@ public final class TrainManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Place a train on the rail network.
|
* Attempt to place a train on the rail network.
|
||||||
|
*
|
||||||
* @param trainId identifier of the train to place
|
* @param trainId identifier of the train to place
|
||||||
* @param position where to place the train
|
* @param position where to place the train
|
||||||
* @param direction direction in which the train should initially go
|
* @param direction direction in which the train should initially go
|
||||||
* @return whether the train was successfully placed
|
* @return whether the train was successfully placed
|
||||||
* @throws InvalidInputException when the train is too long
|
* @throws InvalidInputException if train could not be placed due to semantic error
|
||||||
*/
|
*/
|
||||||
public boolean putTrain(int trainId, Vector2D position, Vector2D direction) throws InvalidInputException {
|
public boolean putTrain(int trainId, Vector2D position, Vector2D direction) throws InvalidInputException {
|
||||||
final Train train = trains.get(trainId);
|
final Train train = trains.get(trainId);
|
||||||
@ -168,7 +169,7 @@ public final class TrainManager {
|
|||||||
}
|
}
|
||||||
// attempt to place train
|
// attempt to place train
|
||||||
final boolean placed = train.placeOn(railNetwork, position, direction);
|
final boolean placed = train.placeOn(railNetwork, position, direction);
|
||||||
// check for collisions
|
// check for collisions with existing trains
|
||||||
if (placed && !getPlacementCollisions().isEmpty()) {
|
if (placed && !getPlacementCollisions().isEmpty()) {
|
||||||
train.removeFromRails();
|
train.removeFromRails();
|
||||||
return false;
|
return false;
|
||||||
@ -178,7 +179,7 @@ public final class TrainManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Calculate the next train identifier.
|
* Calculate the next available train identifier.
|
||||||
* @return the next train identifier, or -1 if none available
|
* @return the next train identifier, or -1 if none available
|
||||||
*/
|
*/
|
||||||
private int getNextTrainIdentifier() {
|
private int getNextTrainIdentifier() {
|
||||||
@ -222,7 +223,7 @@ public final class TrainManager {
|
|||||||
private List<Set<Train>> getPlacementCollisions() {
|
private List<Set<Train>> getPlacementCollisions() {
|
||||||
final List<Set<Train>> collisions = new ArrayList<>();
|
final List<Set<Train>> collisions = new ArrayList<>();
|
||||||
trains.values().stream().filter(Train::isPlaced).forEach(train1 ->
|
trains.values().stream().filter(Train::isPlaced).forEach(train1 ->
|
||||||
trains.values().stream().filter(train -> train != train1).filter(Train::isPlaced).forEach(train2 -> {
|
trains.values().stream().filter(Train::isPlaced).forEach(train2 -> {
|
||||||
final Set<Rail> occupiedByTrain1 = train1.getOccupiedRails();
|
final Set<Rail> occupiedByTrain1 = train1.getOccupiedRails();
|
||||||
Collections.addAll(occupiedByTrain1, railNetwork.findTouchingRails(train1.getFrontPosition()));
|
Collections.addAll(occupiedByTrain1, railNetwork.findTouchingRails(train1.getFrontPosition()));
|
||||||
Collections.addAll(occupiedByTrain1, railNetwork.findTouchingRails(train1.getRearPosition()));
|
Collections.addAll(occupiedByTrain1, railNetwork.findTouchingRails(train1.getRearPosition()));
|
||||||
|
Loading…
Reference in New Issue
Block a user