mirror of
https://gitlab.com/arnekeller/kit-programmieren-ws1920-final1.git
synced 2024-11-24 01:15:05 +00:00
SonarQube
This commit is contained in:
parent
f5706a2edf
commit
8ec474520c
@ -71,7 +71,7 @@ public class ModelRailwaySimulation {
|
||||
*/
|
||||
public boolean removeRail(int id) {
|
||||
// check whether any trains are on this rail
|
||||
return railNetwork.getRail(id).isPresent() && !trainManager.anyTrainOnRail(railNetwork.getRail(id).get())
|
||||
return !railNetwork.getRail(id).map(trainManager::anyTrainOnRail).orElse(true)
|
||||
&& railNetwork.removeRail(id);
|
||||
}
|
||||
|
||||
@ -250,16 +250,19 @@ public class ModelRailwaySimulation {
|
||||
|
||||
/**
|
||||
* Create a new train or add rolling stock to an existing train.
|
||||
*
|
||||
* @param trainId identifier of the train
|
||||
* @param rollingStockId identifier of the rolling stock
|
||||
* @return the added rolling stock
|
||||
* @throws InvalidInputException if input is incorrect
|
||||
*/
|
||||
public void addTrain(int trainId, String rollingStockId) throws InvalidInputException {
|
||||
public RollingStock addTrain(int trainId, String rollingStockId) throws InvalidInputException {
|
||||
final Optional<RollingStock> rollingStock = getRollingStock(rollingStockId);
|
||||
if (!rollingStock.isPresent()) {
|
||||
throw new InvalidInputException("rolling stock not found");
|
||||
}
|
||||
trainManager.addTrain(trainId, rollingStock.get());
|
||||
return rollingStock.get();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -153,9 +153,9 @@ public final class Train {
|
||||
length -= distanceToLastPosition;
|
||||
|
||||
final Rail occupiedRail = railNetwork.findRail(positionList.getLast(), rollingStockPosition).get();
|
||||
if (occupiedRailsSet.contains(occupiedRail) && positionList.size() >= 4) {
|
||||
if (occupiedRailsSet.contains(occupiedRail) && positionList.size() > 4) {
|
||||
// perhaps a self intersection
|
||||
final long occupiedAtFrontOfTrain = positionList.get(0).distanceTo(positionList.get(1));
|
||||
final long occupiedAtFrontOfTrain = positionList.getFirst().distanceTo(positionList.get(1));
|
||||
final long occupiedAtBackOfTrain = positionList.getLast()
|
||||
.distanceTo(positionList.get(positionList.size() - 2));
|
||||
if (occupiedAtFrontOfTrain + occupiedAtBackOfTrain > occupiedRail.getLength()) {
|
||||
@ -269,6 +269,7 @@ public final class Train {
|
||||
* @param backPosition position to move back of the train to
|
||||
*/
|
||||
public void moveBackTo(RailwayNetwork railNetwork, Vector2D backPosition) {
|
||||
// TODO: create common method for both directions
|
||||
final Optional<Rail> railUnderFrontOfTrain = railNetwork.findContainingRail(positions.getFirst());
|
||||
positions.getFirst().subtractInPlace(getDirection());
|
||||
if (positions.getFirst().equals(positions.get(1))) {
|
||||
|
@ -32,10 +32,10 @@ public final class CommandLine {
|
||||
while (true) {
|
||||
final String input = Terminal.readLine();
|
||||
if (input == null) {
|
||||
break; // TODO remove
|
||||
break; // FIXME remove
|
||||
}
|
||||
if (input.startsWith("#")) {
|
||||
continue; // TODO remove
|
||||
continue; // FIXME remove
|
||||
}
|
||||
|
||||
if (input.startsWith(EXIT)) {
|
||||
@ -43,7 +43,7 @@ public final class CommandLine {
|
||||
Terminal.printError("input after exit command");
|
||||
continue;
|
||||
} else {
|
||||
break;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -36,8 +36,7 @@ public class AddTrain extends Command {
|
||||
if (rollingStockId == null) {
|
||||
throw new IllegalStateException("command not initialized");
|
||||
}
|
||||
simulation.addTrain(trainId, rollingStockId);
|
||||
final RollingStock rollingStock = simulation.getRollingStock(rollingStockId).get();
|
||||
final RollingStock rollingStock = simulation.addTrain(trainId, rollingStockId);
|
||||
Terminal.printLine(String.format("%s %s added to train %d",
|
||||
rollingStock.description(), rollingStock.getIdentifier(), trainId));
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user