Created
November 15, 2012 10:52
-
-
Save novln/4077952 to your computer and use it in GitHub Desktop.
CommandFactory - Example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package fr.umlv.poo.automate0.command; | |
import fr.umlv.poo.automate0.robot.Robot; | |
import fr.umlv.poo.automate0.robot.axis.AxisType; | |
/** | |
* Example: | |
* CommandFactory.create(robot, CommandFactory.AXIS_MOVE_COMMAND, AxisType.X, 120); | |
* CommandFactory.create(robot, CommandFactory.PLIERS_OPEN_COMMAND); | |
*/ | |
public final class CommandFactory { | |
public final static int AXIS_MOVE_COMMAND = 0; | |
public final static int LIGHT_OFF_COMMAND = AXIS_MOVE_COMMAND + 1; | |
public final static int LIGHT_ON_COMMAND = LIGHT_OFF_COMMAND + 1; | |
public final static int PLIERS_CLOSE_COMMAND = LIGHT_ON_COMMAND + 1; | |
public final static int PLIERS_OPEN_COMMAND = PLIERS_CLOSE_COMMAND + 1; | |
private CommandFactory() {} | |
public static Command create(Robot robot, int which, Object... args) { | |
switch(which) { | |
case AXIS_MOVE_COMMAND: { | |
return new AxisMoveCommand(robot, (AxisType) args[0], (int) args[1]); | |
} | |
case LIGHT_OFF_COMMAND: { | |
return new LightOffCommand(robot); | |
} | |
case LIGHT_ON_COMMAND: { | |
return new LightOnCommand(robot); | |
} | |
case PLIERS_CLOSE_COMMAND: { | |
return new PliersCloseCommand(robot); | |
} | |
case PLIERS_OPEN_COMMAND: { | |
return new PliersOpenCommand(robot); | |
} | |
default: { | |
throw new IllegalArgumentException(); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment