From 4da5eeebd3c0d681d696ba110c740ca57dfa3e79 Mon Sep 17 00:00:00 2001 From: Arne Keller Date: Thu, 20 Feb 2020 14:11:26 +0100 Subject: [PATCH] Checkstyle --- src/edu/kit/informatik/model/Coach.java | 12 +++++++++++- src/edu/kit/informatik/model/DieselEngine.java | 3 ++- .../kit/informatik/model/ElectricalEngine.java | 3 ++- src/edu/kit/informatik/model/Engine.java | 10 ++++++++++ src/edu/kit/informatik/model/FreightCoach.java | 3 ++- .../informatik/model/ModelRailwaySimulation.java | 4 ++-- src/edu/kit/informatik/model/PassengerCoach.java | 3 ++- src/edu/kit/informatik/model/RailwayNetwork.java | 2 +- src/edu/kit/informatik/model/RollingStock.java | 10 ++++++++++ src/edu/kit/informatik/model/SpecialCoach.java | 3 ++- src/edu/kit/informatik/model/SteamEngine.java | 3 ++- src/edu/kit/informatik/model/Train.java | 9 +++------ src/edu/kit/informatik/model/TrainSet.java | 15 +++++++++++++-- 13 files changed, 62 insertions(+), 18 deletions(-) diff --git a/src/edu/kit/informatik/model/Coach.java b/src/edu/kit/informatik/model/Coach.java index 8319ba3..dc012d3 100644 --- a/src/edu/kit/informatik/model/Coach.java +++ b/src/edu/kit/informatik/model/Coach.java @@ -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 */ diff --git a/src/edu/kit/informatik/model/DieselEngine.java b/src/edu/kit/informatik/model/DieselEngine.java index 700d655..91f7789 100644 --- a/src/edu/kit/informatik/model/DieselEngine.java +++ b/src/edu/kit/informatik/model/DieselEngine.java @@ -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 diff --git a/src/edu/kit/informatik/model/ElectricalEngine.java b/src/edu/kit/informatik/model/ElectricalEngine.java index 1594867..56b30b6 100644 --- a/src/edu/kit/informatik/model/ElectricalEngine.java +++ b/src/edu/kit/informatik/model/ElectricalEngine.java @@ -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 diff --git a/src/edu/kit/informatik/model/Engine.java b/src/edu/kit/informatik/model/Engine.java index 3243c5e..1cd88bc 100644 --- a/src/edu/kit/informatik/model/Engine.java +++ b/src/edu/kit/informatik/model/Engine.java @@ -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; + } } diff --git a/src/edu/kit/informatik/model/FreightCoach.java b/src/edu/kit/informatik/model/FreightCoach.java index a8d8cfc..f4aa56a 100644 --- a/src/edu/kit/informatik/model/FreightCoach.java +++ b/src/edu/kit/informatik/model/FreightCoach.java @@ -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 diff --git a/src/edu/kit/informatik/model/ModelRailwaySimulation.java b/src/edu/kit/informatik/model/ModelRailwaySimulation.java index 2b6f074..dc4c0b6 100644 --- a/src/edu/kit/informatik/model/ModelRailwaySimulation.java +++ b/src/edu/kit/informatik/model/ModelRailwaySimulation.java @@ -38,11 +38,11 @@ public class ModelRailwaySimulation { */ private final List trainSets = new ArrayList<>(); /** - * List of coaches used in the simulation. + * Map of coaches used in the simulation. */ private final Map coaches = new HashMap<>(); /** - * List of trains simulated. + * Map of trains simulated. */ private final Map trains = new HashMap<>(); diff --git a/src/edu/kit/informatik/model/PassengerCoach.java b/src/edu/kit/informatik/model/PassengerCoach.java index 57981ee..45106b1 100644 --- a/src/edu/kit/informatik/model/PassengerCoach.java +++ b/src/edu/kit/informatik/model/PassengerCoach.java @@ -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 diff --git a/src/edu/kit/informatik/model/RailwayNetwork.java b/src/edu/kit/informatik/model/RailwayNetwork.java index d9f0399..ab05e37 100644 --- a/src/edu/kit/informatik/model/RailwayNetwork.java +++ b/src/edu/kit/informatik/model/RailwayNetwork.java @@ -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)) { diff --git a/src/edu/kit/informatik/model/RollingStock.java b/src/edu/kit/informatik/model/RollingStock.java index a3447ed..6d08e3b 100644 --- a/src/edu/kit/informatik/model/RollingStock.java +++ b/src/edu/kit/informatik/model/RollingStock.java @@ -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 */ diff --git a/src/edu/kit/informatik/model/SpecialCoach.java b/src/edu/kit/informatik/model/SpecialCoach.java index 8d2f80c..63c6335 100644 --- a/src/edu/kit/informatik/model/SpecialCoach.java +++ b/src/edu/kit/informatik/model/SpecialCoach.java @@ -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 diff --git a/src/edu/kit/informatik/model/SteamEngine.java b/src/edu/kit/informatik/model/SteamEngine.java index 1aac074..a724034 100644 --- a/src/edu/kit/informatik/model/SteamEngine.java +++ b/src/edu/kit/informatik/model/SteamEngine.java @@ -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 diff --git a/src/edu/kit/informatik/model/Train.java b/src/edu/kit/informatik/model/Train.java index 680684b..68e74e0 100644 --- a/src/edu/kit/informatik/model/Train.java +++ b/src/edu/kit/informatik/model/Train.java @@ -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(); } /** diff --git a/src/edu/kit/informatik/model/TrainSet.java b/src/edu/kit/informatik/model/TrainSet.java index e1af78c..72074e9 100644 --- a/src/edu/kit/informatik/model/TrainSet.java +++ b/src/edu/kit/informatik/model/TrainSet.java @@ -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