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
036847553d
commit
4fd72ebe43
@ -4,6 +4,8 @@ import edu.kit.informatik.ui.InvalidInputException;
|
||||
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import static edu.kit.informatik.ui.command.CommandFactory.NUMBER;
|
||||
|
||||
/**
|
||||
* A coach.
|
||||
*
|
||||
@ -16,21 +18,22 @@ public abstract class Coach extends RollingStock {
|
||||
*/
|
||||
public static final String IDENTIFIER_PREFIX = "W";
|
||||
/**
|
||||
* Regex pattern to match coach identifiers.
|
||||
* Pattern to match a single coach identifier.
|
||||
*/
|
||||
public static final Pattern IDENTIFIER_PATTERN = Pattern.compile(IDENTIFIER_PREFIX + "\\+?\\d+");
|
||||
public static final Pattern IDENTIFIER_PATTERN = Pattern.compile(IDENTIFIER_PREFIX + NUMBER);
|
||||
/**
|
||||
* Regex pattern to match coach type (passenger, freight, or special).
|
||||
* Pattern to match coach type (passenger, freight, or special).
|
||||
*/
|
||||
public static final String COACH_TYPE = "passenger|freight|special";
|
||||
|
||||
/**
|
||||
* The unique identifier of this coach.
|
||||
* The (unique) identifier of this coach.
|
||||
*/
|
||||
private final int identifier;
|
||||
|
||||
/**
|
||||
* Construct a new coach.
|
||||
*
|
||||
* @param identifier identifier to use
|
||||
* @param length length of coach
|
||||
* @param couplingFront whether the coach should have a front coupling
|
||||
@ -42,6 +45,11 @@ public abstract class Coach extends RollingStock {
|
||||
this.identifier = identifier;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the textual identifier of this coach in this format: [PREFIX][NUMERICAL_IDENTIFIER].
|
||||
*
|
||||
* @return the textual identifier of this coach
|
||||
*/
|
||||
@Override
|
||||
public String getIdentifier() {
|
||||
return String.format("%s%d", IDENTIFIER_PREFIX, identifier);
|
||||
@ -70,6 +78,8 @@ public abstract class Coach extends RollingStock {
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the type of this coach ("p" for passenger, "f" for freight, "s" for special).
|
||||
*
|
||||
* @return abbreviation of the type of this coach
|
||||
*/
|
||||
public abstract String getType();
|
||||
|
@ -23,6 +23,7 @@ public class DieselEngine extends Engine {
|
||||
|
||||
/**
|
||||
* Construct a new diesel engine.
|
||||
*
|
||||
* @param series series/class of engine
|
||||
* @param name name of engine
|
||||
* @param length length of engine
|
||||
@ -36,9 +37,8 @@ public class DieselEngine extends Engine {
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return String.format("d %s %s %d %b %b", getSeries(), getName(), getLength(),
|
||||
hasCouplingFront(), hasCouplingBack());
|
||||
public String getType() {
|
||||
return "d";
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -25,6 +25,7 @@ public class ElectricalEngine extends Engine {
|
||||
|
||||
/**
|
||||
* Construct a new electrical engine.
|
||||
*
|
||||
* @param series series/class of engine
|
||||
* @param name name of engine
|
||||
* @param length length of engine
|
||||
@ -32,15 +33,14 @@ public class ElectricalEngine extends Engine {
|
||||
* @param couplingBack whether the engine should have a back coupling
|
||||
* @throws InvalidInputException on invalid user input (e.g. zero-sized engine)
|
||||
*/
|
||||
public ElectricalEngine(String series, String name, int length,
|
||||
boolean couplingFront, boolean couplingBack) throws InvalidInputException {
|
||||
public ElectricalEngine(String series, String name, int length, boolean couplingFront, boolean couplingBack)
|
||||
throws InvalidInputException {
|
||||
super(series, name, length, couplingFront, couplingBack);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return String.format("e %s %s %d %b %b", getSeries(), getName(), getLength(),
|
||||
hasCouplingFront(), hasCouplingBack());
|
||||
public String getType() {
|
||||
return "e";
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -20,6 +20,7 @@ public abstract class Engine extends RollingStock {
|
||||
|
||||
/**
|
||||
* Initialize an engine.
|
||||
*
|
||||
* @param series series/class of this engine
|
||||
* @param name name of this engine
|
||||
* @param length length of this engine
|
||||
@ -67,4 +68,23 @@ public abstract class Engine extends RollingStock {
|
||||
public boolean usefulAtBackOfTrain() {
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the type of this engine ("s" for steam, "d" for diesel, "e" for electrical).
|
||||
*
|
||||
* @return abbreviation of the type of this engine
|
||||
*/
|
||||
public abstract String getType();
|
||||
|
||||
/**
|
||||
* Get the textual representation of this engine in the format:
|
||||
* [type] [series] [name] [length] [couplingFront] [couplingBack]
|
||||
*
|
||||
* @return textual representation of the engine
|
||||
*/
|
||||
@Override
|
||||
public String toString() {
|
||||
return String.format("%s %s %s %d %b %b", getType(), getSeries(), getName(), getLength(),
|
||||
hasCouplingFront(), hasCouplingBack());
|
||||
}
|
||||
}
|
||||
|
@ -22,11 +22,12 @@ public class FreightCoach extends Coach {
|
||||
|
||||
/**
|
||||
* Construct a new freight coach.
|
||||
*
|
||||
* @param identifier identifier to use
|
||||
* @param length length of coach
|
||||
* @param couplingFront whether the coach should have a front coupling
|
||||
* @param couplingBack whether the coach should have a back coupling
|
||||
* @throws InvalidInputException on invalid user input (zero-sized coach)
|
||||
* @throws InvalidInputException on invalid user input (e.g. zero-sized coach)
|
||||
*/
|
||||
public FreightCoach(int identifier, int length, boolean couplingFront, boolean couplingBack)
|
||||
throws InvalidInputException {
|
||||
|
@ -45,6 +45,7 @@ public class ModelRailwaySimulation {
|
||||
|
||||
/**
|
||||
* 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 if none available
|
||||
@ -56,6 +57,7 @@ public class ModelRailwaySimulation {
|
||||
|
||||
/**
|
||||
* 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
|
||||
@ -90,6 +92,7 @@ public class ModelRailwaySimulation {
|
||||
|
||||
/**
|
||||
* 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
|
||||
@ -132,6 +135,7 @@ public class ModelRailwaySimulation {
|
||||
|
||||
/**
|
||||
* 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
|
||||
@ -163,6 +167,7 @@ public class ModelRailwaySimulation {
|
||||
|
||||
/**
|
||||
* Calculate the next coach identifier.
|
||||
*
|
||||
* @return the next coach identifier, or -1 if none available
|
||||
*/
|
||||
private int getNextCoachIdentifier() {
|
||||
@ -189,6 +194,7 @@ public class ModelRailwaySimulation {
|
||||
|
||||
/**
|
||||
* Add a new train set to the simulation.
|
||||
*
|
||||
* @param newTrainSet the train set to add
|
||||
* @throws InvalidInputException if the identifier is already used
|
||||
*/
|
||||
@ -218,6 +224,7 @@ public class ModelRailwaySimulation {
|
||||
|
||||
/**
|
||||
* Delete a rolling stock.
|
||||
*
|
||||
* @param id identifier of the rolling stock to remove
|
||||
* @return whether the rolling was successfully removed
|
||||
*/
|
||||
@ -270,6 +277,7 @@ public class ModelRailwaySimulation {
|
||||
|
||||
/**
|
||||
* Delete a train.
|
||||
*
|
||||
* @param id identifier of the train
|
||||
* @return whether the train could be deleted
|
||||
*/
|
||||
@ -298,6 +306,7 @@ public class ModelRailwaySimulation {
|
||||
|
||||
/**
|
||||
* Get the ASCII art representation of a train.
|
||||
*
|
||||
* @param id identifier of the train to show
|
||||
* @return rows of ASCII art representing this train
|
||||
* @throws InvalidInputException if train not found
|
||||
@ -308,6 +317,7 @@ public class ModelRailwaySimulation {
|
||||
|
||||
/**
|
||||
* Put a train on the rail network.
|
||||
*
|
||||
* @param trainId identifier of the train to place
|
||||
* @param position where to place the train
|
||||
* @param direction direction in which the train should initially go
|
||||
|
@ -23,11 +23,12 @@ public class PassengerCoach extends Coach {
|
||||
|
||||
/**
|
||||
* Construct a new passenger coach.
|
||||
*
|
||||
* @param identifier identifier to use
|
||||
* @param length length of coach
|
||||
* @param couplingFront whether the coach should have a front coupling
|
||||
* @param couplingBack whether the coach should have a back coupling
|
||||
* @throws InvalidInputException on invalid user input (zero-sized coach)
|
||||
* @throws InvalidInputException on invalid user input (e.g. zero-sized coach)
|
||||
*/
|
||||
public PassengerCoach(int identifier, int length, boolean couplingFront, boolean couplingBack)
|
||||
throws InvalidInputException {
|
||||
|
@ -14,6 +14,7 @@ public abstract class Rail {
|
||||
|
||||
/**
|
||||
* Initialize a new rail with the specified identifier.
|
||||
*
|
||||
* @param id the identifier of this rail
|
||||
*/
|
||||
protected Rail(int id) {
|
||||
@ -47,7 +48,7 @@ public abstract class Rail {
|
||||
public abstract boolean canConnectTo(Vector2D point);
|
||||
|
||||
/**
|
||||
* @param rail rail to check for connection
|
||||
* @param rail rail to check for possible connection
|
||||
* @return whether this rail can connect to the specified rail
|
||||
*/
|
||||
public abstract boolean canConnectToRail(Rail rail);
|
||||
@ -60,6 +61,7 @@ public abstract class Rail {
|
||||
|
||||
/**
|
||||
* 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
|
||||
*/
|
||||
|
@ -27,6 +27,7 @@ public class RailwayNetwork {
|
||||
|
||||
/**
|
||||
* Add a new track to the rail network.
|
||||
*
|
||||
* @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 if none available
|
||||
@ -63,6 +64,7 @@ public class RailwayNetwork {
|
||||
|
||||
/**
|
||||
* Add a switch to the rail network.
|
||||
*
|
||||
* @param start start point of the switch
|
||||
* @param end1 end position 1 of the switch
|
||||
* @param end2 end position 2 of the switch
|
||||
@ -101,6 +103,7 @@ public class RailwayNetwork {
|
||||
|
||||
/**
|
||||
* Get the rail with the specified identifier.
|
||||
*
|
||||
* @param id rail identifier to get
|
||||
* @return the rail
|
||||
*/
|
||||
@ -110,6 +113,7 @@ public class RailwayNetwork {
|
||||
|
||||
/**
|
||||
* Remove the specified rail from the rail network.
|
||||
*
|
||||
* @param id identifier of the rail to remove
|
||||
* @return whether the rail could be successfully removed
|
||||
*/
|
||||
@ -162,6 +166,7 @@ public class RailwayNetwork {
|
||||
|
||||
/**
|
||||
* 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
|
||||
@ -288,6 +293,7 @@ public class RailwayNetwork {
|
||||
|
||||
/**
|
||||
* Find all rails that *touch* (not contain) this position.
|
||||
*
|
||||
* @param position the position to check
|
||||
* @return the rail(s) that touch this position
|
||||
*/
|
||||
@ -297,6 +303,7 @@ public class RailwayNetwork {
|
||||
|
||||
/**
|
||||
* Check whether the rail network is ready for trains (all switches set, etc.).
|
||||
*
|
||||
* @return whether the rail network is ready
|
||||
*/
|
||||
public boolean isReadyForTrains() {
|
||||
|
@ -43,8 +43,6 @@ public abstract class RollingStock {
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the identifier of this rolling stock.
|
||||
*
|
||||
* @return identifier of this rolling stock
|
||||
*/
|
||||
public abstract String getIdentifier();
|
||||
@ -71,18 +69,21 @@ public abstract class RollingStock {
|
||||
}
|
||||
|
||||
/**
|
||||
* Check whether this rolling stock can theoretically couple to another rolling stock. This method will not check
|
||||
* whether the other rolling stock has special coupling requirements.
|
||||
*
|
||||
* @param rollingStock other rolling stock
|
||||
* @return whether this rolling stock can couple to the other rolling stock
|
||||
*/
|
||||
public abstract boolean canCoupleTo(RollingStock rollingStock);
|
||||
|
||||
/**
|
||||
* @return whether this rolling stock is useful at the front end of a train
|
||||
* @return whether this rolling stock is useful at the front of a train
|
||||
*/
|
||||
public abstract boolean usefulAtFrontOfTrain();
|
||||
|
||||
/**
|
||||
* @return whether this rolling stock is useful at the rear end of a train
|
||||
* @return whether this rolling stock is useful at the back of a train
|
||||
*/
|
||||
public abstract boolean usefulAtBackOfTrain();
|
||||
|
||||
|
@ -24,11 +24,12 @@ public class SpecialCoach extends Coach {
|
||||
|
||||
/**
|
||||
* Construct a new special coach.
|
||||
*
|
||||
* @param identifier identifier to use
|
||||
* @param length length of coach
|
||||
* @param couplingFront whether the coach should have a front coupling
|
||||
* @param couplingBack whether the coach should have a back coupling
|
||||
* @throws InvalidInputException on invalid user input (zero-sized coach)
|
||||
* @throws InvalidInputException on invalid user input (e.g. zero-sized coach)
|
||||
*/
|
||||
public SpecialCoach(int identifier, int length, boolean couplingFront, boolean couplingBack)
|
||||
throws InvalidInputException {
|
||||
|
@ -23,6 +23,7 @@ public class SteamEngine extends Engine {
|
||||
|
||||
/**
|
||||
* Construct a new steam engine.
|
||||
*
|
||||
* @param series series/class of engine
|
||||
* @param name name of engine
|
||||
* @param length length of engine
|
||||
@ -36,9 +37,8 @@ public class SteamEngine extends Engine {
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return String.format("s %s %s %d %b %b", getSeries(), getName(), getLength(),
|
||||
hasCouplingFront(), hasCouplingBack());
|
||||
public String getType() {
|
||||
return "s";
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -20,7 +20,7 @@ public final class Switch extends Rail {
|
||||
*/
|
||||
private final Track positionTwo;
|
||||
/**
|
||||
* Currently selected position (either one or two).
|
||||
* Currently selected position (either {@link #positionOne} or {@link #positionTwo}).
|
||||
*/
|
||||
private Track selection;
|
||||
|
||||
@ -44,11 +44,19 @@ public final class Switch extends Rail {
|
||||
return positionOne.canConnectTo(point) || positionTwo.canConnectTo(point);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param point point to check for connection
|
||||
* @return whether the currently active configuration connects to the position
|
||||
*/
|
||||
@Override
|
||||
public boolean connectsTo(Vector2D point) {
|
||||
return selection != null && selection.canConnectTo(point);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param rail rail to check for possible connection
|
||||
* @return whether any of the configurations can connect to the position
|
||||
*/
|
||||
@Override
|
||||
public boolean canConnectToRail(Rail rail) {
|
||||
return rail.canConnectToRail(positionOne) || rail.canConnectToRail(positionTwo);
|
||||
@ -66,11 +74,18 @@ public final class Switch extends Rail {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return whether this switch is set
|
||||
*/
|
||||
@Override
|
||||
public boolean isReadyForTrains() {
|
||||
return selection != null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param position the point to check
|
||||
* @return whether the active switch configuration contains that position
|
||||
*/
|
||||
@Override
|
||||
public boolean contains(Vector2D position) {
|
||||
return selection != null && selection.contains(position);
|
||||
@ -101,6 +116,9 @@ public final class Switch extends Rail {
|
||||
|| positionTwo.allowsMovement(position, direction);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return length of the current configuration
|
||||
*/
|
||||
@Override
|
||||
public long getLength() {
|
||||
return selection.getLength();
|
||||
|
@ -33,7 +33,7 @@ public final class Train implements Comparable<Train> {
|
||||
/**
|
||||
* List of positions this train occupies. More specifically, it only contains:
|
||||
* the position of the front of the train, any positions on rail connections, the position of the back of the train
|
||||
*
|
||||
* <p>
|
||||
* This is a linked list because we only have to update
|
||||
* the positions at the start and end of the list when moving the train.
|
||||
*/
|
||||
@ -71,6 +71,7 @@ public final class Train implements Comparable<Train> {
|
||||
|
||||
/**
|
||||
* Add a rolling stock to this train.
|
||||
*
|
||||
* @param rollingStock the rolling stack to add
|
||||
* @throws InvalidInputException if the rolling stock could not be added to the train
|
||||
*/
|
||||
|
@ -34,6 +34,7 @@ public class TrainSet extends RollingStock {
|
||||
|
||||
/**
|
||||
* Construct a new train set.
|
||||
*
|
||||
* @param series series/class of train set
|
||||
* @param name name of train set
|
||||
* @param length length of train set
|
||||
|
@ -20,6 +20,7 @@ public class Vector2D {
|
||||
|
||||
/**
|
||||
* Construct a new vector.
|
||||
*
|
||||
* @param x first component
|
||||
* @param y second component
|
||||
*/
|
||||
@ -30,6 +31,7 @@ public class Vector2D {
|
||||
|
||||
/**
|
||||
* Copy a vector, creating a new object.
|
||||
*
|
||||
* @param other a vector
|
||||
*/
|
||||
public Vector2D(Vector2D other) {
|
||||
@ -123,6 +125,7 @@ public class Vector2D {
|
||||
|
||||
/**
|
||||
* Subtract another vector from this one.
|
||||
*
|
||||
* @param other another vector
|
||||
* @return the difference of this vector and the other vector
|
||||
*/
|
||||
|
@ -22,6 +22,7 @@ public enum CoachType {
|
||||
|
||||
/**
|
||||
* Parse the textual representation of a coach type into the correct enum value.
|
||||
*
|
||||
* @param value coach type as text
|
||||
* @return coach type as enum, or null if invalid
|
||||
*/
|
||||
|
@ -22,6 +22,7 @@ public enum EngineType {
|
||||
|
||||
/**
|
||||
* Parse the textual representation of a engine type into the correct enum value.
|
||||
*
|
||||
* @param value engine type as text
|
||||
* @return engine type as enum, or null if invalid
|
||||
*/
|
||||
|
@ -9,6 +9,7 @@ package edu.kit.informatik.ui;
|
||||
public class InvalidInputException extends Exception {
|
||||
/**
|
||||
* Construct a new invalid input exception with a specific message.
|
||||
*
|
||||
* @param message the error message
|
||||
*/
|
||||
public InvalidInputException(String message) {
|
||||
|
@ -13,6 +13,7 @@ import edu.kit.informatik.ui.InvalidInputException;
|
||||
public abstract class Command {
|
||||
/**
|
||||
* Apply this command to a model railway simulation.
|
||||
*
|
||||
* @param simulation simulation to use
|
||||
* @throws InvalidInputException on invalid user input
|
||||
*/
|
||||
@ -20,6 +21,7 @@ public abstract class Command {
|
||||
|
||||
/**
|
||||
* Parse user input into this command object.
|
||||
*
|
||||
* @param input one line of user input
|
||||
* @throws InvalidInputException if user input is in any way invalid
|
||||
*/
|
||||
|
@ -14,6 +14,10 @@ import java.util.function.Supplier;
|
||||
* @version 1.0
|
||||
*/
|
||||
public final class CommandFactory {
|
||||
/**
|
||||
* Regex to accept one boolean (true or false).
|
||||
*/
|
||||
public static final String BOOL = "true|false";
|
||||
/**
|
||||
* Regex to match a number, accepting leading plus sign and zeros.
|
||||
*/
|
||||
@ -31,10 +35,6 @@ public final class CommandFactory {
|
||||
*/
|
||||
public static final String ROLLING_STOCK_IDENTIFIER
|
||||
= "(" + ALPHANUMERIC_WORD + "-" + ALPHANUMERIC_WORD + ")|" + Coach.IDENTIFIER_PATTERN;
|
||||
/**
|
||||
* Regex to accept one boolean (true or false).
|
||||
*/
|
||||
public static final String BOOL = "true|false";
|
||||
|
||||
/**
|
||||
* Name of the add track command.
|
||||
@ -142,6 +142,7 @@ public final class CommandFactory {
|
||||
|
||||
/**
|
||||
* Parse a single line of user input into one command.
|
||||
*
|
||||
* @param input user input line
|
||||
* @return a fully specified command object
|
||||
* @throws InvalidInputException if user input is invalid
|
||||
|
Loading…
Reference in New Issue
Block a user