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

View File

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

View File

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

View File

@ -57,4 +57,14 @@ public abstract class Engine extends RollingStock {
public boolean canCoupleTo(RollingStock rollingStock) { public boolean canCoupleTo(RollingStock rollingStock) {
return true; 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 @Override
public String[] textRepresentation() { public String[] textRepresentation() {
return FREIGHT_TEXT; // make sure caller can not modify private data
return FREIGHT_TEXT.clone();
} }
@Override @Override

View File

@ -38,11 +38,11 @@ public class ModelRailwaySimulation {
*/ */
private final List<TrainSet> trainSets = new ArrayList<>(); 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<>(); private final Map<Integer, Coach> coaches = new HashMap<>();
/** /**
* List of trains simulated. * Map of trains simulated.
*/ */
private final Map<Integer, Train> trains = new HashMap<>(); private final Map<Integer, Train> trains = new HashMap<>();

View File

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

View File

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

View File

@ -71,6 +71,16 @@ public abstract class RollingStock {
*/ */
public abstract boolean canCoupleTo(RollingStock 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 * @return ASCII art representation of this rolling stock
*/ */

View File

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

View File

@ -43,7 +43,8 @@ public class SteamEngine extends Engine {
@Override @Override
public String[] textRepresentation() { public String[] textRepresentation() {
return STEAM_ENGINE_TEXT; // make sure caller can not modify private data
return STEAM_ENGINE_TEXT.clone();
} }
@Override @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 * Check whether this train is correctly set up. More specifically, it usually either consists of train sets or has
* engine as first or last rolling stock. * an engine as first or last rolling stock.
* @return whether this train is valid * @return whether this train is valid
*/ */
public boolean isProperTrain() { public boolean isProperTrain() {
RollingStock first = rollingStocks.get(0); RollingStock first = rollingStocks.get(0);
RollingStock last = rollingStocks.get(rollingStocks.size() - 1); RollingStock last = rollingStocks.get(rollingStocks.size() - 1);
// the first or last rolling stock HAVE TO BE an engine OR a train-set! return first.usefulAtFrontOfTrain() || last.usefulAtBackOfTrain();
// 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;
} }
/** /**

View File

@ -28,7 +28,7 @@ public class TrainSet extends RollingStock {
*/ */
private final String series; private final String series;
/** /**
* Name of this train set. TODO: create NamedRollingStock class * Name of this train set.
*/ */
private final String name; 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); 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 @Override
public String[] textRepresentation() { public String[] textRepresentation() {
return TRAIN_SET_TEXT; // make sure caller can not modify private data
return TRAIN_SET_TEXT.clone();
} }
@Override @Override