private void addSuffixMatch()

in src/main/software/amazon/event/ruler/ByteMachine.java [611:636]


    private void addSuffixMatch(final byte[] val, final Set<NameStateWithPattern> transitionTo,
                                final Map<NameState, List<Patterns>> failedAnythingButs) {
        // we only attempt to evaluate suffix matches when there is suffix match in current byte machine instance.
        // it works as performance level to avoid other type of matches from being affected by suffix checking.
        if (hasSuffix.get() > 0) {
            ByteTransition trans = startState;
            // check the byte in reverse order in order to harvest suffix matches
            for (int valIndex = val.length - 1; valIndex >= 0; valIndex--) {
                final ByteTransition nextTrans = getTransition(trans, val[valIndex]);
                for (ByteMatch match : nextTrans.getMatches()) {
                    // given we are traversing in reverse order (from right to left), only suffix matches are eligible
                    // to be collected.
                    MatchType patternType = match.getPattern().type();
                    if (patternType == SUFFIX || patternType == SUFFIX_EQUALS_IGNORE_CASE) {
                        transitionTo.add(new NameStateWithPattern(match.getNextNameState(), match.getPattern()));
                    } else if (patternType == ANYTHING_BUT_SUFFIX) {
                        addToAnythingButsMap(failedAnythingButs, match.getNextNameState(), match.getPattern());
                    }
                }
                trans = nextTrans.getTransitionForNextByteStates();
                if (trans == null) {
                    break;
                }
            }
        }
    }