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
f5cb7e6f80
commit
0f4ad23bdb
@ -18,6 +18,7 @@ public final class Main {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Program entry point.
|
* Program entry point.
|
||||||
|
*
|
||||||
* @param args command-line arguments
|
* @param args command-line arguments
|
||||||
*/
|
*/
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
|
@ -7,6 +7,7 @@ import java.nio.file.Files;
|
|||||||
|
|
||||||
import static org.junit.jupiter.api.Assertions.*;
|
import static org.junit.jupiter.api.Assertions.*;
|
||||||
|
|
||||||
|
@SuppressWarnings("ALL")
|
||||||
class MainTest {
|
class MainTest {
|
||||||
@Test
|
@Test
|
||||||
void basics() throws IOException {
|
void basics() throws IOException {
|
||||||
|
@ -17,6 +17,7 @@ import java.io.InputStreamReader;
|
|||||||
* @author IPD, SDQ Group
|
* @author IPD, SDQ Group
|
||||||
* @version 5.03, 2016/05/07
|
* @version 5.03, 2016/05/07
|
||||||
*/
|
*/
|
||||||
|
@SuppressWarnings("ALL")
|
||||||
public final class Terminal {
|
public final class Terminal {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -58,12 +58,6 @@ public abstract class Rail {
|
|||||||
*/
|
*/
|
||||||
public abstract boolean contains(Vector2D position);
|
public abstract boolean contains(Vector2D position);
|
||||||
|
|
||||||
/**
|
|
||||||
* @param position the point to check
|
|
||||||
* @return whether the point can be inside this rail (not on the edge)
|
|
||||||
*/
|
|
||||||
public abstract boolean canContain(Vector2D position);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Try to set the rail to connect to this position. Obviously only makes sense for switches and similar rails.
|
* Try to set the rail to connect to this position. Obviously only makes sense for switches and similar rails.
|
||||||
* @param position point to connect to
|
* @param position point to connect to
|
||||||
|
@ -215,7 +215,7 @@ public class RailwayNetwork {
|
|||||||
final Vector2D onRailOne = touchingRails[0].move(position, new Vector2D(direction), steps);
|
final Vector2D onRailOne = touchingRails[0].move(position, new Vector2D(direction), steps);
|
||||||
final Vector2D onRailTwo = touchingRails[1].move(position, new Vector2D(direction), steps);
|
final Vector2D onRailTwo = touchingRails[1].move(position, new Vector2D(direction), steps);
|
||||||
if (position.equals(onRailOne) || onRailOne == null
|
if (position.equals(onRailOne) || onRailOne == null
|
||||||
|| (onRailTwo != null && onRailTwo.subtract(position).directionEquals(direction))) {
|
|| onRailTwo != null && onRailTwo.subtract(position).directionEquals(direction)) {
|
||||||
// we are moving on rail two
|
// we are moving on rail two
|
||||||
final Vector2D newDirection = touchingRails[1].getDirectionFrom(position);
|
final Vector2D newDirection = touchingRails[1].getDirectionFrom(position);
|
||||||
direction.copyFrom(newDirection);
|
direction.copyFrom(newDirection);
|
||||||
@ -244,16 +244,13 @@ public class RailwayNetwork {
|
|||||||
// check that the requested direction is equal to the direction of one the tracks
|
// check that the requested direction is equal to the direction of one the tracks
|
||||||
final Rail[] touchingRails = findTouchingRails(position);
|
final Rail[] touchingRails = findTouchingRails(position);
|
||||||
if (touchingRails.length == 0) {
|
if (touchingRails.length == 0) {
|
||||||
if (!findContainingRail(position)
|
return findContainingRail(position)
|
||||||
.map(rail -> rail.allowsPlacement(position, direction))
|
.map(rail -> rail.allowsPlacement(position, direction))
|
||||||
.orElse(false)) {
|
.orElse(false); // containing rail is orthogonal to the requested direction
|
||||||
return false; // containing rail is orthogonal to the requested direction
|
|
||||||
}
|
|
||||||
} else if (touchingRails.length == 1) {
|
} else if (touchingRails.length == 1) {
|
||||||
if (!(touchingRails[0].allowsPlacement(position, direction)
|
// rail should not be orthogonal to the requested direction
|
||||||
|| touchingRails[0].allowsMovement(position, direction))) {
|
return touchingRails[0].allowsPlacement(position, direction)
|
||||||
return false; // rail is orthogonal to the requested direction
|
|| touchingRails[0].allowsMovement(position, direction);
|
||||||
}
|
|
||||||
} else if (!touchingRails[0].allowsPlacement(position, direction)
|
} else if (!touchingRails[0].allowsPlacement(position, direction)
|
||||||
&& !touchingRails[1].allowsPlacement(position, direction)
|
&& !touchingRails[1].allowsPlacement(position, direction)
|
||||||
&& !(touchingRails[0].allowsMovement(position, direction)
|
&& !(touchingRails[0].allowsMovement(position, direction)
|
||||||
|
@ -10,7 +10,7 @@ import edu.kit.informatik.ui.InvalidInputException;
|
|||||||
*/
|
*/
|
||||||
public class SpecialCoach extends Coach {
|
public class SpecialCoach extends Coach {
|
||||||
/**
|
/**
|
||||||
* ASCII art represantation of a special coach.
|
* ASCII art representation of a special coach.
|
||||||
*/
|
*/
|
||||||
private static final String[] SPECIAL_TEXT = new String[] {
|
private static final String[] SPECIAL_TEXT = new String[] {
|
||||||
" ____",
|
" ____",
|
||||||
|
@ -76,11 +76,6 @@ public final class Switch extends Rail {
|
|||||||
return selection != null && selection.contains(position);
|
return selection != null && selection.contains(position);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean canContain(Vector2D position) {
|
|
||||||
return positionOne.contains(position) || positionTwo.contains(position);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Vector2D move(Vector2D position, Vector2D direction, long steps) {
|
public Vector2D move(Vector2D position, Vector2D direction, long steps) {
|
||||||
if (contains(position) || connectsTo(position)) {
|
if (contains(position) || connectsTo(position)) {
|
||||||
|
@ -72,11 +72,6 @@ public final class Track extends Rail {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean canContain(Vector2D position) {
|
|
||||||
return contains(position);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Vector2D move(Vector2D position, Vector2D direction, long steps) {
|
public Vector2D move(Vector2D position, Vector2D direction, long steps) {
|
||||||
final Vector2D nextPosition = position.add(direction.scale(steps));
|
final Vector2D nextPosition = position.add(direction.scale(steps));
|
||||||
|
@ -18,6 +18,8 @@ import java.util.stream.Collectors;
|
|||||||
import java.util.stream.IntStream;
|
import java.util.stream.IntStream;
|
||||||
import java.util.stream.Stream;
|
import java.util.stream.Stream;
|
||||||
|
|
||||||
|
import static edu.kit.informatik.ui.CommandLine.OK;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Train manager, used for processing train placements and movement on a rail network.
|
* Train manager, used for processing train placements and movement on a rail network.
|
||||||
*
|
*
|
||||||
@ -177,7 +179,7 @@ public final class TrainManager {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Calculate the next train identifier.
|
* Calculate the next train identifier.
|
||||||
* @return the next train identfier, or -1 if none available
|
* @return the next train identifier, or -1 if none available
|
||||||
*/
|
*/
|
||||||
private int getNextTrainIdentifier() {
|
private int getNextTrainIdentifier() {
|
||||||
return IntStream.rangeClosed(1, Integer.MAX_VALUE)
|
return IntStream.rangeClosed(1, Integer.MAX_VALUE)
|
||||||
@ -323,7 +325,7 @@ public final class TrainManager {
|
|||||||
throw new InvalidInputException("rail tracks/switches not set up");
|
throw new InvalidInputException("rail tracks/switches not set up");
|
||||||
}
|
}
|
||||||
if (trains.values().stream().noneMatch(Train::isPlaced)) {
|
if (trains.values().stream().noneMatch(Train::isPlaced)) {
|
||||||
Terminal.printLine("OK");
|
Terminal.printLine(OK);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -11,6 +11,11 @@ import edu.kit.informatik.ui.command.CommandFactory;
|
|||||||
* @version 1.0
|
* @version 1.0
|
||||||
*/
|
*/
|
||||||
public final class CommandLine {
|
public final class CommandLine {
|
||||||
|
/**
|
||||||
|
* Text used to indicate that an operation was successful.
|
||||||
|
*/
|
||||||
|
public static final String OK = "OK";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Command used to exit the simulation and terminate the program.
|
* Command used to exit the simulation and terminate the program.
|
||||||
*/
|
*/
|
||||||
|
@ -7,6 +7,7 @@ import edu.kit.informatik.ui.InvalidInputException;
|
|||||||
import java.util.regex.Matcher;
|
import java.util.regex.Matcher;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
|
import static edu.kit.informatik.ui.CommandLine.OK;
|
||||||
import static edu.kit.informatik.ui.command.CommandFactory.DELETE_ROLLING_STOCK;
|
import static edu.kit.informatik.ui.command.CommandFactory.DELETE_ROLLING_STOCK;
|
||||||
import static edu.kit.informatik.ui.command.CommandFactory.ROLLING_STOCK_IDENTIFIER;
|
import static edu.kit.informatik.ui.command.CommandFactory.ROLLING_STOCK_IDENTIFIER;
|
||||||
|
|
||||||
@ -30,7 +31,7 @@ public class DeleteRollingStock extends Command {
|
|||||||
throw new IllegalStateException("command not initialized");
|
throw new IllegalStateException("command not initialized");
|
||||||
}
|
}
|
||||||
if (simulation.deleteRollingStock(id)) {
|
if (simulation.deleteRollingStock(id)) {
|
||||||
Terminal.printLine("OK");
|
Terminal.printLine(OK);
|
||||||
} else {
|
} else {
|
||||||
Terminal.printError("could not delete rolling stock");
|
Terminal.printError("could not delete rolling stock");
|
||||||
}
|
}
|
||||||
|
@ -4,6 +4,7 @@ import edu.kit.informatik.model.ModelRailwaySimulation;
|
|||||||
import edu.kit.informatik.Terminal;
|
import edu.kit.informatik.Terminal;
|
||||||
import edu.kit.informatik.ui.InvalidInputException;
|
import edu.kit.informatik.ui.InvalidInputException;
|
||||||
|
|
||||||
|
import static edu.kit.informatik.ui.CommandLine.OK;
|
||||||
import static edu.kit.informatik.ui.command.CommandFactory.DELETE_TRACK;
|
import static edu.kit.informatik.ui.command.CommandFactory.DELETE_TRACK;
|
||||||
import static edu.kit.informatik.ui.command.CommandFactory.NUMBER;
|
import static edu.kit.informatik.ui.command.CommandFactory.NUMBER;
|
||||||
|
|
||||||
@ -22,7 +23,7 @@ public class DeleteTrack extends Command {
|
|||||||
@Override
|
@Override
|
||||||
public void apply(ModelRailwaySimulation simulation) {
|
public void apply(ModelRailwaySimulation simulation) {
|
||||||
if (simulation.removeRail(id)) {
|
if (simulation.removeRail(id)) {
|
||||||
Terminal.printLine("OK");
|
Terminal.printLine(OK);
|
||||||
} else {
|
} else {
|
||||||
Terminal.printError("could not delete rail segment");
|
Terminal.printError("could not delete rail segment");
|
||||||
}
|
}
|
||||||
|
@ -4,6 +4,7 @@ import edu.kit.informatik.model.ModelRailwaySimulation;
|
|||||||
import edu.kit.informatik.Terminal;
|
import edu.kit.informatik.Terminal;
|
||||||
import edu.kit.informatik.ui.InvalidInputException;
|
import edu.kit.informatik.ui.InvalidInputException;
|
||||||
|
|
||||||
|
import static edu.kit.informatik.ui.CommandLine.OK;
|
||||||
import static edu.kit.informatik.ui.command.CommandFactory.DELETE_TRAIN;
|
import static edu.kit.informatik.ui.command.CommandFactory.DELETE_TRAIN;
|
||||||
import static edu.kit.informatik.ui.command.CommandFactory.NUMBER;
|
import static edu.kit.informatik.ui.command.CommandFactory.NUMBER;
|
||||||
|
|
||||||
@ -22,7 +23,7 @@ public class DeleteTrain extends Command {
|
|||||||
@Override
|
@Override
|
||||||
public void apply(ModelRailwaySimulation simulation) {
|
public void apply(ModelRailwaySimulation simulation) {
|
||||||
if (simulation.deleteTrain(id)) {
|
if (simulation.deleteTrain(id)) {
|
||||||
Terminal.printLine("OK");
|
Terminal.printLine(OK);
|
||||||
} else {
|
} else {
|
||||||
Terminal.printError("could not remove train");
|
Terminal.printError("could not remove train");
|
||||||
}
|
}
|
||||||
|
@ -8,6 +8,7 @@ import edu.kit.informatik.ui.InvalidInputException;
|
|||||||
import java.util.regex.Matcher;
|
import java.util.regex.Matcher;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
|
import static edu.kit.informatik.ui.CommandLine.OK;
|
||||||
import static edu.kit.informatik.ui.command.CommandFactory.NUMBER;
|
import static edu.kit.informatik.ui.command.CommandFactory.NUMBER;
|
||||||
import static edu.kit.informatik.ui.command.CommandFactory.PUT_TRAIN;
|
import static edu.kit.informatik.ui.command.CommandFactory.PUT_TRAIN;
|
||||||
import static edu.kit.informatik.ui.command.CommandFactory.VECTOR;
|
import static edu.kit.informatik.ui.command.CommandFactory.VECTOR;
|
||||||
@ -41,7 +42,7 @@ public class PutTrain extends Command {
|
|||||||
throw new IllegalStateException("command not initialized");
|
throw new IllegalStateException("command not initialized");
|
||||||
}
|
}
|
||||||
if (simulation.putTrain(id, point, direction)) {
|
if (simulation.putTrain(id, point, direction)) {
|
||||||
Terminal.printLine("OK");
|
Terminal.printLine(OK);
|
||||||
} else {
|
} else {
|
||||||
Terminal.printError("could not place train");
|
Terminal.printError("could not place train");
|
||||||
}
|
}
|
||||||
|
@ -8,6 +8,7 @@ import edu.kit.informatik.ui.InvalidInputException;
|
|||||||
import java.util.regex.Matcher;
|
import java.util.regex.Matcher;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
|
import static edu.kit.informatik.ui.CommandLine.OK;
|
||||||
import static edu.kit.informatik.ui.command.CommandFactory.NUMBER;
|
import static edu.kit.informatik.ui.command.CommandFactory.NUMBER;
|
||||||
import static edu.kit.informatik.ui.command.CommandFactory.SET_SWITCH;
|
import static edu.kit.informatik.ui.command.CommandFactory.SET_SWITCH;
|
||||||
import static edu.kit.informatik.ui.command.CommandFactory.VECTOR;
|
import static edu.kit.informatik.ui.command.CommandFactory.VECTOR;
|
||||||
@ -37,7 +38,7 @@ public class SetSwitch extends Command {
|
|||||||
throw new IllegalStateException("command not initialized");
|
throw new IllegalStateException("command not initialized");
|
||||||
}
|
}
|
||||||
if (simulation.setSwitch(id, point)) {
|
if (simulation.setSwitch(id, point)) {
|
||||||
Terminal.printLine("OK");
|
Terminal.printLine(OK);
|
||||||
} else {
|
} else {
|
||||||
Terminal.printError("could not set switch");
|
Terminal.printError("could not set switch");
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user