in src/main/software/amazon/event/ruler/ByteMachine.java [998:1049]
private NameState findMatchPattern(final InputCharacter[] characters, final Patterns pattern) {
Set<SingleByteTransition> transitionsToProcess = new HashSet<>();
transitionsToProcess.add(startState);
ByteTransition shortcutTrans = null;
// Iterate down all possible paths in machine that match characters.
outerLoop: for (int i = 0; i < characters.length - 1; i++) {
Set<SingleByteTransition> nextTransitionsToProcess = new HashSet<>();
for (SingleByteTransition trans : transitionsToProcess) {
ByteTransition nextTrans = getTransition(trans, characters[i]);
for (SingleByteTransition eachTrans : nextTrans.expand()) {
// Shortcut and stop outer character loop
if (SHORTCUT_MATCH_TYPES.contains(pattern.type()) && eachTrans.isShortcutTrans()) {
shortcutTrans = eachTrans;
break outerLoop;
}
SingleByteTransition nextByteState = eachTrans.getNextByteState();
if (nextByteState == null) {
continue;
}
// We are interested in the first state that hasn't simply led back to trans
if (trans != nextByteState) {
nextTransitionsToProcess.add(nextByteState);
}
}
}
transitionsToProcess = nextTransitionsToProcess;
}
// Get all possible transitions for final character.
Set<ByteTransition> finalTransitionsToProcess = new HashSet<>();
if (shortcutTrans != null) {
finalTransitionsToProcess.add(shortcutTrans);
} else {
for (SingleByteTransition trans : transitionsToProcess) {
finalTransitionsToProcess.add(getTransition(trans, characters[characters.length - 1]));
}
}
// Check matches for all possible final transitions until we find the pattern we are looking for.
for (ByteTransition nextTrans : finalTransitionsToProcess) {
for (ByteMatch match : nextTrans.getMatches()) {
if (match.getPattern().equals(pattern)) {
return match.getNextNameState();
}
}
}
return null;
}