package core.framework.test.redis;

/**
 * @author neo
 */
class KeyMatcher {
    private final String pattern;

    KeyMatcher(String pattern) {
        this.pattern = pattern;
    }

    // only support '*' and '?', refer to https://redis.io/commands/keys
    boolean matches(String key) {
        int keyLength = key.length();
        int patternLength = pattern.length();
        boolean state[][] = new boolean[keyLength + 1][patternLength + 1];
        state[0][0] = true;     // empty key matches empty pattern
        for (int i = 0; i < patternLength; i++) {
            if (pattern.charAt(i) == '*') state[0][i + 1] = state[0][i];    // whether first empty matches pattern
        }
        for (int i = 0; i < keyLength; i++) {
            for (int j = 0; j < patternLength; j++) {
                char ch = pattern.charAt(j);
                if (key.charAt(i) == ch || ch == '?') {
                    state[i + 1][j + 1] = state[i][j];
                } else if (ch == '*') {
                    state[i + 1][j + 1] = state[i][j + 1] || state[i + 1][j];
                }
            }
        }
        return state[keyLength][patternLength];
    }
}

@@ -851,16 +851,29 @@
     if (
+ch == '?' %7C%7C 
 key.char
@@ -887,21 +887,8 @@
 = ch
- %7C%7C ch == '?'
 ) %7B%0A

fix check style