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
cb9c82ecdf
commit
49e2e65908
@ -1,10 +1,47 @@
|
||||
package edu.kit.informatik;
|
||||
|
||||
/**
|
||||
* A coach.
|
||||
*/
|
||||
public class Coach extends RollingStock {
|
||||
private static final String[] PASSENGER_TEXT = new String[] {
|
||||
"____________________",
|
||||
"| ___ ___ ___ ___ |",
|
||||
"| |_| |_| |_| |_| |",
|
||||
"|__________________|",
|
||||
"|__________________|",
|
||||
" (O) (O) "
|
||||
};
|
||||
private static final String[] FREIGHT_TEXT = new String[] {
|
||||
"| |",
|
||||
"| |",
|
||||
"| |",
|
||||
"|__________________|",
|
||||
" (O) (O) "
|
||||
};
|
||||
private static final String[] SPECIAL_TEXT = new String[] {
|
||||
" ____",
|
||||
"/--------------| |",
|
||||
"\\--------------| |",
|
||||
" | | | |",
|
||||
" _|_|__________| |",
|
||||
"|_________________|",
|
||||
" (O) (O) "
|
||||
};
|
||||
|
||||
private CoachType type;
|
||||
private int identifier;
|
||||
|
||||
public Coach(final int identifier, final CoachType type, final int length, final boolean couplingFront, final boolean couplingBack) {
|
||||
/**
|
||||
* Construct a new coach.
|
||||
* @param identifier identifier to use
|
||||
* @param type type of coach
|
||||
* @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
|
||||
*/
|
||||
public Coach(final int identifier, final CoachType type, final int length,
|
||||
final boolean couplingFront, final boolean couplingBack) {
|
||||
this.identifier = identifier;
|
||||
this.type = type;
|
||||
super.length = length;
|
||||
@ -36,31 +73,6 @@ public class Coach extends RollingStock {
|
||||
return type;
|
||||
}
|
||||
|
||||
private static final String[] PASSENGER_TEXT = new String[] {
|
||||
"____________________",
|
||||
"| ___ ___ ___ ___ |",
|
||||
"| |_| |_| |_| |_| |",
|
||||
"|__________________|",
|
||||
"|__________________|",
|
||||
" (O) (O) "
|
||||
};
|
||||
private static final String[] FREIGHT_TEXT = new String[] {
|
||||
"| |",
|
||||
"| |",
|
||||
"| |",
|
||||
"|__________________|",
|
||||
" (O) (O) "
|
||||
};
|
||||
private static final String[] SPECIAL_TEXT = new String[] {
|
||||
" ____",
|
||||
"/--------------| |",
|
||||
"\\--------------| |",
|
||||
" | | | |",
|
||||
" _|_|__________| |",
|
||||
"|_________________|",
|
||||
" (O) (O) "
|
||||
};
|
||||
|
||||
@Override
|
||||
public String[] textRepresentation() {
|
||||
switch (type) {
|
||||
|
@ -1,10 +1,30 @@
|
||||
package edu.kit.informatik;
|
||||
|
||||
/**
|
||||
* Type of a coach.
|
||||
*
|
||||
* @author Arne Keller
|
||||
* @version 1.0
|
||||
*/
|
||||
public enum CoachType {
|
||||
/**
|
||||
* Passenger coach.
|
||||
*/
|
||||
PASSENGER,
|
||||
/**
|
||||
* Freight coach.
|
||||
*/
|
||||
FREIGHT,
|
||||
/**
|
||||
* Special coach used for e.g. firefighting.
|
||||
*/
|
||||
SPECIAL;
|
||||
|
||||
/**
|
||||
* 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
|
||||
*/
|
||||
public static CoachType parse(String value) {
|
||||
switch (value) {
|
||||
case "passenger":
|
||||
|
@ -2,6 +2,9 @@ package edu.kit.informatik;
|
||||
|
||||
/**
|
||||
* Type of locomotive. Can be either diesel, steam or electrical.
|
||||
*
|
||||
* @author Arne Keller
|
||||
* @version 1.0
|
||||
*/
|
||||
public enum EngineType {
|
||||
/**
|
||||
@ -17,6 +20,11 @@ public enum EngineType {
|
||||
*/
|
||||
ELECTRICAL;
|
||||
|
||||
/**
|
||||
* 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
|
||||
*/
|
||||
public static EngineType parse(String value) {
|
||||
switch (value) {
|
||||
case "diesel":
|
||||
|
@ -1,13 +1,31 @@
|
||||
package edu.kit.informatik;
|
||||
|
||||
/**
|
||||
* Generic rail that other rails can connect to.
|
||||
*/
|
||||
public abstract class Rail {
|
||||
protected int id;
|
||||
|
||||
public int getIdentifier() {
|
||||
return this.id;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param point point to check for connection
|
||||
* @return whether the rail currently connects to the point
|
||||
*/
|
||||
public abstract boolean connectsTo(Point point);
|
||||
|
||||
/**
|
||||
* @param point point to check for connection
|
||||
* @return whether the rail can connect to the point
|
||||
*/
|
||||
public abstract boolean canConnectTo(Point point);
|
||||
|
||||
/**
|
||||
* @param rail rail to check for connection
|
||||
* @return whether this rail can connect to the specified rail
|
||||
*/
|
||||
public abstract boolean canConnectToRail(Rail rail);
|
||||
|
||||
/**
|
||||
@ -17,8 +35,15 @@ public abstract class Rail {
|
||||
*/
|
||||
public abstract boolean switchTo(Point position);
|
||||
|
||||
/**
|
||||
* @return whether the rail is ready for trains running on it
|
||||
*/
|
||||
public abstract boolean isReadyForTrains();
|
||||
|
||||
/**
|
||||
* @param position the point to check
|
||||
* @return whether the point is inside this rail (not on the edge)
|
||||
*/
|
||||
public abstract boolean contains(Point position);
|
||||
|
||||
public abstract Point getDirectionFrom(Point position);
|
||||
|
@ -2,9 +2,15 @@ package edu.kit.informatik.command;
|
||||
|
||||
import edu.kit.informatik.ModelRailwaySimulation;
|
||||
|
||||
/**
|
||||
* Command used to list engines.
|
||||
*
|
||||
* @author Arne Keller
|
||||
* @version 1.0
|
||||
*/
|
||||
public class ListEngines extends Command {
|
||||
@Override
|
||||
public void apply(ModelRailwaySimulation simulation) {
|
||||
public void apply(final ModelRailwaySimulation simulation) {
|
||||
simulation.printEngines();
|
||||
}
|
||||
}
|
||||
|
@ -2,9 +2,15 @@ package edu.kit.informatik.command;
|
||||
|
||||
import edu.kit.informatik.ModelRailwaySimulation;
|
||||
|
||||
/**
|
||||
* Command used to list tracks and switches.
|
||||
*
|
||||
* @author Arne Keller
|
||||
* @version 1.0
|
||||
*/
|
||||
public class ListTracks extends Command {
|
||||
@Override
|
||||
public void apply(ModelRailwaySimulation simulation) {
|
||||
public void apply(final ModelRailwaySimulation simulation) {
|
||||
simulation.printTracks();
|
||||
}
|
||||
}
|
||||
|
@ -2,9 +2,15 @@ package edu.kit.informatik.command;
|
||||
|
||||
import edu.kit.informatik.ModelRailwaySimulation;
|
||||
|
||||
/**
|
||||
* Command used to list train sets.
|
||||
*
|
||||
* @author Arne Keller
|
||||
* @version 1.0
|
||||
*/
|
||||
public class ListTrainSets extends Command {
|
||||
@Override
|
||||
public void apply(ModelRailwaySimulation simulation) {
|
||||
public void apply(final ModelRailwaySimulation simulation) {
|
||||
simulation.printTrainSets();
|
||||
}
|
||||
}
|
||||
|
@ -2,9 +2,15 @@ package edu.kit.informatik.command;
|
||||
|
||||
import edu.kit.informatik.ModelRailwaySimulation;
|
||||
|
||||
/**
|
||||
* Command used to list trains.
|
||||
*
|
||||
* @author Arne Keller
|
||||
* @version 1.0
|
||||
*/
|
||||
public class ListTrains extends Command {
|
||||
@Override
|
||||
public void apply(ModelRailwaySimulation simulation) {
|
||||
public void apply(final ModelRailwaySimulation simulation) {
|
||||
simulation.printTrains();
|
||||
}
|
||||
}
|
||||
|
@ -4,12 +4,25 @@ import edu.kit.informatik.ModelRailwaySimulation;
|
||||
import edu.kit.informatik.Point;
|
||||
import edu.kit.informatik.Terminal;
|
||||
|
||||
/**
|
||||
* Command used to put a train on the rail network.
|
||||
*
|
||||
* @author Arne Keller
|
||||
* @version 1.0
|
||||
*/
|
||||
public class PutTrain extends Command {
|
||||
private final int id;
|
||||
private final Point point;
|
||||
private final int x;
|
||||
private final int y;
|
||||
|
||||
/**
|
||||
* Construct a new 'put train' command.
|
||||
* @param id identifier of the train
|
||||
* @param point where to put the train
|
||||
* @param x initial x direction
|
||||
* @param y initial y direction
|
||||
*/
|
||||
public PutTrain(final int id, final Point point, final int x, final int y) {
|
||||
this.id = id;
|
||||
this.point = point;
|
||||
@ -18,7 +31,7 @@ public class PutTrain extends Command {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void apply(ModelRailwaySimulation simulation) {
|
||||
public void apply(final ModelRailwaySimulation simulation) {
|
||||
if (simulation.putTrain(id, point, new Point(x, y))) {
|
||||
Terminal.printLine("OK");
|
||||
} else {
|
||||
|
@ -4,10 +4,21 @@ import edu.kit.informatik.ModelRailwaySimulation;
|
||||
import edu.kit.informatik.Point;
|
||||
import edu.kit.informatik.Terminal;
|
||||
|
||||
/**
|
||||
* Command used to set the position a switch is set to.
|
||||
*
|
||||
* @author Arne Keller
|
||||
* @version 1.0
|
||||
*/
|
||||
public class SetSwitch extends Command {
|
||||
private final int id;
|
||||
private final Point point;
|
||||
|
||||
/**
|
||||
* Construct a new 'set switch' command.
|
||||
* @param id identifier of the switch
|
||||
* @param point position to set the switch to
|
||||
*/
|
||||
public SetSwitch(final int id, final Point point) {
|
||||
this.id = id;
|
||||
this.point = point;
|
||||
|
@ -2,9 +2,19 @@ package edu.kit.informatik.command;
|
||||
|
||||
import edu.kit.informatik.ModelRailwaySimulation;
|
||||
|
||||
/**
|
||||
* Command used to print a train as ASCII art.
|
||||
*
|
||||
* @author Arne Keller
|
||||
* @version 1.0
|
||||
*/
|
||||
public class ShowTrain extends Command {
|
||||
private final int id;
|
||||
|
||||
/**
|
||||
* Construct a new 'show train' command.
|
||||
* @param id identifier of the train to show
|
||||
*/
|
||||
public ShowTrain(final int id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
@ -2,15 +2,25 @@ package edu.kit.informatik.command;
|
||||
|
||||
import edu.kit.informatik.ModelRailwaySimulation;
|
||||
|
||||
/**
|
||||
* Command used to run the simulation.
|
||||
*
|
||||
* @author Arne Keller
|
||||
* @version 1.0
|
||||
*/
|
||||
public class Step extends Command {
|
||||
private final short speed;
|
||||
|
||||
/**
|
||||
* Construct a new 'step' command.
|
||||
* @param speed the amount of steps to perform
|
||||
*/
|
||||
public Step(final short speed) {
|
||||
this.speed = speed;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void apply(ModelRailwaySimulation simulation) {
|
||||
public void apply(final ModelRailwaySimulation simulation) {
|
||||
simulation.step(speed);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user