-
Notifications
You must be signed in to change notification settings - Fork 174
Expand file tree
/
Copy pathValidation.java
More file actions
31 lines (26 loc) · 1.02 KB
/
Validation.java
File metadata and controls
31 lines (26 loc) · 1.02 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
import constant.GameConstant;
import java.util.HashSet;
import java.util.Set;
import java.util.regex.Pattern;
public final class Validation {
static final String TREE_DIGIT_REGEX = "^[0-9]{3}$";
static final String ONE_DIGIT_REGEX = "^[0-9]{1}$";
public static boolean checkThreeDigitNumber(String inputNumber) {
return Pattern.compile(TREE_DIGIT_REGEX).matcher(inputNumber).matches();
}
public static boolean checkDuplicateNumber(String inputNumber) {
Set<Character> chars = new HashSet<>();
for (char c : inputNumber.toCharArray()) {
chars.add(c);
}
return chars.size() == GameConstant.NUMBER_COUNT;
}
public static boolean checkEndCommand(String inputCommand) {
if (!Pattern.compile(ONE_DIGIT_REGEX).matcher(inputCommand).matches()) {
return false;
}
int command = Integer.parseInt(inputCommand);
return command == GameConstant.END_GAME_NUMBER
|| command == GameConstant.RESTART_GAME_NUMBER;
}
}