-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathElectronics.java
84 lines (70 loc) · 2.62 KB
/
Electronics.java
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
package KDTBE5_Java_Assignment3.me.practice.Practice03;
import KDTBE5_Java_Assignment3.me.practice.Practice01.AuthMethod;
import KDTBE5_Java_Assignment3.me.practice.Practice01.Company;
import KDTBE5_Java_Assignment3.me.practice.Practice01.Electronic;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Objects;
public class Electronics {
private static final Electronics INSTANCE = new Electronics();
public Electronics() {
}
public static Electronics getINSTANCE() {
return INSTANCE;
}
private Electronic[] electronicList;
public Electronic[] getElectronicList() {
return electronicList;
}
public void setElectronicList(Electronic[] electronicList) {
this.electronicList = electronicList;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
Electronics that = (Electronics) o;
return Objects.equals(INSTANCE, that.INSTANCE) && Arrays.equals(electronicList, that.electronicList);
}
@Override
public int hashCode() {
int result = Objects.hash(INSTANCE);
result = 31 * result + Arrays.hashCode(electronicList);
return result;
}
@Override
public String toString() {
return "Electronics{" +
"INSTANCE=" + INSTANCE +
", electronicList=" + Arrays.toString(electronicList) +
'}';
}
public Electronic findByProductNo(String productNo) throws Exception {
for (Electronic electronic:this.electronicList
) {
if(electronic.getProductNo().equals(productNo))return electronic;
}
throw new Exception("해당 생산번호를 가지는 기기는 없습니다.");
};
public Electronic[] groupByCompanyName(Company company){
List<Electronic> electronics = new ArrayList<Electronic>();
for (Electronic electronic:this.electronicList
) {
if(electronic.getCompany() == company){
electronics.add(electronic);
}
}
return electronics.toArray(new Electronic[electronics.size()]);
};
public Electronic[] groupByAuthMethod(AuthMethod authMethod){
List<Electronic> electronics = new ArrayList<Electronic>();
for (Electronic electronic:this.electronicList
) {
if(Arrays.asList(electronic.getAuthMethod()).indexOf(authMethod)>-1){
electronics.add(electronic);
}
}
return electronics.toArray(new Electronic[electronics.size()]);
};
}