<commit_before>import { Build } from '../trait/build/fb-build';
import { Indenter } from '../../../../../classes/indent/indenter';
import { Field } from '../../../../../classes/parse/field/field';

export class FluidBuilderClass {

    constructor(
        readonly indenter?: Indenter
    ) {
        this.indenter = indenter || new Indenter();
    }

    declarationAndBody(fields: Field[], methods: string[], targetBuild: Build): string {
        return [
            this.builderClassDeclaration(),
            this.builderClassBody(fields, methods, targetBuild),
            '}'
        ].join('\n\n');
    }

    private builderClassDeclaration(): string {
        return '/** 2017-08-06 Generated Fluid Builder github.com/bvkatwijk/fluid-builder-generator */'
            + '\npublic static class SingleFieldSampleBuilder implements WithFirstField, BuildSingleFieldSample {';
    }

    private builderClassBody(fields: Field[], methods: string[], targetBuild: Build): string {
        return this
            .indenter
            .indent([
                this.mutableFieldDeclarations(fields),
                methods.join('\n\n'),
                targetBuild.method('firstField')
            ].join('\n\n'));
    }

    private builderMethodDeclaration(): string {
        return 'public static WithFirstField builder() {'
            + '\n' + this.indenter.indent('return new SingleFieldSampleBuilder();')
            + '\n}';
    }<commit_msg>Use withs instead of strings<commit_after>import { With } from '../trait/with/fb-with';
import { Build } from '../trait/build/fb-build';
import { Indenter } from '../../../../../classes/indent/indenter';
import { Field } from '../../../../../classes/parse/field/field';

export class FluidBuilderClass {

    constructor(
        readonly indenter?: Indenter
    ) {
        this.indenter = indenter || new Indenter();
    }

    declarationAndBody(fields: Field[], withs: With[], targetBuild: Build): string {
        return [
            this.builderClassDeclaration(withs),
            this.builderClassBody(
                fields,
                withs.map(it => it.method()),
                targetBuild),
            '}'
        ].join('\n\n');
    }

    private builderClassDeclaration(withs: With[]): string {
        return '/** 2017-08-06 Generated Fluid Builder github.com/bvkatwijk/fluid-builder-generator */'
            + '\npublic static class SingleFieldSampleBuilder implements ' + this.getWithTypes(withs) + ' {';
    }

    private getWithTypes(withs: With[]): string {
        return withs
            .map(it => it.getType())
            .join(', ') + ', BuildSingleFieldSample';
    }

    private builderClassBody(fields: Field[], methods: string[], targetBuild: Build): string {
        return this
            .indenter
            .indent([
                this.mutableFieldDeclarations(fields),
                methods.join('\n\n'),
                targetBuild.method(fields.map(it => it.name).join(', '))
            ].join('\n\n'));
    }

    private builderMethodDeclaration(): string {
        return 'public static WithFirstField builder() {'
            + '\n' + this.indenter.indent('return new SingleFieldSampleBuilder();')
            + '\n}';
    }
{'fraction_non_alphanumeric': 0.1501233045622688, 'fraction_numerical': 0.004932182490752158, 'mean_word_length': 2.1596884128529696, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 6, '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': '3436941', 'n_tokens_mistral': 871, 'n_tokens_neox': 855, 'n_words': 183}