-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCourse.java
More file actions
89 lines (65 loc) · 1.65 KB
/
Course.java
File metadata and controls
89 lines (65 loc) · 1.65 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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
import java.util.List;
import java.util.Date;
public class Course {
private final String uuid;
private final String name;
private final List<Session> sessions;
public Course(final String uuid, final String name, final List<Session> sessions) {
this.uuid = uuid;
this.name = name;
this.sessions = sessions;
}
public String getUuid() {
return uuid;
}
public String getName() {
return name;
}
public List<Session> getSessions() {
return sessions;
}
@Override
public boolean equals(final Object object) {
if (!(object instanceof Course))
return false;
final Course that = (Course) object;
if (!that.getUuid().equals(this.getUuid()))
return false;
return true;
}
@Override
public int hashCode() {
// BEGIN (write your solution here)
if (null == uuid || "".equals(uuid)) return 0;
int code = 0;
for (char ch : uuid.toCharArray()) code += ch;
return code;
// END
}
public class Session {
private final Date startDate;
public Session(final Date startDate) {
this.startDate = startDate;
}
public Date getStartDate() {
return this.startDate;
}
public Course getCourse() {
return Course.this;
}
@Override
public boolean equals(final Object object) {
if (!(object instanceof Session)) return false;
final Session that = (Session) object;
if (!that.getStartDate().equals(this.getStartDate())) return false;
if (!that.getCourse().equals(this.getCourse())) return false;
return true;
}
@Override
public int hashCode() {
// BEGIN (write your solution here)
return startDate.hashCode();
// END
}
}
}