-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathApplicationCsvInfo.java
More file actions
70 lines (64 loc) · 2.28 KB
/
ApplicationCsvInfo.java
File metadata and controls
70 lines (64 loc) · 2.28 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
package life.mosu.mosuserver.application.admin.dto;
import java.time.LocalDate;
import java.time.format.DateTimeParseException;
public record ApplicationCsvInfo(
String createdAt,
String name,
String gender,
LocalDate birth,
String phoneNumber,
LocalDate examDate,
String examSchool,
Boolean isLunchChecked,
Boolean isTestPaperChecked,
String subject1,
String subject2
) {
public static ApplicationCsvInfo of(
String createdAt,
String name,
String gender,
LocalDate birth,
String phoneNumber,
LocalDate examDate,
String examSchool,
Boolean isLunchChecked,
Boolean isTestPaperChecked,
String subject1,
String subject2
) {
return new ApplicationCsvInfo(createdAt, name, gender, birth, phoneNumber, examDate, examSchool, isLunchChecked, isTestPaperChecked, subject1, subject2);
}
public static ApplicationCsvInfo of(String[] values) {
if (values.length < 11) {
throw new IllegalArgumentException("CSV 행이 필수 컬럼 수(11개)보다 부족합니다. 실제 컬럼 수: " + values.length);
}
return new ApplicationCsvInfo(
values[0], // createdAt
values[1], // name
values[2], // gender
parseDate(values[3]), // birth
values[4], // phoneNumber
parseDate(values[5]), // examDate
values[6], // examSchool
parseBoolean(values[7]), // isLunchChecked
parseBoolean(values[8]), // isTestPaperChecked
values[9], // subject1
values[10] // subject2
);
}
private static LocalDate parseDate(String dateStr) {
try {
return LocalDate.parse(dateStr.trim());
} catch (DateTimeParseException e) {
throw new IllegalArgumentException("날짜 형식이 올바르지 않습니다");
}
}
private static Boolean parseBoolean(String bool) {
if (bool == null || bool.isBlank()) {
return false;
}
String trimmedValue = bool.trim();
return Boolean.parseBoolean(trimmedValue);
}
}