mirror of
https://gitlab.com/arnekeller/kit-programmieren-ws1920-final1.git
synced 2024-11-24 09:24:58 +00:00
Checkstyle
This commit is contained in:
parent
3610cfac8d
commit
d446628f35
@ -13,16 +13,14 @@ public class CommandLine {
|
|||||||
private static final String EXIT = "exit";
|
private static final String EXIT = "exit";
|
||||||
|
|
||||||
public static void startInteractive() {
|
public static void startInteractive() {
|
||||||
|
// create a new simulation
|
||||||
ModelRailwaySimulation simulation = new ModelRailwaySimulation();
|
ModelRailwaySimulation simulation = new ModelRailwaySimulation();
|
||||||
|
|
||||||
while (true) {
|
while (true) {
|
||||||
final String input = Terminal.readLine();
|
final String input = Terminal.readLine();
|
||||||
if (input == null) {
|
if (input == null || input.startsWith("#")) {
|
||||||
break; // TODO remove
|
break; // TODO remove
|
||||||
}
|
}
|
||||||
if (input.startsWith("#")) {
|
|
||||||
continue; // TODO remove
|
|
||||||
}
|
|
||||||
|
|
||||||
if (input.equals(EXIT)) {
|
if (input.equals(EXIT)) {
|
||||||
break;
|
break;
|
||||||
@ -30,7 +28,6 @@ public class CommandLine {
|
|||||||
|
|
||||||
final Command command;
|
final Command command;
|
||||||
try {
|
try {
|
||||||
//Terminal.printLine("> " + input);
|
|
||||||
command = CommandFactory.getCommand(input);
|
command = CommandFactory.getCommand(input);
|
||||||
} catch (NumberFormatException e) {
|
} catch (NumberFormatException e) {
|
||||||
Terminal.printError("number too big");
|
Terminal.printError("number too big");
|
||||||
|
@ -11,10 +11,10 @@ public class ModelRailwaySimulation {
|
|||||||
private List<Train> trains = new ArrayList<>();
|
private List<Train> trains = new ArrayList<>();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Identifier if success, -1 if fail
|
* Add a new track to the rail network of this simulation.
|
||||||
* @param start
|
* @param start start position of the new track
|
||||||
* @param end
|
* @param end end position of the new track
|
||||||
* @return
|
* @return the positive identifier of the new track if successful, -1 otherwise
|
||||||
*/
|
*/
|
||||||
public int addTrack(final Vector2D start, final Vector2D end) {
|
public int addTrack(final Vector2D start, final Vector2D end) {
|
||||||
if (start.distanceTo(end) == 0) {
|
if (start.distanceTo(end) == 0) {
|
||||||
@ -46,11 +46,11 @@ public class ModelRailwaySimulation {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* -1 if fail
|
* Add a switch to the rail network of this simulation.
|
||||||
* @param start
|
* @param start start point of the switch
|
||||||
* @param end1
|
* @param end1 end position 1 of the switch
|
||||||
* @param end2
|
* @param end2 end position 2 of the switch
|
||||||
* @return
|
* @return the positive identifier of the switch if successful, -1 otherwise
|
||||||
*/
|
*/
|
||||||
public int addSwitch(final Vector2D start, final Vector2D end1, final Vector2D end2) {
|
public int addSwitch(final Vector2D start, final Vector2D end1, final Vector2D end2) {
|
||||||
if (start.distanceTo(end1) == 0 || start.distanceTo(end2) == 0 || end1.distanceTo(end2) == 0) {
|
if (start.distanceTo(end1) == 0 || start.distanceTo(end2) == 0 || end1.distanceTo(end2) == 0) {
|
||||||
@ -97,9 +97,9 @@ public class ModelRailwaySimulation {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* true success, false fail
|
* Remove the specified rail from the rail network.
|
||||||
* @param id
|
* @param id identifier of the rail to remove
|
||||||
* @return
|
* @return true if rail could be successfully removed, false otherwise
|
||||||
*/
|
*/
|
||||||
public boolean removeRail(final int id) {
|
public boolean removeRail(final int id) {
|
||||||
if (rails.size() == 0) {
|
if (rails.size() == 0) {
|
||||||
@ -168,10 +168,10 @@ public class ModelRailwaySimulation {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* true success, false fail
|
* Change the setting of a switch in the rail network.
|
||||||
* @param id
|
* @param id identifier of the switch
|
||||||
* @param position
|
* @param position position to set the switch to
|
||||||
* @return
|
* @return whether the switch could be set
|
||||||
*/
|
*/
|
||||||
public boolean setSwitch(int id, Vector2D position) {
|
public boolean setSwitch(int id, Vector2D position) {
|
||||||
// TODO Falls Gleiseweichen auf denen ein Zug bereitssteht, geschaltet werden, entgleist der daraufstehende Zug
|
// TODO Falls Gleiseweichen auf denen ein Zug bereitssteht, geschaltet werden, entgleist der daraufstehende Zug
|
||||||
@ -184,9 +184,8 @@ public class ModelRailwaySimulation {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* true success, false fail
|
* @param newEngine the engine to add to the simulation
|
||||||
* @param newEngine
|
* @return whether adding this engine was successful
|
||||||
* @return
|
|
||||||
*/
|
*/
|
||||||
public boolean createEngine(final Engine newEngine) {
|
public boolean createEngine(final Engine newEngine) {
|
||||||
String id = newEngine.getIdentifier();
|
String id = newEngine.getIdentifier();
|
||||||
@ -223,8 +222,12 @@ public class ModelRailwaySimulation {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* positive success, -1 fail
|
* Add a new coach to the simulation.
|
||||||
* @return
|
* @param coachType type of the coach
|
||||||
|
* @param length length of the coach
|
||||||
|
* @param couplingFront whether the coach should have a front coupling
|
||||||
|
* @param couplingBack whether the coach should have a back coupling
|
||||||
|
* @return the identifier of the coach if successfully added, -1 otherwise
|
||||||
*/
|
*/
|
||||||
public int createCoach(final CoachType coachType, final int length,
|
public int createCoach(final CoachType coachType, final int length,
|
||||||
final boolean couplingFront, final boolean couplingBack) {
|
final boolean couplingFront, final boolean couplingBack) {
|
||||||
@ -267,9 +270,9 @@ public class ModelRailwaySimulation {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* true success, false fail
|
* Add a new train set to the simulation.
|
||||||
* @param newTrainSet
|
* @param newTrainSet the train set to add
|
||||||
* @return
|
* @return true if the train set was successfully added, false otherwise
|
||||||
*/
|
*/
|
||||||
public boolean createTrainSet(final TrainSet newTrainSet) {
|
public boolean createTrainSet(final TrainSet newTrainSet) {
|
||||||
String id = newTrainSet.getIdentifier();
|
String id = newTrainSet.getIdentifier();
|
||||||
@ -305,9 +308,9 @@ public class ModelRailwaySimulation {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* true success, false fail
|
* Delete a rolling stock.
|
||||||
* @param id
|
* @param id identifier of the rolling stock to remove
|
||||||
* @return
|
* @return whether the rolling was successfully removed
|
||||||
*/
|
*/
|
||||||
public boolean deleteRollingStock(String id) {
|
public boolean deleteRollingStock(String id) {
|
||||||
RollingStock rollingStock = getRollingStock(id);
|
RollingStock rollingStock = getRollingStock(id);
|
||||||
@ -422,11 +425,11 @@ public class ModelRailwaySimulation {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* true success, false fail
|
* Put a train on the rail network.
|
||||||
* @param trainId
|
* @param trainId identifier of the train to place
|
||||||
* @param position
|
* @param position where to place the train
|
||||||
* @param rawDirection
|
* @param rawDirection direction in which the train should initially go
|
||||||
* @return
|
* @return whether the train was successfully placed
|
||||||
*/
|
*/
|
||||||
public boolean putTrain(final int trainId, final Vector2D position, final Vector2D rawDirection) {
|
public boolean putTrain(final int trainId, final Vector2D position, final Vector2D rawDirection) {
|
||||||
final Vector2D direction = rawDirection.normalized();
|
final Vector2D direction = rawDirection.normalized();
|
||||||
|
@ -7,7 +7,14 @@ package edu.kit.informatik;
|
|||||||
* @version 1.0
|
* @version 1.0
|
||||||
*/
|
*/
|
||||||
public abstract class Rail {
|
public abstract class Rail {
|
||||||
protected int id;
|
/**
|
||||||
|
* Unique identifier of this rail.
|
||||||
|
*/
|
||||||
|
protected final int id;
|
||||||
|
|
||||||
|
protected Rail(final int id) {
|
||||||
|
this.id = id;
|
||||||
|
}
|
||||||
|
|
||||||
public int getIdentifier() {
|
public int getIdentifier() {
|
||||||
return this.id;
|
return this.id;
|
||||||
@ -32,9 +39,9 @@ public abstract class Rail {
|
|||||||
public abstract boolean canConnectToRail(Rail rail);
|
public abstract boolean canConnectToRail(Rail rail);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* true success, false fail
|
* Try to set the rail to connect to this position. Obviously only makes sense for switches and similar rails.
|
||||||
* @param position
|
* @param position point to connect to
|
||||||
* @return
|
* @return whether rail could be successfully set
|
||||||
*/
|
*/
|
||||||
public abstract boolean switchTo(Vector2D position);
|
public abstract boolean switchTo(Vector2D position);
|
||||||
|
|
||||||
|
@ -1,8 +1,23 @@
|
|||||||
package edu.kit.informatik;
|
package edu.kit.informatik;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A rolling stock. Is usually an engine, train set or coach.
|
||||||
|
*
|
||||||
|
* @author Arne Keller
|
||||||
|
* @version 1.0
|
||||||
|
*/
|
||||||
public abstract class RollingStock {
|
public abstract class RollingStock {
|
||||||
|
/**
|
||||||
|
* Length of this rolling stock.
|
||||||
|
*/
|
||||||
protected int length;
|
protected int length;
|
||||||
|
/**
|
||||||
|
* Whether this rolling stock has a front coupling.
|
||||||
|
*/
|
||||||
protected boolean couplingFront;
|
protected boolean couplingFront;
|
||||||
|
/**
|
||||||
|
* Whether this rolling stack has a back coupling.
|
||||||
|
*/
|
||||||
protected boolean couplingBack;
|
protected boolean couplingBack;
|
||||||
|
|
||||||
public abstract String getIdentifier();
|
public abstract String getIdentifier();
|
||||||
|
@ -35,6 +35,7 @@ public final class Switch extends Rail {
|
|||||||
* @throws IllegalArgumentException if the switch is not composed of straight lines
|
* @throws IllegalArgumentException if the switch is not composed of straight lines
|
||||||
*/
|
*/
|
||||||
public Switch(Vector2D start, Vector2D end1, Vector2D end2, int id) throws IllegalArgumentException {
|
public Switch(Vector2D start, Vector2D end1, Vector2D end2, int id) throws IllegalArgumentException {
|
||||||
|
super(id);
|
||||||
if (start.getX() != end1.getX() && start.getY() != end1.getY()
|
if (start.getX() != end1.getX() && start.getY() != end1.getY()
|
||||||
|| start.getX() != end2.getX() && start.getY() != end2.getY()) {
|
|| start.getX() != end2.getX() && start.getY() != end2.getY()) {
|
||||||
throw new IllegalArgumentException("start has to be connected in straight lines to end positions!");
|
throw new IllegalArgumentException("start has to be connected in straight lines to end positions!");
|
||||||
@ -42,7 +43,6 @@ public final class Switch extends Rail {
|
|||||||
this.start = start;
|
this.start = start;
|
||||||
this.end1 = end1;
|
this.end1 = end1;
|
||||||
this.end2 = end2;
|
this.end2 = end2;
|
||||||
super.id = id;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -20,12 +20,12 @@ public final class Track extends Rail {
|
|||||||
* @throws IllegalArgumentException if the positions are not on a straight line
|
* @throws IllegalArgumentException if the positions are not on a straight line
|
||||||
*/
|
*/
|
||||||
public Track(final Vector2D start, final Vector2D end, final int id) throws IllegalArgumentException {
|
public Track(final Vector2D start, final Vector2D end, final int id) throws IllegalArgumentException {
|
||||||
|
super(id);
|
||||||
if (start.getX() != end.getX() && start.getY() != end.getY()) {
|
if (start.getX() != end.getX() && start.getY() != end.getY()) {
|
||||||
throw new IllegalArgumentException("start and end have to be in a straight line!");
|
throw new IllegalArgumentException("start and end have to be in a straight line!");
|
||||||
}
|
}
|
||||||
this.start = start;
|
this.start = start;
|
||||||
this.end = end;
|
this.end = end;
|
||||||
super.id = id;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -34,9 +34,9 @@ public final class Train {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* true success, false fail
|
* Add a rolling stock to this train.
|
||||||
* @param rollingStock
|
* @param rollingStock the rolling stack to add
|
||||||
* @return
|
* @return whether the modification was successful
|
||||||
*/
|
*/
|
||||||
public boolean add(RollingStock rollingStock) {
|
public boolean add(RollingStock rollingStock) {
|
||||||
if (rollingStock.canCoupleFrontTo(rollingStocks.get(rollingStocks.size() - 1))) {
|
if (rollingStock.canCoupleFrontTo(rollingStocks.get(rollingStocks.size() - 1))) {
|
||||||
|
@ -82,7 +82,8 @@ public class CommandFactory {
|
|||||||
Vector2D start = Vector2D.parse(matcher.group(1));
|
Vector2D start = Vector2D.parse(matcher.group(1));
|
||||||
Vector2D end1 = Vector2D.parse(matcher.group(2));
|
Vector2D end1 = Vector2D.parse(matcher.group(2));
|
||||||
Vector2D end2 = Vector2D.parse(matcher.group(3));
|
Vector2D end2 = Vector2D.parse(matcher.group(3));
|
||||||
if ((start.getX() == end1.getX() || start.getY() == end1.getY()) && (start.getX() == end2.getX() || start.getY() == end2.getY())) {
|
if ((start.getX() == end1.getX() || start.getY() == end1.getY())
|
||||||
|
&& (start.getX() == end2.getX() || start.getY() == end2.getY())) {
|
||||||
return new AddSwitch(start, end1, end2);
|
return new AddSwitch(start, end1, end2);
|
||||||
} else {
|
} else {
|
||||||
throw new InvalidInputException("switch rails have to be straight lines");
|
throw new InvalidInputException("switch rails have to be straight lines");
|
||||||
|
Loading…
Reference in New Issue
Block a user