-
Notifications
You must be signed in to change notification settings - Fork 33
Expand file tree
/
Copy pathValidation.java
More file actions
35 lines (30 loc) · 1018 Bytes
/
Validation.java
File metadata and controls
35 lines (30 loc) · 1018 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
34
35
package validation;
import exception.ErrorCode;
import exception.RacingCarException;
public class Validation {
// Car 이름 5자 이상 제한 검증
public static void validCarNames(String[] carNames) {
for (String carName : carNames) {
if (!isShortOrEqualFiveAndNotEmptyString(carName)) {
throw new RacingCarException(ErrorCode.INVALID_CAR_NAME_LENGTH);
}
}
}
// 시도횟수 양수 정수인지 검사
public static void validAttemptCountInput(String attemptCount) {
try {
Integer.parseInt(attemptCount);
} catch (Exception e) {
throw new RacingCarException(ErrorCode.INVALID_ATTEMPT_COUNT_INPUT);
}
}
// 랜덤 숫자 검증
public static void validRandomValue(int randomInt) {
if (!(randomInt >= 0 && randomInt <= 9)) {
throw new RacingCarException(ErrorCode.INVALID_RANDOM_VALUE);
}
}
private static boolean isShortOrEqualFiveAndNotEmptyString(String string) {
return string.length() <= 5 && !string.isEmpty();
}
}