added RobotFactory method, documentation
parent
160d3c5ce3
commit
ae17a3013e
|
@ -27,7 +27,6 @@ public abstract class RobotBluePrint implements Robot {
|
||||||
this.name = name;
|
this.name = name;
|
||||||
this.isPowered = false;
|
this.isPowered = false;
|
||||||
if (!this.isValidID(id)) {
|
if (!this.isValidID(id)) {
|
||||||
//TODO write own Exception & change Tests
|
|
||||||
throw new RobotIllegalStateException(String.format("%d is not a valid ID", id), this);
|
throw new RobotIllegalStateException(String.format("%d is not a valid ID", id), this);
|
||||||
}
|
}
|
||||||
this.ID = id;
|
this.ID = id;
|
||||||
|
|
|
@ -1,5 +1,10 @@
|
||||||
package de.hsmannheim.informatik.name.domain;
|
package de.hsmannheim.informatik.name.domain;
|
||||||
|
|
||||||
|
import de.hsmannheim.informatik.name.domain.exceptions.RobotIllegalStateException;
|
||||||
|
import de.hsmannheim.informatik.name.domain.requirements.Robot;
|
||||||
|
import de.hsmannheim.informatik.name.domain.starwars.C3PO;
|
||||||
|
import de.hsmannheim.informatik.name.domain.starwars.R2D2;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <h1>RobotFactory</h1>
|
* <h1>RobotFactory</h1>
|
||||||
* <p>
|
* <p>
|
||||||
|
@ -8,4 +13,26 @@ package de.hsmannheim.informatik.name.domain;
|
||||||
* @see RobotType
|
* @see RobotType
|
||||||
*/
|
*/
|
||||||
public class RobotFactory {
|
public class RobotFactory {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Factory Method to get a {@link Robot}
|
||||||
|
*
|
||||||
|
* @param type {@link RobotType Type} of the robot
|
||||||
|
* @param serialNumber serialnumber in form of an {@code int}
|
||||||
|
* @return a {@link Robot robot instance} of specified type, if no type matches {@code null}
|
||||||
|
* @throws RobotIllegalStateException the robot initializes in an illegal state
|
||||||
|
*/
|
||||||
|
public Robot getRobot(RobotType type, int serialNumber) throws RobotIllegalStateException {
|
||||||
|
switch (type) {
|
||||||
|
case C3P0 -> {
|
||||||
|
return new C3PO(serialNumber);
|
||||||
|
}
|
||||||
|
case R2D2 -> {
|
||||||
|
return new R2D2(serialNumber);
|
||||||
|
}
|
||||||
|
default -> {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,8 +9,15 @@ import de.hsmannheim.informatik.name.domain.RobotBluePrint;
|
||||||
*/
|
*/
|
||||||
public class RobotException extends Exception {
|
public class RobotException extends Exception {
|
||||||
|
|
||||||
|
private final String robotName;
|
||||||
|
|
||||||
public RobotException(String s, RobotBluePrint robot) {
|
public RobotException(String s, RobotBluePrint robot) {
|
||||||
super(s);
|
super(s);
|
||||||
robot.setLastException(this);
|
robot.setLastException(this);
|
||||||
|
this.robotName = robot.getName();
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getRobotName() {
|
||||||
|
return this.robotName;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,6 +2,13 @@ package de.hsmannheim.informatik.name.domain.exceptions;
|
||||||
|
|
||||||
import de.hsmannheim.informatik.name.domain.RobotBluePrint;
|
import de.hsmannheim.informatik.name.domain.RobotBluePrint;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <h1>RobotIllegalStateException</h>
|
||||||
|
* <p>
|
||||||
|
* Exception for the robot reaching any state that is considered illegal.
|
||||||
|
*
|
||||||
|
* @see RobotException
|
||||||
|
*/
|
||||||
public class RobotIllegalStateException extends RobotException {
|
public class RobotIllegalStateException extends RobotException {
|
||||||
public RobotIllegalStateException(String s, RobotBluePrint robot) {
|
public RobotIllegalStateException(String s, RobotBluePrint robot) {
|
||||||
super(s, robot);
|
super(s, robot);
|
||||||
|
|
|
@ -2,6 +2,13 @@ package de.hsmannheim.informatik.name.domain.exceptions;
|
||||||
|
|
||||||
import de.hsmannheim.informatik.name.domain.RobotBluePrint;
|
import de.hsmannheim.informatik.name.domain.RobotBluePrint;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <h1>RobotMagicValueException</h>
|
||||||
|
* <p>
|
||||||
|
* Exception for the robot detecting any kind of Magic Number.
|
||||||
|
*
|
||||||
|
* @see RobotException
|
||||||
|
*/
|
||||||
public class RobotMagicValueException extends RobotException {
|
public class RobotMagicValueException extends RobotException {
|
||||||
public RobotMagicValueException(String s, RobotBluePrint robot) {
|
public RobotMagicValueException(String s, RobotBluePrint robot) {
|
||||||
super(s, robot);
|
super(s, robot);
|
||||||
|
|
Loading…
Reference in New Issue