class DynamicTableNameParser implements ISqlParser {

    @Override
    public SqlInfo parser(MetaObject metaObject, String sql) {
        // fix-issue:https://gitee.com/baomidou/mybatis-plus/issues/I1K7Q1
        // Assert.isFalse(CollectionUtils.isEmpty(tableNameHandlerMap), "tableNameHandlerMap is empty.");
        if (allowProcess(metaObject)) {
            TableNameParser parser = new TableNameParser(sql);
            List<TableNameParser.SqlToken> names = new ArrayList<>();
            parser.accept(names::add);
            StringBuilder builder = new StringBuilder();
            int last = 0;
            for (TableNameParser.SqlToken name : names) {
                int start = name.getStart();
                if (start != last) {
                    builder.append(sql, last, start);
                    String value = name.getValue();
                    ITableNameHandler handler = tableNameHandlerMap.get(value);
                    if (handler != null) {
                        builder.append(handler.dynamicTableName(metaObject, sql, value));
                    } else {
                        builder.append(value);
                    }
                }
                last = name.getEnd();
            }
            if (last != sql.length()) {
                builder.append(sql.substring(last));
            }
            return SqlInfo.of(builder.toString());
        }
        return null;
    }

}