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";
|
||||
|
||||
public static void startInteractive() {
|
||||
// create a new simulation
|
||||
ModelRailwaySimulation simulation = new ModelRailwaySimulation();
|
||||
|
||||
while (true) {
|
||||
final String input = Terminal.readLine();
|
||||
if (input == null) {
|
||||
if (input == null || input.startsWith("#")) {
|
||||
break; // TODO remove
|
||||
}
|
||||
if (input.startsWith("#")) {
|
||||
continue; // TODO remove
|
||||
}
|
||||
|
||||
if (input.equals(EXIT)) {
|
||||
break;
|
||||
@ -30,7 +28,6 @@ public class CommandLine {
|
||||
|
||||
final Command command;
|
||||
try {
|
||||
//Terminal.printLine("> " + input);
|
||||
command = CommandFactory.getCommand(input);
|
||||
} catch (NumberFormatException e) {
|
||||
Terminal.printError("number too big");
|
||||
|
@ -11,10 +11,10 @@ public class ModelRailwaySimulation {
|
||||
private List<Train> trains = new ArrayList<>();
|
||||
|
||||
/**
|
||||
* Identifier if success, -1 if fail
|
||||
* @param start
|
||||
* @param end
|
||||
* @return
|
||||
* Add a new track to the rail network of this simulation.
|
||||
* @param start start position of the new track
|
||||
* @param end end position of the new track
|
||||
* @return the positive identifier of the new track if successful, -1 otherwise
|
||||
*/
|
||||
public int addTrack(final Vector2D start, final Vector2D end) {
|
||||
if (start.distanceTo(end) == 0) {
|
||||
@ -46,11 +46,11 @@ public class ModelRailwaySimulation {
|
||||
}
|
||||
|
||||
/**
|
||||
* -1 if fail
|
||||
* @param start
|
||||
* @param end1
|
||||
* @param end2
|
||||
* @return
|
||||
* Add a switch to the rail network of this simulation.
|
||||
* @param start start point of the switch
|
||||
* @param end1 end position 1 of the switch
|
||||
* @param end2 end position 2 of the switch
|
||||
* @return the positive identifier of the switch if successful, -1 otherwise
|
||||
*/
|
||||
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) {
|
||||
@ -97,9 +97,9 @@ public class ModelRailwaySimulation {
|
||||
}
|
||||
|
||||
/**
|
||||
* true success, false fail
|
||||
* @param id
|
||||
* @return
|
||||
* Remove the specified rail from the rail network.
|
||||
* @param id identifier of the rail to remove
|
||||
* @return true if rail could be successfully removed, false otherwise
|
||||
*/
|
||||
public boolean removeRail(final int id) {
|
||||
if (rails.size() == 0) {
|
||||
@ -168,10 +168,10 @@ public class ModelRailwaySimulation {
|
||||
}
|
||||
|
||||
/**
|
||||
* true success, false fail
|
||||
* @param id
|
||||
* @param position
|
||||
* @return
|
||||
* Change the setting of a switch in the rail network.
|
||||
* @param id identifier of the switch
|
||||
* @param position position to set the switch to
|
||||
* @return whether the switch could be set
|
||||
*/
|
||||
public boolean setSwitch(int id, Vector2D position) {
|
||||
// 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
|
||||
* @return
|
||||
* @param newEngine the engine to add to the simulation
|
||||
* @return whether adding this engine was successful
|
||||
*/
|
||||
public boolean createEngine(final Engine newEngine) {
|
||||
String id = newEngine.getIdentifier();
|
||||
@ -223,8 +222,12 @@ public class ModelRailwaySimulation {
|
||||
}
|
||||
|
||||
/**
|
||||
* positive success, -1 fail
|
||||
* @return
|
||||
* Add a new coach to the simulation.
|
||||
* @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,
|
||||
final boolean couplingFront, final boolean couplingBack) {
|
||||
@ -267,9 +270,9 @@ public class ModelRailwaySimulation {
|
||||
}
|
||||
|
||||
/**
|
||||
* true success, false fail
|
||||
* @param newTrainSet
|
||||
* @return
|
||||
* Add a new train set to the simulation.
|
||||
* @param newTrainSet the train set to add
|
||||
* @return true if the train set was successfully added, false otherwise
|
||||
*/
|
||||
public boolean createTrainSet(final TrainSet newTrainSet) {
|
||||
String id = newTrainSet.getIdentifier();
|
||||
@ -305,9 +308,9 @@ public class ModelRailwaySimulation {
|
||||
}
|
||||
|
||||
/**
|
||||
* true success, false fail
|
||||
* @param id
|
||||
* @return
|
||||
* Delete a rolling stock.
|
||||
* @param id identifier of the rolling stock to remove
|
||||
* @return whether the rolling was successfully removed
|
||||
*/
|
||||
public boolean deleteRollingStock(String id) {
|
||||
RollingStock rollingStock = getRollingStock(id);
|
||||
@ -422,11 +425,11 @@ public class ModelRailwaySimulation {
|
||||
}
|
||||
|
||||
/**
|
||||
* true success, false fail
|
||||
* @param trainId
|
||||
* @param position
|
||||
* @param rawDirection
|
||||
* @return
|
||||
* Put a train on the rail network.
|
||||
* @param trainId identifier of the train to place
|
||||
* @param position where to place the train
|
||||
* @param rawDirection direction in which the train should initially go
|
||||
* @return whether the train was successfully placed
|
||||
*/
|
||||
public boolean putTrain(final int trainId, final Vector2D position, final Vector2D rawDirection) {
|
||||
final Vector2D direction = rawDirection.normalized();
|
||||
|
@ -7,7 +7,14 @@ package edu.kit.informatik;
|
||||
* @version 1.0
|
||||
*/
|
||||
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() {
|
||||
return this.id;
|
||||
@ -32,9 +39,9 @@ public abstract class Rail {
|
||||
public abstract boolean canConnectToRail(Rail rail);
|
||||
|
||||
/**
|
||||
* true success, false fail
|
||||
* @param position
|
||||
* @return
|
||||
* 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
|
||||
* @return whether rail could be successfully set
|
||||
*/
|
||||
public abstract boolean switchTo(Vector2D position);
|
||||
|
||||
|
@ -1,8 +1,23 @@
|
||||
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 {
|
||||
/**
|
||||
* Length of this rolling stock.
|
||||
*/
|
||||
protected int length;
|
||||
/**
|
||||
* Whether this rolling stock has a front coupling.
|
||||
*/
|
||||
protected boolean couplingFront;
|
||||
/**
|
||||
* Whether this rolling stack has a back coupling.
|
||||
*/
|
||||
protected boolean couplingBack;
|
||||
|
||||
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
|
||||
*/
|
||||
public Switch(Vector2D start, Vector2D end1, Vector2D end2, int id) throws IllegalArgumentException {
|
||||
super(id);
|
||||
if (start.getX() != end1.getX() && start.getY() != end1.getY()
|
||||
|| start.getX() != end2.getX() && start.getY() != end2.getY()) {
|
||||
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.end1 = end1;
|
||||
this.end2 = end2;
|
||||
super.id = id;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -20,12 +20,12 @@ public final class Track extends Rail {
|
||||
* @throws IllegalArgumentException if the positions are not on a straight line
|
||||
*/
|
||||
public Track(final Vector2D start, final Vector2D end, final int id) throws IllegalArgumentException {
|
||||
super(id);
|
||||
if (start.getX() != end.getX() && start.getY() != end.getY()) {
|
||||
throw new IllegalArgumentException("start and end have to be in a straight line!");
|
||||
}
|
||||
this.start = start;
|
||||
this.end = end;
|
||||
super.id = id;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -34,9 +34,9 @@ public final class Train {
|
||||
}
|
||||
|
||||
/**
|
||||
* true success, false fail
|
||||
* @param rollingStock
|
||||
* @return
|
||||
* Add a rolling stock to this train.
|
||||
* @param rollingStock the rolling stack to add
|
||||
* @return whether the modification was successful
|
||||
*/
|
||||
public boolean add(RollingStock rollingStock) {
|
||||
if (rollingStock.canCoupleFrontTo(rollingStocks.get(rollingStocks.size() - 1))) {
|
||||
|
@ -82,7 +82,8 @@ public class CommandFactory {
|
||||
Vector2D start = Vector2D.parse(matcher.group(1));
|
||||
Vector2D end1 = Vector2D.parse(matcher.group(2));
|
||||
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);
|
||||
} else {
|
||||
throw new InvalidInputException("switch rails have to be straight lines");
|
||||
|
Loading…
Reference in New Issue
Block a user