-
Notifications
You must be signed in to change notification settings - Fork 566
Expand file tree
/
Copy pathStudyCafeFileHandler.java
More file actions
38 lines (32 loc) · 1.54 KB
/
StudyCafeFileHandler.java
File metadata and controls
38 lines (32 loc) · 1.54 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
package cleancode.studycafe.tobe.io;
import cleancode.studycafe.tobe.model.StudyCafeLockerPass;
import cleancode.studycafe.tobe.model.StudyCafePass;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.List;
public class StudyCafeFileHandler {
public List<StudyCafePass> readStudyCafePasses() {
List<StudyCafeLockerPass> lockerPasses = readLockerPasses();
try {
List<String> lines = Files.readAllLines(Paths.get("src/main/resources/cleancode/studycafe/pass-list.csv"));
return lines.stream().map(line -> line.split(","))
.map(values -> {
int duration = Integer.parseInt(values[1]);
StudyCafeLockerPass locker = lockerPasses.stream().filter((lockerPass -> lockerPass.isCompatible(duration))).findFirst().orElse(null);
return StudyCafePass.of(values, locker);
}).toList();
} catch (IOException e) {
throw new RuntimeException("파일을 읽는데 실패했습니다.", e);
}
}
private List<StudyCafeLockerPass> readLockerPasses() {
try {
List<String> lines = Files.readAllLines(Paths.get("src/main/resources/cleancode/studycafe/locker.csv"));
return lines.stream().map(line -> line.split(","))
.map(StudyCafeLockerPass::fromValues).toList();
} catch (IOException e) {
throw new RuntimeException("파일을 읽는데 실패했습니다.", e);
}
}
}