-
Notifications
You must be signed in to change notification settings - Fork 307
Expand file tree
/
Copy pathEnrollment.java
More file actions
51 lines (41 loc) · 1.27 KB
/
Enrollment.java
File metadata and controls
51 lines (41 loc) · 1.27 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
package nextstep.courses.domain.session;
import nextstep.users.domain.NsUser;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
public class Enrollment {
private final List<NsUser> users;
private final SessionCapacity sessionCapacity;
public Enrollment(List<NsUser> users, SessionCapacity sessionCapacity) {
this.users = users;
this.sessionCapacity = sessionCapacity;
}
public Enrollment(SessionCapacity sessionCapacity) {
this(new ArrayList<>(), sessionCapacity);
}
public Enrollment(int capacity) {
this(new ArrayList<>(), new SessionCapacity(capacity));
}
public Enrollment(List<NsUser> users) {
this(users, new SessionCapacity(0));
}
public void enroll(NsUser user) {
sessionCapacity.increase();
this.users.add(user);
}
@Override
public int hashCode() {
return Objects.hashCode(users);
}
@Override
public boolean equals(Object object) {
if (object == this) {
return true;
}
if (object == null || getClass() != object.getClass()) {
return false;
}
Enrollment enrollment = (Enrollment) object;
return Objects.equals(enrollment.users, this.users);
}
}