-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRemoteControl.java
More file actions
43 lines (36 loc) · 1.16 KB
/
Copy pathRemoteControl.java
File metadata and controls
43 lines (36 loc) · 1.16 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
package TheCommandPattern;
import java.util.Arrays;
public class RemoteControl {
Command[] onCommands;
Command[] offCommands;
public RemoteControl() {
onCommands = new Command[7];
offCommands = new Command[7];
Command noCommand = new NoCommand();
for(int i=0;i<7;i++){
onCommands[i] = noCommand;
offCommands[i] = noCommand;
}
}
public void setCommand(int slot,Command onCommand,Command offCommand){
onCommands[slot] = onCommand;
offCommands[slot] = offCommand;
}
public void onButtonWasPushed(int slot){
onCommands[slot].exceute();
}
public void offButtonWasPushed(int slot){
offCommands[slot].exceute();
}
@Override
public String toString() {
StringBuffer stringBuffer = new StringBuffer();
for(int i=0;i<onCommands.length;i++){
stringBuffer.append("RemoteControl{" +
"onCommand=" + onCommands[i].getClass().getName() +
", offCommands=" + offCommands[i].getClass().getName() +
'}' + "\n");
}
return stringBuffer.toString();
}
}