class TokenTtlTrie {

    public Long scan(byte[] rawString) {
        int bestPriority = Integer.MAX_VALUE;
        float ttl = 0;
        int curState = 0;
        for (byte b : rawString) {
            short charClass = charClasses[0xff & (int) b];
            if (curState == REJECT_TOKEN) {
                if (charClass == DELIMITER_CHAR_CLASS) {
                    curState = 0;
                }
                continue;
            }
            switch (charClass) {
                case UNRECOGNIZED_CHAR_CLASS:
                    curState = REJECT_TOKEN;
                    continue;
                case DELIMITER_CHAR_CLASS:
                    int statePriority = statePriorities[curState];
                    if (statePriority < bestPriority) {
                        bestPriority = statePriority;
                        ttl = stateTTLs[curState];
                    }
                    curState = 0;
                    continue;
                default:
                    curState = transitionTable[curState * charClassCount + charClass];
                    break;
            }
        }
        // Check the last token's state, as it might not have a delimiter
        if (curState != REJECT_TOKEN) {
            int statePriority = statePriorities[curState];
            if (statePriority < bestPriority) {
                bestPriority = statePriority;
                ttl = stateTTLs[curState];
            }
        }
        return bestPriority == Integer.MAX_VALUE ? null : (long) ttl;
    }

      TokenTtlTrie(int charClassCount, short[] charClasses, int[] transitionTable, int[] statePriorities, long[] stateTTLs);

}