Checkstyle

This commit is contained in:
Arne Keller 2020-02-20 14:11:26 +01:00
parent 29a1953dab
commit 4da5eeebd3
13 changed files with 62 additions and 18 deletions

View File

@ -41,7 +41,7 @@ public abstract class Coach extends RollingStock {
@Override
public String getIdentifier() {
return String.format("W%d", identifier);
return String.format("%s%d", IDENTIFIER_PREFIX, identifier);
}
@Override
@ -49,6 +49,16 @@ public abstract class Coach extends RollingStock {
return true;
}
@Override
public boolean usefulAtFrontOfTrain() {
return false;
}
@Override
public boolean usefulAtBackOfTrain() {
return false;
}
/**
* @return the numerical identifier of this coach
*/

View File

@ -43,7 +43,8 @@ public class DieselEngine extends Engine {
@Override
public String[] textRepresentation() {
return DIESEL_ENGINE_TEXT;
// make sure caller can not modify private data
return DIESEL_ENGINE_TEXT.clone();
}
@Override

View File

@ -45,7 +45,8 @@ public class ElectricalEngine extends Engine {
@Override
public String[] textRepresentation() {
return ELECTRICAL_ENGINE_TEXT;
// make sure caller can not modify private data
return ELECTRICAL_ENGINE_TEXT.clone();
}
@Override

View File

@ -57,4 +57,14 @@ public abstract class Engine extends RollingStock {
public boolean canCoupleTo(RollingStock rollingStock) {
return true;
}
@Override
public boolean usefulAtFrontOfTrain() {
return true;
}
@Override
public boolean usefulAtBackOfTrain() {
return true;
}
}

View File

@ -34,7 +34,8 @@ public class FreightCoach extends Coach {
@Override
public String[] textRepresentation() {
return FREIGHT_TEXT;
// make sure caller can not modify private data
return FREIGHT_TEXT.clone();
}
@Override

View File

@ -38,11 +38,11 @@ public class ModelRailwaySimulation {
*/
private final List<TrainSet> trainSets = new ArrayList<>();
/**
* List of coaches used in the simulation.
* Map of coaches used in the simulation.
*/
private final Map<Integer, Coach> coaches = new HashMap<>();
/**
* List of trains simulated.
* Map of trains simulated.
*/
private final Map<Integer, Train> trains = new HashMap<>();

View File

@ -35,7 +35,8 @@ public class PassengerCoach extends Coach {
@Override
public String[] textRepresentation() {
return PASSENGER_TEXT;
// make sure caller can not modify private data
return PASSENGER_TEXT.clone();
}
@Override

View File

@ -108,7 +108,7 @@ public class RailwayNetwork {
return false;
}
// locate one other rail: TODO use rail.connectedrails?
// locate one connected rail
Rail otherRail = null;
for (Rail anotherRail : rails.values()) {
if (anotherRail.getIdentifier() != id && anotherRail.canConnectToRail(toRemove)) {

View File

@ -71,6 +71,16 @@ public abstract class RollingStock {
*/
public abstract boolean canCoupleTo(RollingStock rollingStock);
/**
* @return whether this rolling stock is useful at the front end of a train
*/
public abstract boolean usefulAtFrontOfTrain();
/**
* @return whether this rolling stock is useful at the rear end of a train
*/
public abstract boolean usefulAtBackOfTrain();
/**
* @return ASCII art representation of this rolling stock
*/

View File

@ -36,7 +36,8 @@ public class SpecialCoach extends Coach {
@Override
public String[] textRepresentation() {
return SPECIAL_TEXT;
// make sure caller can not modify private data
return SPECIAL_TEXT.clone();
}
@Override

View File

@ -43,7 +43,8 @@ public class SteamEngine extends Engine {
@Override
public String[] textRepresentation() {
return STEAM_ENGINE_TEXT;
// make sure caller can not modify private data
return STEAM_ENGINE_TEXT.clone();
}
@Override

View File

@ -192,17 +192,14 @@ public final class Train {
}
/**
* Check whether this train is correctly set up. More specifically, it either consists of train sets or has an
* engine as first or last rolling stock.
* Check whether this train is correctly set up. More specifically, it usually either consists of train sets or has
* an engine as first or last rolling stock.
* @return whether this train is valid
*/
public boolean isProperTrain() {
RollingStock first = rollingStocks.get(0);
RollingStock last = rollingStocks.get(rollingStocks.size() - 1);
// the first or last rolling stock HAVE TO BE an engine OR a train-set!
// therefore, no other rolling stock types should be allowed at all.
// TODO: consider using first.canBeAtFront() ???
return first instanceof Engine || first instanceof TrainSet || last instanceof Engine;
return first.usefulAtFrontOfTrain() || last.usefulAtBackOfTrain();
}
/**

View File

@ -28,7 +28,7 @@ public class TrainSet extends RollingStock {
*/
private final String series;
/**
* Name of this train set. TODO: create NamedRollingStock class
* Name of this train set.
*/
private final String name;
@ -63,9 +63,20 @@ public class TrainSet extends RollingStock {
return rollingStock.getClass().equals(this.getClass()) && ((TrainSet) rollingStock).series.equals(this.series);
}
@Override
public boolean usefulAtFrontOfTrain() {
return true;
}
@Override
public boolean usefulAtBackOfTrain() {
return true;
}
@Override
public String[] textRepresentation() {
return TRAIN_SET_TEXT;
// make sure caller can not modify private data
return TRAIN_SET_TEXT.clone();
}
@Override