-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathNameValidCharactersRequirement.java
49 lines (38 loc) · 1.5 KB
/
NameValidCharactersRequirement.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
package com.jcp.automation.common.requirements;
import com.google.common.base.CharMatcher;
import com.jcp.automation.common.ErrorCodes;
import org.apache.commons.lang3.StringUtils;
/**
* @author ykrasnopolskiy
* @since 3/19/17.
*/
public class NameValidCharactersRequirement extends AbstractRequirement {
private String nameAlphabet = ".*[a-zA-Z]+.*";
private String repeatingCharacters = ".*(.)\\1\\1+.*";
public String getNameAlphabet() {
return nameAlphabet;
}
public void setNameAlphabet(String nameAlphabet) {
this.nameAlphabet = nameAlphabet;
}
public String getRepeatingCharacters() {
return repeatingCharacters;
}
public void setRepeatingCharacters(String repeatingCharacters) {
this.repeatingCharacters = repeatingCharacters;
}
/**
* The constructor is planned to be used only to instantiate Requirement inside Requirements enum
*/
NameValidCharactersRequirement(ErrorCodes associatedErrorIfNotMeetRequiement){
setErrorCode(associatedErrorIfNotMeetRequiement);
}
@Override
public boolean meets(Object objectToCheck) {
String nameToCheck = objectToCheck != null ? objectToCheck.toString() : null;
return StringUtils.isEmpty(nameToCheck)
|| (CharMatcher.ASCII.matchesAllOf(nameToCheck)
&& nameToCheck.matches(nameAlphabet)
&& !nameToCheck.toLowerCase().matches(repeatingCharacters));
}
}