<commit_before>package org.xcolab.service.utils.db.jooq.generator;

import org.jooq.tools.StringUtils;
import org.jooq.util.DefaultGeneratorStrategy;
import org.jooq.util.Definition;

public class XColabGeneratorStrategy extends DefaultGeneratorStrategy {

    private static final String[] TABLE_PREFIXES = {"xcolab_", "members_", "contest_",
            "content_", "proposal_", "comment_", "files_", "balloon_", "admin_", "activities_",
            "flagging_", "filtering_","sharedcolab_"};

    private static String toUpperCase(String string) {
        if (string != null && !string.isEmpty()) {
            return Character.toUpperCase(string.charAt(0))
                    + string.substring(1);
        } else {
            return string;
        }
    }

    @Override
    public String getJavaIdentifier(Definition definition) {
        // regex to split camel case taken (and adapted) from
        // https://stackoverflow.com/questions/7593969/regex-to-split-camelcase-or-titlecase-advanced/7599674#7599674

        final String unprefixedTableName = cleanUpSchemeAndPrefix(definition.getOutputName());
        final String underscoreSeparatedName = StringUtils.join(
                unprefixedTableName
                        .split("(?<=[a-z0-9])(?=[A-Z0-9])|(?<=[A-Z0-9])(?=[A-Z0-9][a-z0-9])"), "_");
        return underscoreSeparatedName.toUpperCase();
    }

    @Override
    public String getJavaSetterName(Definition definition, Mode mode) {
        return "set" + toUpperCase(definition.getOutputName());
    }

    @Override
    public String getJavaGetterName(Definition definition, Mode mode) {
        return "get" + toUpperCase(definition.getOutputName());
    }

    @Override
    public String getJavaClassName(Definition definition, Mode mode) {
        StringBuilder result = new StringBuilder();
        if (containsPrefix(definition.getOutputName())) {
            result.append(cleanUpSchemeAndPrefix(definition.getOutputName()));
            if (mode == Mode.DEFAULT) {
                result.append("Table");
            }
        } else {
            result.append(StringUtils.toCamelCase(definition.getOutputName()));
        }
        if (mode == Mode.RECORD) {
            result.append("Record");
        } else if (mode == Mode.DAO) {
            result.append("Dao");
        } else if (mode == Mode.INTERFACE) {
            result.insert(0, "I");
        }

        return result.toString();
    }

    private boolean containsPrefix(String string) {

        for (String prefix : TABLE_PREFIXES) {
            if (string.startsWith(prefix) && (string.length() != prefix.length())) {
                return true;
            }
        }
        return false;
    }

    private String cleanUpSchemeAndPrefix(String val) {
        String ret = val;

        for (String prefix : TABLE_PREFIXES) {
            if( ret.length() != prefix.length() ){
                ret = ret.replace(prefix, "");
            }
        }
        return ret;
    }
}<commit_msg>Fixed table name generation for liferay tables without prefix<commit_after>package org.xcolab.service.utils.db.jooq.generator;

import org.jooq.tools.StringUtils;
import org.jooq.util.DefaultGeneratorStrategy;
import org.jooq.util.Definition;

public class XColabGeneratorStrategy extends DefaultGeneratorStrategy {

    private static final String[] TABLE_PREFIXES = {"xcolab_", "members_", "contest_",
            "content_", "proposal_", "comment_", "files_", "balloon_", "admin_", "activities_",
            "flagging_", "filtering_","sharedcolab_"};

    private static String toUpperCase(String string) {
        if (string != null && !string.isEmpty()) {
            return Character.toUpperCase(string.charAt(0))
                    + string.substring(1);
        } else {
            return string;
        }
    }

    @Override
    public String getJavaIdentifier(Definition definition) {
        // regex to split camel case taken (and adapted) from
        // https://stackoverflow.com/questions/7593969/regex-to-split-camelcase-or-titlecase-advanced/7599674#7599674

        final String unprefixedTableName = cleanUpSchemeAndPrefix(definition.getOutputName());
        final String underscoreSeparatedName = StringUtils.join(
                unprefixedTableName
                        .split("(?<=[a-z0-9])(?=[A-Z0-9])|(?<=[A-Z0-9])(?=[A-Z0-9][a-z0-9])"), "_");
        return underscoreSeparatedName.toUpperCase();
    }

    @Override
    public String getJavaSetterName(Definition definition, Mode mode) {
        return "set" + toUpperCase(definition.getOutputName());
    }

    @Override
    public String getJavaGetterName(Definition definition, Mode mode) {
        return "get" + toUpperCase(definition.getOutputName());
    }

    @Override
    public String getJavaClassName(Definition definition, Mode mode) {
        StringBuilder result = new StringBuilder();
        if (containsPrefix(definition.getOutputName())) {
            result.append(cleanUpSchemeAndPrefix(definition.getOutputName()));
        } else {
            result.append(definition.getOutputName());
        }
        if (mode == Mode.DEFAULT) {
            result.append("Table");
        }else if (mode == Mode.RECORD) {
            result.append("Record");
        } else if (mode == Mode.DAO) {
            result.append("Dao");
        } else if (mode == Mode.INTERFACE) {
            result.insert(0, "I");
        }

        return result.toString();
    }

    private boolean containsPrefix(String string) {

        for (String prefix : TABLE_PREFIXES) {
            if (string.startsWith(prefix) && (string.length() != prefix.length())) {
                return true;
            }
        }
        return false;
    }

    private String cleanUpSchemeAndPrefix(String val) {
        String ret = val;

        for (String prefix : TABLE_PREFIXES) {
            if( ret.length() != prefix.length() ){
                ret = ret.replace(prefix, "");
            }
        }
        return ret;
    }
}
{'fraction_non_alphanumeric': 0.12456344586728754, 'fraction_numerical': 0.011308830866456012, 'mean_word_length': 2.4209328782707624, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 3, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6446179', 'n_tokens_mistral': 1723, 'n_tokens_neox': 1654, 'n_words': 335}