-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPower.java
More file actions
36 lines (28 loc) · 723 Bytes
/
Power.java
File metadata and controls
36 lines (28 loc) · 723 Bytes
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
package behavioral.command;
import java.util.Objects;
public class Power {
private static Power power;
private Boolean isOn;
private Power() {
this.isOn = Boolean.FALSE;
}
public static Power getInstance() {
if (Objects.isNull(power)) {
synchronized (Power.class) {
if (Objects.isNull(power)) {
power = new Power();
}
}
}
return power;
}
public Boolean toggle() {
this.isOn = !this.isOn;
return this.isOn;
}
@Override
public String toString() {
String state = this.isOn ? "is on" : "is off";
return "Air conditioner " + state;
}
}