public static void main(String[] args) { SimpleRemoteControl remote = new SimpleRemoteControl(); Light light = new Light(); LightOnCommand lightOn = new LightOnCommand(light); LightOffCommand lightOff = new LightOffCommand(light); GarageDoor garageDoor = new GarageDoor(light); GarageDoorOpenCommand doorUp = new GarageDoorOpenCommand(garageDoor); remote.setCommand(lightOn); remote.buttonPressed(); remote.setCommand(lightOff); remote.buttonPressed(); remote.setCommand(doorUp); remote.buttonPressed(); RemoteControl complexRemote = new RemoteControl(); Stereo stereo = new Stereo(); CD cd = new CD("Sgt. PepperÕs Lonely Hearts Club Band"); StereoOnWithCDCommand stereoOn = new StereoOnWithCDCommand(stereo, cd); StereoOffWithCDCommand stereoOff = new StereoOffWithCDCommand(stereo, cd); complexRemote.setCommand(0, lightOn, lightOff); complexRemote.setCommand(1, stereoOn, stereoOff); System.out.println(complexRemote); complexRemote.onButtonWasPushed(0); complexRemote.onButtonWasPushed(1); complexRemote.offButtonWasPushed(0); CeilingFan ceilingFan = new CeilingFan("Living Room"); CeilingFanMediumCommand ceilingFanMedium = new CeilingFanMediumCommand(ceilingFan); CeilingFanLowCommand ceilingFanLow = new CeilingFanLowCommand(ceilingFan); CeilingFanHighCommand ceilingFanHigh = new CeilingFanHighCommand(ceilingFan); CeilingFanOffCommand ceilingFanOff = new CeilingFanOffCommand(ceilingFan); complexRemote.setCommand(0, ceilingFanMedium, ceilingFanOff); complexRemote.setCommand(1, ceilingFanHigh, ceilingFanOff); complexRemote.setCommand(2, ceilingFanLow, ceilingFanOff); complexRemote.onButtonWasPushed(0); complexRemote.offButtonWasPushed(0); System.out.println(complexRemote); complexRemote.undoButtonWasPushed(); }
public static void main(String[] args) { RemoteControl rc = new RemoteControl(); Light light = new Light(); Stereo stereo = new Stereo("livingroom"); Hottub hottub = new Hottub(); LightOnCommand loc = new LightOnCommand(light); LightOffCommand loffc = new LightOffCommand(light); StereoOnCommand soc = new StereoOnCommand(stereo); StereoOffCommand soffc = new StereoOffCommand(stereo); HottubOnCommand hoc = new HottubOnCommand(hottub); HottubOffCommand hoffc = new HottubOffCommand(hottub); Command[] partyOn = {loc, soc, hoc}; Command[] partyOff = {loffc, soffc, hoffc}; MacroCommand partyOnMacro = new MacroCommand(partyOn); MacroCommand partyOffMacro = new MacroCommand(partyOff); rc.setCommand(0, partyOnMacro, partyOffMacro); rc.onButtonWasPressed(0); rc.offButtonWasPressed(0); }
@Test public void testMacroCommands() { Light light = new Light("Living Room"); Stereo stereo = new Stereo("Livin Room"); LightOnCommand lightOnCommand = new LightOnCommand(light); StereoOnWithCDCommand stereoOnWithCDCommand = new StereoOnWithCDCommand(stereo); LightOffCommand lightOffCommand = new LightOffCommand(light); StereoOffCommand stereoOffCommand = new StereoOffCommand(stereo); Command[] partyOn = {lightOnCommand, stereoOnWithCDCommand}; Command[] partyOff = {lightOffCommand, stereoOffCommand}; MacroCommand partyOnMacro = new MacroCommand(partyOn); MacroCommand partyOffMacro = new MacroCommand(partyOff); RemoteControl remoteControl = new RemoteControl(); remoteControl.setCommand(0, partyOnMacro, partyOffMacro); System.out.println(remoteControl); System.out.println("-----Pushing macro on-----"); remoteControl.onButtonWasPushed(0); System.out.println("-----Pushing macro off-----"); remoteControl.offButtonWasPushed(0); }