-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRemoteControlTest.java
More file actions
44 lines (30 loc) · 1.41 KB
/
RemoteControlTest.java
File metadata and controls
44 lines (30 loc) · 1.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
package CommandPattern.LambdaRemote;
public class RemoteControlTest {
public static void main(String[] args){
RemoteControl remote = new RemoteControl();
Light livingRoomLight = new Light("Living Room");
Light kitchenLight = new Light("Kitchen");
CeilingFan ceilingFan = new CeilingFan("Living Room");
Stereo stereo = new Stereo("Living Room");
remote.setCommand(0, () -> { livingRoomLight.on(); }, () -> { livingRoomLight.off(); });
// method reference example
remote.setCommand(1, kitchenLight::on, kitchenLight::off);
remote.setCommand(2, ceilingFan::high, ceilingFan::off);
// Setting multiple commands to a lambda
Command stereoOnWithCD = () -> { stereo.on(); stereo.setCD(); stereo.setVolume(11);};
remote.setCommand(3,stereoOnWithCD, stereo::off );
System.out.println(remote);
System.out.println("------Living Room light-------");
remote.onButtonWasPushed(0);
remote.offButtonWasPushed(0);
System.out.println("------Kitchen Light-------");
remote.onButtonWasPushed(1);
remote.offButtonWasPushed(1);
System.out.println("------Ceiling fan-------");
remote.onButtonWasPushed(2);
remote.offButtonWasPushed(2);
System.out.println("------Stereo-------");
remote.onButtonWasPushed(3);
remote.offButtonWasPushed(3);
}
}