-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathElectronic.java
More file actions
140 lines (107 loc) · 3.88 KB
/
Electronic.java
File metadata and controls
140 lines (107 loc) · 3.88 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
132
133
134
135
136
137
138
139
140
package me.day05.practice.practice01;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.time.format.DateTimeParseException;
import java.util.Arrays;
import java.util.Objects;
public class Electronic {
private static int objectNo = 0; //등록된제품순서.
private String productNo; //제품일련번호
private String modelName; //전자기기 모델명
private Company companyName; //제조회사명
private String dateOfMade; //생산일자
private AuthMethod[] authMethods; //본인인증방법 , 배열로정의
public Electronic() {
objectNo++;
}
// 기본생성자
public Electronic( String modelName, Company companyName, String dateOfMade, AuthMethod[] authMethods) {
objectNo++;
//this.productNo = LocalDate.now().format(DateTimeFormatter.ofPattern("yyMMdd")) + String.format("%04d", objectNo) ;
StringBuilder sb = new StringBuilder();
sb.append(LocalDate.now().format(DateTimeFormatter.ofPattern("yyMMdd")));
sb.append(String.format("%04d", objectNo));
// 날짜 형식 검증
if (!isValidDateFormat(dateOfMade)) {
dateOfMade = "20000101"; // 기본값으로 지정
}
this.productNo = sb.toString();
this.modelName = modelName;
this.companyName = companyName;
this.dateOfMade = dateOfMade;
this.authMethods = authMethods;
}
//5개의 인자를 가지는 생성자
private boolean isValidDateFormat(String date) {
// 문자열 길이와 숫자 형식 검증
if (date.length() != 8 || !date.matches("\\d{8}")) {
return false;
}
// 날짜 형식 검증
try {
LocalDate.parse(date, DateTimeFormatter.ofPattern("yyyyMMdd"));
return true;
} catch (DateTimeParseException e) {
return false;
}
}
public String getProductNo() {
return productNo;
}
public void setProductNo(String productNo) {
this.productNo = productNo;
}
public String getModelName() {
return modelName;
}
public void setModelName(String modelName) {
this.modelName = modelName;
}
public Company getCompanyName() {
return companyName;
}
public void setCompanyName(Company companyName) {
this.companyName = companyName;
}
public String getDateOfMade() {
return dateOfMade;
}
public void setDateOfMade(String dateOfMade) {
this.dateOfMade = dateOfMade;
}
public AuthMethod[] getAuthMethod() {
return authMethods;
}
public void setAuthMethod(AuthMethod[] authMethods) {
this.authMethods = authMethods;
}
public static int getObjectNo() {
return objectNo;
}
public static void setObjectNo(int objectNo) {
Electronic.objectNo = objectNo;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
Electronic that = (Electronic) o;
return Objects.equals(productNo, that.productNo) && Objects.equals(modelName, that.modelName) && companyName == that.companyName && Objects.equals(dateOfMade, that.dateOfMade) && Arrays.equals(authMethods, that.authMethods);
}
@Override
public int hashCode() {
int result = Objects.hash(productNo, modelName, companyName, dateOfMade);
result = 31 * result + Arrays.hashCode(authMethods);
return result;
}
@Override
public String toString() {
return "{" +
"productNo='" + productNo + '\'' +
", modelName='" + modelName + '\'' +
", companyName=" + companyName +
", dateOfMade='" + dateOfMade + '\'' +
", authMethod=" + Arrays.toString(authMethods) +
'}';
}
}