-
Notifications
You must be signed in to change notification settings - Fork 4
/
CounterStringValidator.java
47 lines (39 loc) · 1.41 KB
/
CounterStringValidator.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
package uk.co.compendiumdev.javafortesters.domain.counterstrings;
public class CounterStringValidator {
private final String counterString;
public CounterStringValidator(String counterString) {
this.counterString = counterString;
}
public boolean isValid() {
String[] values = counterString.split("\\*");
boolean firstOnly = true;
if(values.length==0){
return false;
}
for(String position : values){
int positionVal = -1;
if(position.length()>0){
positionVal=Integer.parseInt(position);
positionVal = positionVal-1;
}else{
// when first char is an * then check the first char
if(firstOnly){
positionVal=0;
}
}
firstOnly=false;
try {
if (counterString.charAt(positionVal) != '*') {
System.out.println("Error validating: " + counterString);
System.out.println("Position " + position + " is not a delimter it is " + counterString.charAt(positionVal));
return false;
}
}catch(Exception e){
System.out.println("Error validating: " + counterString);
e.printStackTrace();
return false;
}
}
return true;
}
}