forked from next-step/java-baseball-precourse
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathInputValidator.java
More file actions
33 lines (28 loc) · 907 Bytes
/
InputValidator.java
File metadata and controls
33 lines (28 loc) · 907 Bytes
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
package view;
public class InputValidator {
public static void validateString(String input) {
isNotEmpty(input);
}
public static void validatePositiveNumber(String input) {
isNotEmpty(input);
isInteger(input);
isPositive(input);
}
private static void isNotEmpty(String input) {
if (input.isEmpty()) {
throw new IllegalArgumentException("입력 문자열이 공백입니다.");
}
}
private static void isInteger(String input) {
try {
Integer.parseInt(input);
} catch (NumberFormatException e) {
throw new IllegalArgumentException("정수를 입력해 주세요.");
}
}
private static void isPositive(String input) {
if (Integer.parseInt(input) < 1) {
throw new IllegalArgumentException("양수를 입력해 주세요.");
}
}
}