-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathProgressService.java
More file actions
39 lines (28 loc) · 1.16 KB
/
ProgressService.java
File metadata and controls
39 lines (28 loc) · 1.16 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
package org.cleancode.journal.service;
import org.cleancode.journal.domain.Day;
import org.cleancode.journal.domain.LogEntry;
import org.cleancode.journal.domain.Progress;
import org.springframework.stereotype.Service;
import java.time.LocalDate;
import java.util.stream.IntStream;
import static java.util.stream.IntStream.range;
@Service
public class ProgressService implements IProgressService {
@Override
public Progress getCurrentProgress() {
return getSampleProgress();
}
private Progress getSampleProgress() {
Progress progress = new Progress(21, LocalDate.now().minusDays(12));
range(1, 16).mapToObj(progress::getDay).peek(this::setDayFulfilled).forEach(progress::addDay);
IntStream.of(4, 8, 10, 13).mapToObj(progress::getDay).peek(this::setDayPartialFulfilled).forEach(progress::addDay);
return progress;
}
private void setDayFulfilled(Day day) {
day.addLogEntry(new LogEntry(LogEntry.Type.Fulfilled));
}
private void setDayPartialFulfilled(Day day) {
day.addLogEntry(new LogEntry(LogEntry.Type.Fulfilled));
day.addLogEntry(new LogEntry(LogEntry.Type.Violated));
}
}