-
Notifications
You must be signed in to change notification settings - Fork 299
/
Copy pathSessionImageSize.java
57 lines (47 loc) · 1.73 KB
/
SessionImageSize.java
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;
public class SessionImageSize {
private static final int WIDTH_RATIO = 3;
private static final int HEIGHT_RATIO = 2;
private static final int WIDTH_MAXIMUM = 300;
private static final int HEIGHT_MAXIMUM = 200;
private int width;
private int height;
private String ratio;
public SessionImageSize(int width, int height) {
validation(width, height);
this.width = width;
this.height = height;
this.ratio = calculateRatio();
}
private void validation(int width, int height) {
widthAndHeightValidate(width, height);
ratioValidate(width, height);
}
private void ratioValidate(int width, int height) {
if (WIDTH_RATIO != calculaateWidthRatio(width) && HEIGHT_RATIO != calculaateHeightRatio(height)) {
throw new IllegalArgumentException(" 이미지 비율을 3:2만 가능합니다.");
}
}
private void widthAndHeightValidate(int width, int height) {
if (width < WIDTH_MAXIMUM || height < HEIGHT_MAXIMUM) {
throw new IllegalArgumentException(" 이미지의 크기는 세로 300, 가로 200 픽셀 이상만 가능합니다. ");
}
}
private String calculateRatio() {
return calculaateWidthRatio(width) + ":" + calculaateHeightRatio(height);
}
private int calculaateWidthRatio(int width) {
int divided = width / 100;
if(WIDTH_RATIO != divided){
divided = divided / WIDTH_RATIO;
}
return divided;
}
private int calculaateHeightRatio(int height) {
int divided = height / 100;
if(HEIGHT_RATIO != divided){
divided = divided / HEIGHT_RATIO;
}
return divided;
}
}