-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCustomEnum.java
More file actions
131 lines (109 loc) · 3.39 KB
/
CustomEnum.java
File metadata and controls
131 lines (109 loc) · 3.39 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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
package example.EnumExample;
import example.EnumExample.Drone.CurrentStatus;
import example.EnumExample.Drone.SwitchStatus;
import example.EnumExample.Pizza.PizzaStatus;
/**
* Class + Enum 範例
*
* TODO: 繼續擴充學習觀念並結合!
*
* Reference:
* - https://github.com/linth/JavaGuide/blob/master/docs/java/basic/%E7%94%A8%E5%A5%BDJava%E4%B8%AD%E7%9A%84%E6%9E%9A%E4%B8%BE%E7%9C%9F%E7%9A%84%E6%B2%A1%E6%9C%89%E9%82%A3%E4%B9%88%E7%AE%80%E5%8D%95.md
*/
public class CustomEnum {
public static void main(String[] args) {
// pizza example.
Pizza pizza = new Pizza();
pizza.setStatus(PizzaStatus.ORDERED);
if (pizza.getStatus().equals(Pizza.PizzaStatus.ORDERED)) {
System.out.println("ORDERED");
} else if (pizza.getStatus().equals(Pizza.PizzaStatus.READY)) {
System.out.println("READY");
} else {
System.out.println("DELIVERED");
}
// drone example.
Drone drone = new Drone();
drone.setSwitchStatus(SwitchStatus.ON)
.setCurrentStatus(CurrentStatus.IotHub)
.setIsMediaStreaming(true)
.setIsIotHub(true)
.setIsAiMediaStreaming(false);
System.out.println("CurrentStatus: " + drone.getCurrentStatus());
System.out.println("IsMediaStreaming: " + drone.getIsMediaStreaming());
System.out.println("IsIotHub: " + drone.getIsIotHub());
System.out.println("IsAiMediaStreaming: " + drone.getIsAiMediaStreaming());
}
}
class Pizza {
private PizzaStatus status;
public enum PizzaStatus {
ORDERED,
READY,
DELIVERED;
}
public PizzaStatus getStatus() {
return status;
}
public void setStatus(PizzaStatus status) {
this.status = status;
}
public boolean isDeliverable() {
if (getStatus() == PizzaStatus.READY) {
return true;
}
return false;
}
}
class Drone {
// ! class + enum example.
private SwitchStatus switchStatus;
private CurrentStatus currentStatus;
private boolean IsMediaStreaming = false;
private boolean IsIotHub = false;
private boolean IsAiMediaStreaming = false;
public enum SwitchStatus {
ON,
OFF;
}
public enum CurrentStatus {
MediaStreaming,
IotHub,
AiMediaStreaming;
}
public SwitchStatus getSwitchStatus() {
return switchStatus;
}
public Drone setSwitchStatus(SwitchStatus switchStatus) {
this.switchStatus = switchStatus;
return this;
}
public CurrentStatus getCurrentStatus() {
return currentStatus;
}
public Drone setCurrentStatus(CurrentStatus currentStatus) {
this.currentStatus = currentStatus;
return this;
}
public boolean getIsMediaStreaming() {
return IsMediaStreaming;
}
public Drone setIsMediaStreaming(boolean IsMediaStreaming) {
this.IsMediaStreaming = IsMediaStreaming;
return this;
}
public boolean getIsIotHub() {
return IsIotHub;
}
public Drone setIsIotHub(boolean IsIotHub) {
this.IsIotHub = IsIotHub;
return this;
}
public boolean getIsAiMediaStreaming() {
return IsAiMediaStreaming;
}
public Drone setIsAiMediaStreaming(boolean IsAiMediaStreaming) {
this.IsAiMediaStreaming = IsAiMediaStreaming;
return this;
}
}