-
Notifications
You must be signed in to change notification settings - Fork 0
/
StateNotation.java
45 lines (37 loc) · 1.17 KB
/
StateNotation.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
package siteswapsuite;
import java.util.regex.Pattern;
class InvalidStateNotationException extends InvalidNotationException {
String message;
InvalidStateNotationException(String notation) {
this.message = "ERROR: string `" + notation + "' is not valid state notation";
}
public String getMessage() {
return this.message;
}
}
public enum StateNotation {
SIMPLE,
COMPLEX;
public static String charge = "(-?[0-9a-z])";
public static String simpleStateNotation = charge + "+";
public static String beat = "(\\(" + charge + "(" + "," + charge + ")*" + "\\))";
public static String complexStateNotation = "\\(" + beat + "+\\)";
public static StateNotation analyze(String string) throws InvalidStateNotationException {
if(Pattern.matches(simpleStateNotation, string)) {
return StateNotation.SIMPLE;
} else if(Pattern.matches(complexStateNotation, string)) {
return StateNotation.COMPLEX;
} else {
throw new InvalidStateNotationException(string);
}
}
public static StateNotation defaultNotationType(int numHands) {
if(numHands == 0) {
return StateNotation.SIMPLE;
} else if(numHands > 0) {
return StateNotation.COMPLEX;
} else {
return null;
}
}
}