-
Notifications
You must be signed in to change notification settings - Fork 307
Expand file tree
/
Copy pathSessionImage.java
More file actions
59 lines (49 loc) · 1.95 KB
/
SessionImage.java
File metadata and controls
59 lines (49 loc) · 1.95 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
package nextstep.courses.domain.session;
import nextstep.courses.InvalidImageException;
import java.util.Objects;
public class SessionImage {
private static final int MAX_IMAGE_SIZE = 1000000;
private static final int MIN_WIDTH = 300;
private static final int MIN_HEIGHT = 200;
private static final double WIDTH_PER_HEIGHT = 1.5;
private final int width;
private final int height;
private final int size;
private final SessionImageType imageType;
public SessionImage(int width, int height, int size, String imageType) {
this(width, height, size, SessionImageType.of(imageType));
}
public SessionImage(int width, int height, int size, SessionImageType imageType) {
this.width = width;
this.height = height;
this.size = size;
this.imageType = imageType;
checkValidSessionImage();
}
private void checkValidSessionImage() {
if (this.width < MIN_WIDTH || this.height < MIN_HEIGHT) {
throw new InvalidImageException("이미지의 width는 300픽셀, height는 200픽셀 이상이어야 한다.");
}
if ((double) this.width / this.height != WIDTH_PER_HEIGHT) {
throw new InvalidImageException("이미지의 width, height의 비율은 3:2여야 한다.");
}
if (this.size > MAX_IMAGE_SIZE) {
throw new InvalidImageException("이미지의 크기는 1MB 이하여야 한다.");
}
}
@Override
public int hashCode() {
return Objects.hash(width, height, size, imageType);
}
@Override
public boolean equals(Object object) {
if (object == this) {
return true;
}
if (object == null || getClass() != object.getClass()) {
return false;
}
SessionImage image = (SessionImage) object;
return Objects.equals(image.imageType, imageType) && image.width == width && image.height == height && image.size == size;
}
}