-
Notifications
You must be signed in to change notification settings - Fork 307
Expand file tree
/
Copy pathSessionCapacity.java
More file actions
57 lines (46 loc) · 1.46 KB
/
SessionCapacity.java
File metadata and controls
57 lines (46 loc) · 1.46 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
package nextstep.courses.domain.session;
import nextstep.courses.CannotEnrollException;
import java.util.Objects;
public class SessionCapacity {
private static final int MIN_CAPACITY = 1;
private int capacity;
private final int maxCapacity;
public SessionCapacity(int capacity, int maxCapacity) {
this.capacity = capacity;
this.maxCapacity = maxCapacity;
checkValidCapacity();
}
public SessionCapacity(int maxCapacity) {
this(0, maxCapacity);
}
private void checkValidCapacity() {
if (maxCapacity < MIN_CAPACITY) {
throw new IllegalArgumentException();
}
isValidCapacity();
}
public void increase() {
capacity++;
isValidCapacity();
}
@Override
public int hashCode() {
return Objects.hash(capacity, maxCapacity);
}
@Override
public boolean equals(Object object) {
if (object == this) {
return true;
}
if (object == null || getClass() != object.getClass()) {
return false;
}
SessionCapacity sessionCapacity = (SessionCapacity) object;
return sessionCapacity.capacity == this.capacity && sessionCapacity.maxCapacity == this.maxCapacity;
}
private void isValidCapacity(){
if(this.capacity > this.maxCapacity) {
throw new CannotEnrollException("최대 수용 인원을 현재 인원이 초과할 수 없다.");
}
}
}