-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathProgress.java
More file actions
70 lines (55 loc) · 1.73 KB
/
Progress.java
File metadata and controls
70 lines (55 loc) · 1.73 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 org.cleancode.journal.domain;
import org.cleancode.journal.util.ToStringUtil;
import java.io.Serializable;
import java.time.LocalDate;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.stream.IntStream;
import static java.util.stream.Collectors.toList;
public class Progress implements Serializable {
private final int size;
private LocalDate start;
private List<Day> days = new ArrayList<>();
public Progress(int size, LocalDate start) {
this.size = size;
this.start = start;
}
public List<Day> getAllDays() {
return IntStream.range(0, size).mapToObj(this::getDay).collect(toList());
}
public Day getDay(int dayOfProgress) {
if (dayOfProgress < 0) {
throw new IllegalArgumentException("dayOfProgress cant be < 0");
}
LocalDate dayToSearch = start.plusDays(dayOfProgress);
return days.stream().filter(day -> day.getDate().equals(dayToSearch)).findFirst().orElse(new Day(dayToSearch));
}
public int getSize() {
return size;
}
public List<Day> getDays() {
return days;
}
public void setDays(List<Day> days) {
this.days = days;
}
public void addDay(Day day) {
days.add(day);
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
Progress progress = (Progress) o;
return days.equals(progress.days);
}
@Override
public int hashCode() {
return Objects.hash(days);
}
@Override
public String toString() {
return "Started: " + ToStringUtil.toString(start) + " Days: " + days;
}
}