lesson 8. · AlbertoJava/basejava@6b036bb · GitHub
Skip to content

Commit 6b036bb

Browse files
committed
lesson 8.
Устранение ошибок: 1. Реализация doRead в AbstarctFileStorage 2.ALT+L 3. обработка null из listFiles() в AbstractFileStoradge.doCopyAll
1 parent f71323e commit 6b036bb

6 files changed

Lines changed: 128 additions & 42 deletions

File tree

src/com/urise/webapp/model/ListSection.java

Lines changed: 6 additions & 0 deletions
Lines changed: 87 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,37 @@
11
package com.urise.webapp.model;
22

3+
import com.urise.webapp.util.DateUtil;
4+
35
import java.time.LocalDate;
6+
import java.time.Month;
47
import java.util.ArrayList;
8+
import java.util.Arrays;
59
import java.util.List;
610
import java.util.Objects;
711

12+
import static com.urise.webapp.util.DateUtil.NOW;
13+
import static com.urise.webapp.util.DateUtil.of;
14+
815
public class Organization {
916
private final Link homePage;
10-
private final String title;
11-
private final String description;
12-
private List<DateInterval> periods = new ArrayList<>();
13-
14-
public Organization(String name, String url, LocalDate startDate, LocalDate endDate, String title, String description) {
15-
Objects.requireNonNull(startDate, "startDate must not null");
16-
Objects.requireNonNull(endDate, "endDate must not null");
17-
Objects.requireNonNull(title, "title must not null");
18-
19-
this.homePage = new Link(name, url);
20-
periods.add(new DateInterval(startDate, endDate));
21-
this.title = title;
22-
this.description = description;
17+
private List<Position> positions = new ArrayList<>();
18+
19+
public Organization(String name, String url, Position... positions) {
20+
this ( new Link(name, url), Arrays.asList(positions));
21+
}
22+
23+
public Organization(String name, String url, List<Position> positions) {
24+
this ( new Link(name, url),positions);
25+
}
26+
27+
public Organization(Link homePage, List<Position> positions) {
28+
this.homePage = homePage;
29+
this.positions = positions;
2330
}
2431

2532
@Override
2633
public String toString() {
27-
final String periodDescription = periods.stream().map((x) -> x.toString()).reduce((x, y) -> x + ", " + y).toString();
28-
return "Organization{" +
29-
"homePage=" + homePage +
30-
", workPeriod=" + periodDescription +
31-
", title='" + title + '\'' +
32-
", description='" + description + '\'' +
33-
'}';
34+
return "Organization(" + homePage +positions +')';
3435
}
3536

3637
@Override
@@ -41,32 +42,87 @@ public boolean equals(Object o) {
4142
Organization that = (Organization) o;
4243

4344
if (homePage != null ? !homePage.equals(that.homePage) : that.homePage != null) return false;
44-
if (!periods.equals(that.periods)) return false;
45-
if (!title.equals(that.title)) return false;
46-
return description != null ? description.equals(that.description) : that.description == null;
45+
return positions != null ? positions.equals(that.positions) : that.positions == null;
4746
}
4847

4948
@Override
5049
public int hashCode() {
5150
int result = homePage != null ? homePage.hashCode() : 0;
52-
result = 31 * result + periods.hashCode();
53-
result = 31 * result + title.hashCode();
54-
result = 31 * result + (description != null ? description.hashCode() : 0);
51+
result = 31 * result + (positions != null ? positions.hashCode() : 0);
5552
return result;
5653
}
5754

58-
private class DateInterval {
59-
private LocalDate startDate;
60-
private LocalDate endDate;
55+
public static class Position{
56+
private final LocalDate startDate;
57+
private final LocalDate endDate;
58+
private final String title;
59+
private final String description;
6160

62-
private DateInterval(LocalDate startDate, LocalDate endDate) {
61+
public Position(int startYear, Month startMonth, String title, String description) {
62+
this (DateUtil.of(startYear,startMonth), NOW,title, description);
63+
}
64+
65+
public Position(int startYear, Month startMonth, int endYear, Month endMonth, String title, String description) {
66+
this (DateUtil.of(startYear,startMonth), DateUtil.of(endYear,endMonth),title, description);
67+
}
68+
69+
public Position(LocalDate startDate, LocalDate endDate, String title, String description) {
70+
Objects.requireNonNull(startDate, "startDate must not be null");
71+
Objects.requireNonNull(endDate, "endDate must not be null");
72+
Objects.requireNonNull(title, "title must not be null");
6373
this.startDate = startDate;
6474
this.endDate = endDate;
75+
this.title = title;
76+
this.description = description;
77+
}
78+
79+
public LocalDate getStartDate() {
80+
return startDate;
81+
}
82+
83+
public LocalDate getEndDate() {
84+
return endDate;
85+
}
86+
87+
public String getTitle() {
88+
return title;
89+
}
90+
91+
public String getDescription() {
92+
return description;
93+
}
94+
95+
@Override
96+
public boolean equals(Object o) {
97+
if (this == o) return true;
98+
if (o == null || getClass() != o.getClass()) return false;
99+
100+
Position position = (Position) o;
101+
102+
if (!startDate.equals(position.startDate)) return false;
103+
if (!endDate.equals(position.endDate)) return false;
104+
if (!title.equals(position.title)) return false;
105+
return description != null ? description.equals(position.description) : position.description == null;
106+
}
107+
108+
@Override
109+
public int hashCode() {
110+
int result = startDate.hashCode();
111+
result = 31 * result + endDate.hashCode();
112+
result = 31 * result + title.hashCode();
113+
result = 31 * result + (description != null ? description.hashCode() : 0);
114+
return result;
65115
}
66116

67117
@Override
68118
public String toString() {
69-
return startDate + " - " + endDate;
119+
return "Position{" +
120+
"startDate=" + startDate +
121+
", endDate=" + endDate +
122+
", title='" + title + '\'' +
123+
", description='" + description + '\'' +
124+
'}';
70125
}
71126
}
127+
72128
}

src/com/urise/webapp/model/OrganizationSection.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,17 @@
11
package com.urise.webapp.model;
22

3+
import java.lang.reflect.Array;
4+
import java.util.Arrays;
35
import java.util.List;
46
import java.util.Objects;
57

68
public class OrganizationSection extends AbstractSection {
79
private final List<Organization> organizations;
810

11+
public OrganizationSection(Organization... organizations) {
12+
this(Arrays.asList(organizations));
13+
}
14+
915
public OrganizationSection(List<Organization> organizations) {
1016
Objects.requireNonNull(organizations,"organizations must not null");
1117
this.organizations = organizations;

src/com/urise/webapp/model/Resume.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,6 @@ public boolean equals(Object o) {
7070

7171
@Override
7272
public int hashCode() {
73-
7473
return Objects.hash(uuid, fullName, contacts, sections);
7574
}
7675
}

src/com/urise/webapp/util/DateUtil.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
import java.time.Month;
55

66
public class DateUtil {
7+
public static final LocalDate NOW=LocalDate.of(3000,1,1);
8+
79
public static LocalDate of (int year, Month month){
810
return LocalDate.of(year,month,1);
911
}

test/com/urise/webapp/storage/ResumeDataTest.java

Lines changed: 27 additions & 10 deletions

0 commit comments

Comments
 (0)