diff --git a/resources/T1000-Concept.txt b/resources/T1000-Concept.txt new file mode 100644 index 0000000..e69de29 diff --git a/src/de/hsmannheim/informatik/name/domain/RobotBluePrint.java b/src/de/hsmannheim/informatik/name/domain/RobotBluePrint.java index f398904..cbf045f 100644 --- a/src/de/hsmannheim/informatik/name/domain/RobotBluePrint.java +++ b/src/de/hsmannheim/informatik/name/domain/RobotBluePrint.java @@ -5,6 +5,14 @@ import de.hsmannheim.informatik.name.domain.exceptions.RobotIllegalStateExceptio import de.hsmannheim.informatik.name.domain.exceptions.RobotMagicValueException; import de.hsmannheim.informatik.name.domain.requirements.Robot; +/** + *
+ * Factory Class for producing Robots of Robots specified by {@link RobotType}. + * + * @see RobotType + */ public class RobotFactory { } diff --git a/src/de/hsmannheim/informatik/name/domain/RobotType.java b/src/de/hsmannheim/informatik/name/domain/RobotType.java index 6ea83cd..53f116d 100644 --- a/src/de/hsmannheim/informatik/name/domain/RobotType.java +++ b/src/de/hsmannheim/informatik/name/domain/RobotType.java @@ -1,4 +1,11 @@ package de.hsmannheim.informatik.name.domain; +/** + *
+ * Enumeration to represent a creatable Robot + */ public enum RobotType { + C3P0, + R2D2 } diff --git a/src/de/hsmannheim/informatik/name/domain/bladerunner/Nexus6.java b/src/de/hsmannheim/informatik/name/domain/bladerunner/Nexus6.java new file mode 100644 index 0000000..080608f --- /dev/null +++ b/src/de/hsmannheim/informatik/name/domain/bladerunner/Nexus6.java @@ -0,0 +1,59 @@ +package de.hsmannheim.informatik.name.domain.bladerunner; + +import de.hsmannheim.informatik.name.domain.RobotBluePrint; +import de.hsmannheim.informatik.name.domain.exceptions.RobotIllegalStateException; + +/** + *
+ * Nexus-6 Robot with Name "Pris" and SerialNumber 19281982. + * This Robot doesnt work properly, since it has been damaged. + *
+ * There can only exist one Instance of this Robot. + * + * @see RobotBluePrint + */ +public class Nexus6 extends RobotBluePrint { + + private static Nexus6 nexus6 = null; + + private final static int NEXUS_ID = 19281982; + + private final static String NEXUS_NAME = "Pris"; + + private Nexus6() throws RobotIllegalStateException { + super(NEXUS_ID, NEXUS_NAME); + } + + /** + * Creates an instance of {@link Nexus6}, if there currently is no available instance yet. + * + * @return instance of {@link Nexus6} + * @throws RobotIllegalStateException if the instance could not be created + */ + public static Nexus6 getInstance() throws RobotIllegalStateException { + if (nexus6 == null) { + nexus6 = new Nexus6(); + } + return nexus6; + } + + @Override + protected boolean isValidID(int id) { + return id == NEXUS_ID; + } + + @Override + public void triggerPowerSwitch() { + } + + @Override + public String speak(int[] zahlen) throws RobotIllegalStateException { + throw new RobotIllegalStateException("Robot is defect", this); + } + + @Override + public int[] think(int[] zahlen) throws RobotIllegalStateException { + throw new RobotIllegalStateException("Robot is defect", this); + } +} diff --git a/src/de/hsmannheim/informatik/name/domain/exceptions/RobotException.java b/src/de/hsmannheim/informatik/name/domain/exceptions/RobotException.java index e270194..d0d839b 100644 --- a/src/de/hsmannheim/informatik/name/domain/exceptions/RobotException.java +++ b/src/de/hsmannheim/informatik/name/domain/exceptions/RobotException.java @@ -1,4 +1,16 @@ package de.hsmannheim.informatik.name.domain.exceptions; +import de.hsmannheim.informatik.name.domain.RobotBluePrint; + +/** + *
+ * Exception for any unexpected Behaviour for any Robot. + */ public class RobotException extends Exception { + + public RobotException(String s, RobotBluePrint robot) { + super(s); + robot.setLastException(this); + } } diff --git a/src/de/hsmannheim/informatik/name/domain/exceptions/RobotIllegalStateException.java b/src/de/hsmannheim/informatik/name/domain/exceptions/RobotIllegalStateException.java index 4f85eec..9464394 100644 --- a/src/de/hsmannheim/informatik/name/domain/exceptions/RobotIllegalStateException.java +++ b/src/de/hsmannheim/informatik/name/domain/exceptions/RobotIllegalStateException.java @@ -1,4 +1,9 @@ package de.hsmannheim.informatik.name.domain.exceptions; -public class RobotIllegalStateException extends Exception { +import de.hsmannheim.informatik.name.domain.RobotBluePrint; + +public class RobotIllegalStateException extends RobotException { + public RobotIllegalStateException(String s, RobotBluePrint robot) { + super(s, robot); + } } diff --git a/src/de/hsmannheim/informatik/name/domain/exceptions/RobotMagicValueException.java b/src/de/hsmannheim/informatik/name/domain/exceptions/RobotMagicValueException.java index 21d809d..26f6f3d 100644 --- a/src/de/hsmannheim/informatik/name/domain/exceptions/RobotMagicValueException.java +++ b/src/de/hsmannheim/informatik/name/domain/exceptions/RobotMagicValueException.java @@ -1,4 +1,9 @@ package de.hsmannheim.informatik.name.domain.exceptions; -public class RobotMagicValueException extends Exception { +import de.hsmannheim.informatik.name.domain.RobotBluePrint; + +public class RobotMagicValueException extends RobotException { + public RobotMagicValueException(String s, RobotBluePrint robot) { + super(s, robot); + } } diff --git a/src/de/hsmannheim/informatik/name/domain/starwars/C3PO.java b/src/de/hsmannheim/informatik/name/domain/starwars/C3PO.java index 2679744..9c429b5 100644 --- a/src/de/hsmannheim/informatik/name/domain/starwars/C3PO.java +++ b/src/de/hsmannheim/informatik/name/domain/starwars/C3PO.java @@ -3,6 +3,14 @@ package de.hsmannheim.informatik.name.domain.starwars; import de.hsmannheim.informatik.name.domain.exceptions.RobotException; import de.hsmannheim.informatik.name.domain.exceptions.RobotIllegalStateException; +/** + *
+ * R2D2 robot using the InsertionSort-algorithm for {@code think()} and separating + * each element in {@code speak()} with ";". + * + * @see StarWarsRobot + */ public class C3PO extends StarWarsRobot { public C3PO(int id) throws RobotIllegalStateException { super(';', id, "C3PO"); diff --git a/src/de/hsmannheim/informatik/name/domain/starwars/R2D2.java b/src/de/hsmannheim/informatik/name/domain/starwars/R2D2.java index 8b3e6e9..786aa11 100644 --- a/src/de/hsmannheim/informatik/name/domain/starwars/R2D2.java +++ b/src/de/hsmannheim/informatik/name/domain/starwars/R2D2.java @@ -4,6 +4,14 @@ import de.hsmannheim.informatik.name.domain.exceptions.RobotException; import de.hsmannheim.informatik.name.domain.exceptions.RobotIllegalStateException; import de.hsmannheim.informatik.name.domain.exceptions.RobotMagicValueException; +/** + *
+ * R2D2 robot using the SelectionSort-algorithm for {@code think()} and separating + * each element in {@code speak()} with ",". + * + * @see StarWarsRobot + */ public class R2D2 extends StarWarsRobot { public R2D2(int id) throws RobotIllegalStateException { super(',', id, "R2D2"); @@ -18,8 +26,8 @@ public class R2D2 extends StarWarsRobot { public int[] think(int[] zahlen) throws RobotException, RobotMagicValueException { int[] arrayToSort = zahlen.clone(); for (int i = 0; i < arrayToSort.length; i++) { - if (arrayToSort[i] == 42) { - throw new RobotMagicValueException(); + if (arrayToSort[i] == MAGIC_NUMBER) { + throw new RobotMagicValueException(String.format("Appearance of Magic Number: %d", MAGIC_NUMBER), this); } int smallest = Integer.MAX_VALUE; int smallestIndex = 0; diff --git a/src/de/hsmannheim/informatik/name/domain/starwars/StarWarsRobot.java b/src/de/hsmannheim/informatik/name/domain/starwars/StarWarsRobot.java index 7ad894b..497181a 100644 --- a/src/de/hsmannheim/informatik/name/domain/starwars/StarWarsRobot.java +++ b/src/de/hsmannheim/informatik/name/domain/starwars/StarWarsRobot.java @@ -8,7 +8,13 @@ import de.hsmannheim.informatik.name.domain.exceptions.RobotMagicValueException; import java.util.Arrays; import java.util.stream.Collectors; - +/** + *