in juneau-core/juneau-marshall/src/main/java/org/apache/juneau/objecttools/TimeMatcherFactory.java [115:348]
public TimeMatcher(SimpleDateFormat[] f, String s) {
// Possible patterns:
// >2000, <2000, >=2000, <=2000, > 2000, 2000 - 2001, '2000', >'2000', '2000'-'2001', '2000' - '2001'
// Possible states:
// S01 = Looking for [<]/[>]/quote/NUM ([>]=S02, [<]=S03, [']=S05, ["]=S06, NUM=S08)
// S02 = Found [>], looking for [=]/quote/NUM ([=]=S04, [']=S05, ["]=S06, NUM=S08)
// S03 = Found [<], looking for [=]/quote/NUM ([=]=S04, [']=S05, ["]=S06, NUM=S08)
// S04 = Found [>=] or [<=], looking for quote/NUM ([']=S05, ["]=S06, NUM=S08)
// S05 = Found ['], looking for ['] ([']=S01)
// S06 = Found ["], looking for ["] (["]=S01)
// S07 = Found [123"] or [123'], looking for WS (WS=S09)
// S08 = Found [2], looking for WS (WS=S09)
// S09 = Found [2000 ], looking for [-]/quote/NUM ([-]=S10, [']=S11, ["]=S12, NUM=S13)
// S10 = Found [2000 -], looking for quote/NUM ([']=S11, ["]=S12, NUM=S13)
// S11 = Found [2000 - '], looking for ['] ([']=S01)
// S12 = Found [2000 - "], looking for ["] (["]=S01)
// S13 = Found [2000 - 2], looking for WS (WS=S01)
StateMachineState state = S01;
int mark = 0;
Equality eq = Equality.NONE;
String s1 = null, s2 = null;
int i;
char c = 0;
for (i = 0; i < s.trim().length(); i++) {
c = s.charAt(i);
if (state == S01) {
// S01 = Looking for [>]/[<]/quote/NUM ([>]=S02, [<]=S03, [']=S05, ["]=S06, NUM=S08)
if (WS.contains(c)) {
state = S01;
} else if (c == '>') {
state = S02;
eq = Equality.GT;
} else if (c == '<') {
state = S03;
eq = Equality.LT;
} else if (c == '\'') {
state = S05;
mark = i+1;
} else if (c == '"') {
state = S06;
mark = i+1;
} else if (DT.contains(c)) {
state = S08;
mark = i;
} else {
break;
}
} else if (state == S02) {
// S02 = Found [>], looking for [=]/quote/NUM ([=]=S04, [']=S05, ["]=S06, NUM=S08)
if (WS.contains(c)) {
state = S02;
} else if (c == '=') {
state = S04;
eq = Equality.GTE;
} else if (c == '\'') {
state = S05;
mark = i+1;
} else if (c == '"') {
state = S06;
mark = i+1;
} else if (DT.contains(c)) {
state = S08;
mark = i;
} else {
break;
}
} else if (state == S03) {
// S03 = Found [<], looking for [=]/quote/NUM ([=]=S04, [']=S05, ["]=S06, NUM=S08)
if (WS.contains(c)) {
state = S03;
} else if (c == '=') {
state = S04;
eq = Equality.LTE;
} else if (c == '\'') {
state = S05;
mark = i+1;
} else if (c == '"') {
state = S06;
mark = i+1;
} else if (DT.contains(c)) {
state = S08;
mark = i;
} else {
break;
}
} else if (state == S04) {
// S04 = Found [>=] or [<=], looking for quote/NUM ([']=S05, ["]=S06, NUM=S08)
if (WS.contains(c)) {
state = S04;
} else if (c == '\'') {
state = S05;
mark = i+1;
} else if (c == '"') {
state = S06;
mark = i+1;
} else if (DT.contains(c)) {
state = S08;
mark = i;
} else {
break;
}
} else if (state == S05) {
// S05 = Found ['], looking for ['] ([']=S07)
if (c == '\'') {
state = S07;
s1 = s.substring(mark, i);
}
} else if (state == S06) {
// S06 = Found ["], looking for ["] (["]=S07)
if (c == '"') {
state = S07;
s1 = s.substring(mark, i);
}
} else if (state == S07) {
// S07 = Found [123"] or [123'], looking for WS (WS=S09)
if (WS.contains(c)) {
state = S09;
} else if (c == '-') {
state = S10;
} else {
break;
}
} else if (state == S08) {
// S08 = Found [1], looking for WS (WS=S09)
if (WS.contains(c)) {
state = S09;
s1 = s.substring(mark, i);
}
} else if (state == S09) {
// S09 = Found [2000 ], looking for [-]/[>]/[<]/quote/NUM ([-]=S10, [>]=S02, [<]=S03, [']=S05, ["]=S06, NUM=S08)
if (WS.contains(c)) {
state = S09;
} else if (c == '-') {
state = S10;
} else if (c == '>') {
state = S02;
l.add(new TimestampRange(f, eq, s1));
eq = Equality.GT;
s1 = null;
} else if (c == '<') {
state = S03;
l.add(new TimestampRange(f, eq, s1));
eq = Equality.LT;
s1 = null;
} else if (c == '\'') {
state = S05;
l.add(new TimestampRange(f, eq, s1));
mark = i+1;
eq = null;
s1 = null;
} else if (c == '"') {
state = S06;
l.add(new TimestampRange(f, eq, s1));
mark = i+1;
eq = null;
s1 = null;
} else if (DT.contains(c)) {
state = S08;
l.add(new TimestampRange(f, eq, s1));
eq = null;
s1 = null;
mark = i;
} else {
break;
}
} else if (state == S10) {
// S10 = Found [2000 -], looking for quote/NUM ([']=S11, ["]=S12, NUM=S13)
if (WS.contains(c)) {
state = S10;
} else if (c == '\'') {
state = S11;
mark = i+1;
} else if (c == '"') {
state = S12;
mark = i+1;
} else if (DT.contains(c)) {
state = S13;
mark = i;
} else {
break;
}
} else if (state == S11) {
// S11 = Found [2000 - '], looking for ['] ([']=S01)
if (c == '\'') {
state = S01;
s2 = s.substring(mark, i);
l.add(new TimestampRange(f, s1, s2));
s1 = null;
s2 = null;
}
} else if (state == S12) {
// S12 = Found [2000 - "], looking for ["] (["]=S01)
if (c == '"') {
state = S01;
s2 = s.substring(mark, i);
l.add(new TimestampRange(f, s1, s2));
s1 = null;
s2 = null;
}
} else /* (state == S13) */ {
// S13 = Found [2000 - 2], looking for WS (WS=S01)
if (WS.contains(c)) {
state = S01;
s2 = s.substring(mark, i);
l.add(new TimestampRange(f, s1, s2));
s1 = null;
s2 = null;
}
}
}
if (i != s.length())
throw new PatternException("Invalid range pattern ({0}): pattern=[{1}], pos=[{2}], char=[{3}]", state, s, i, c);
if (state == S01) {
// No tokens found.
} else if (state == S02 || state == S03 || state == S04 || state == S05 || state == S06 || state == S10 || state == S11 || state == S12) {
throw new PatternException("Invalid range pattern (E{0}): {1}", state, s);
} else if (state == S07) {
l.add(new TimestampRange(f, eq, s1));
} else if (state == S08) {
s1 = s.substring(mark).trim();
l.add(new TimestampRange(f, eq, s1));
} else /* (state == S13) */ {
s2 = s.substring(mark).trim();
l.add(new TimestampRange(f, s1, s2));
}
ranges = l.toArray(new TimestampRange[l.size()]);
}