<commit_before>package net.jarlehansen.proto2javame.business.sourcebuilder.main;

import net.jarlehansen.proto2javame.business.sourcebuilder.resource.CommonResourceConstants;
import net.jarlehansen.proto2javame.business.sourcebuilder.resource.JavaSourceCodeUtil;
import net.jarlehansen.proto2javame.business.sourcebuilder.resource.ResourceFormatUtil;
import net.jarlehansen.proto2javame.domain.proto.FieldData;
import net.jarlehansen.proto2javame.domain.proto.ProtoFileInput;
import net.jarlehansen.proto2javame.domain.proto.ValidScopes;

import java.util.Date;

/**
 * @author <EMAIL> <NAME>
 */
public final class MainClassBuilderImpl implements MainClassBuilder {
    private final ResourceFormatUtil resourceFormat = ResourceFormatUtil.MAIN;

    private MainClassBuilderImpl() {
    }

    public static MainClassBuilder newInstance() {
        return new MainClassBuilderImpl();
    }

    public StringBuilder createMainClass(final String className, final ProtoFileInput protoInput) {
        final StringBuilder builder = new StringBuilder();
        builder.append(createPackage(protoInput));
        builder.append(createImports());
        builder.append(createClassInitialization(className));
        builder.append(createFields(protoInput));
        builder.append(createNewBuilderMethod());
        builder.append(createConstructor(className, protoInput));

        return builder;
    }

    private String createPackage(final ProtoFileInput protoInput) {
        final String packageName;

        if (protoInput.getPackageName() == null || "".equals(protoInput.getPackageName())) {
            packageName = "";
        } else {
            packageName = resourceFormat.getString(MainClassConstants.KEY_PACKAGE, protoInput.getPackageName());
        }

        return packageName;
    }

    private String createImports() {
        final String mainPackage = ResourceFormatUtil.COMMON.getString(CommonResourceConstants.KEY_IMPORTS_PACKAGE_MAIN);

        return resourceFormat.getString(MainClassConstants.KEY_IMPORTS, new Date().toString(), mainPackage, mainPackage +
                ResourceFormatUtil.COMMON.getString(CommonResourceConstants.KEY_IMPORTS_PACKAGE_FACTORY), mainPackage +
                ResourceFormatUtil.COMMON.getString(CommonResourceConstants.KEY_IMPORTS_PACKAGE_INPUT), mainPackage +
                ResourceFormatUtil.COMMON.getString(CommonResourceConstants.KEY_IMPORTS_PACKAGE_UTIL), mainPackage +
                ResourceFormatUtil.COMMON.getString(CommonResourceConstants.KEY_IMPORTS_PACKAGE_OUTPUT));
    }


    private String createClassInitialization(final String className) {
        return resourceFormat.getString(MainClassConstants.KEY_INIT, className);
    }

    private String createFields(final ProtoFileInput protoInput) {
        final StringBuilder builder = new StringBuilder();

        for (FieldData field : protoInput.getFields()) {
            if (field.isList()) {
                builder.append(resourceFormat.getString(MainClassConstants.KEY_FIELDS, field.getListImpl()
                        .getImplementation(), field.getName()));
            } else {
                builder.append(resourceFormat.getString(MainClassConstants.KEY_FIELDS, field.getType().getJavaType(),
                        field.getName()));<commit_msg>added createStaticUnknownTagHandlerInitialization() and updated createImports() to include the UnknownTagHandler interface/implementation<commit_after>package net.jarlehansen.proto2javame.business.sourcebuilder.main;

import net.jarlehansen.proto2javame.business.sourcebuilder.resource.CommonResourceConstants;
import net.jarlehansen.proto2javame.business.sourcebuilder.resource.JavaSourceCodeUtil;
import net.jarlehansen.proto2javame.business.sourcebuilder.resource.ResourceFormatUtil;
import net.jarlehansen.proto2javame.domain.proto.FieldData;
import net.jarlehansen.proto2javame.domain.proto.ProtoFileInput;
import net.jarlehansen.proto2javame.domain.proto.ValidScopes;

import java.util.Date;

/**
 * @author <EMAIL> <NAME>
 */
public final class MainClassBuilderImpl implements MainClassBuilder {
    private final ResourceFormatUtil resourceFormat = ResourceFormatUtil.MAIN;

    private MainClassBuilderImpl() {
    }

    public static MainClassBuilder newInstance() {
        return new MainClassBuilderImpl();
    }

    public StringBuilder createMainClass(final String className, final ProtoFileInput protoInput) {
        final StringBuilder builder = new StringBuilder();
        builder.append(createPackage(protoInput));
        builder.append(createImports());
        builder.append(createClassInitialization(className));
        builder.append(createStaticUnknownTagHandlerInitialization());
        builder.append(createFields(protoInput));
        builder.append(createNewBuilderMethod());
        builder.append(createConstructor(className, protoInput));

        return builder;
    }

    private String createPackage(final ProtoFileInput protoInput) {
        final String packageName;

        if (protoInput.getPackageName() == null || "".equals(protoInput.getPackageName())) {
            packageName = "";
        } else {
            packageName = resourceFormat.getString(MainClassConstants.KEY_PACKAGE, protoInput.getPackageName());
        }

        return packageName;
    }

    private String createImports() {
        final String mainPackage = ResourceFormatUtil.COMMON.getString(CommonResourceConstants.KEY_IMPORTS_PACKAGE_MAIN);

        return resourceFormat.getString(MainClassConstants.KEY_IMPORTS, new Date().toString(), mainPackage, mainPackage +
                ResourceFormatUtil.COMMON.getString(CommonResourceConstants.KEY_IMPORTS_PACKAGE_FACTORY), mainPackage +
                ResourceFormatUtil.COMMON.getString(CommonResourceConstants.KEY_IMPORTS_PACKAGE_INPUT), mainPackage +
                ResourceFormatUtil.COMMON.getString(CommonResourceConstants.KEY_IMPORTS_PACKAGE_UTIL), mainPackage +
                ResourceFormatUtil.COMMON.getString(CommonResourceConstants.KEY_IMPORTS_PACKAGE_OUTPUT), mainPackage +
                ResourceFormatUtil.COMMON.getString(CommonResourceConstants.KEY_IMPORTS_PACKAGE_TAGHANDLER));
    }


    private String createClassInitialization(final String className) {
        return resourceFormat.getString(MainClassConstants.KEY_INIT, className);
    }

    private String createStaticUnknownTagHandlerInitialization() {
        return resourceFormat.getString(MainClassConstants.KEY_FIELDS_STATIC_UNKNOWNTAGHANDLER);
    }

    private String createFields(final ProtoFileInput protoInput) {
        final StringBuilder builder = new StringBuilder();

        for (FieldData field : protoInput.getFields()) {
            if (field.isList()) {
                builder.append(resourceFormat.getString(MainClassConstants.KEY_FIELDS, field.getListImpl()
                        .getImplementation(), field.getName()));
            } else {
                builder.append(resourceFormat.getString(MainClassConstants.KEY_FIELDS, field.getType().getJavaType(),
                        field.getName()));
{'fraction_non_alphanumeric': 0.08454481298517996, 'fraction_numerical': 0.0019760056457304165, 'mean_word_length': 3.9796205200281096, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, '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': '6895027', 'n_tokens_mistral': 1796, 'n_tokens_neox': 1752, 'n_words': 280}