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