<commit_before>/*
 * Copyright 2018, TeamDev. All rights reserved.
 *
 * Redistribution and use in source and/or binary forms, with or without
 * modification, must retain the above copyright notice and the following
 * disclaimer.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */

package io.spine.js.generate;

import com.google.common.annotations.VisibleForTesting;
import io.spine.code.Depth;
import io.spine.code.Indent;

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkNotNull;
import static java.lang.String.join;
import static java.lang.System.lineSeparator;

/**
 * The aggregator of the JavaScript output.
 *
 * <p>This class serves as the JS code storage as well as provides the convenience methods for
 * adding the code.
 *
 * <p>The writable representation of the output may be obtained through the {@link #toString()}
 * method.
 */
@SuppressWarnings({"DuplicateStringLiteralInspection"
        /* The generated code duplicates the code used in test that checks it. */,
        "ClassWithTooManyMethods" /* A lot of simple utility methods for code generation. */})
public final class CodeLines {

    @VisibleForTesting
    static final String LINE_SEPARATOR = lineSeparator();

    /**
     * The modifier which is used to create variables.
     *
     * <p>Currently is set to ES6 {@code let}.
     */
    private static final String VARIABLE_MODIFIER = "let";

    private static final int STANDARD_INDENTATION = 2;

    /**
     * The indentation of the code, i.e. how many spaces each depth level takes.
     */
    private final Indent indentation;

    /**
     * The aggregator of the JS code.
     */
    private final List<CodeLine> codeLines;

    /**
     * The current depth of the code on which the next line will be added.
     */
    private Depth currentDepth;

    /**
     * Creates an instance of the {@code JsOutput} with the default indentation.
     */
    public CodeLines() {
        this(STANDARD_INDENTATION);
    }

    /**
     * Creates an instance of the {@code JsOutput} with the custom indentation.
     *
     * @param indentation
     *         the indentation to use
     */
    public CodeLines(int indentation) {
        this.codeLines = new ArrayList<>();
        this.currentDepth = Depth.zero();
        this.indentation = Indent.of(indentation);
    }

    /**
     * Appends another ouput to this output.
     *
     * @param output
     *         the code to add
     */
    public void addLinesFrom(CodeLines output) {
        checkArgument(indentation == output.indentation,
                      "Cannot merge code parts with different indentation.");
        checkArgument(currentDepth == output.currentDepth,
                      "Cannot merge code parts with different depth.");
        addLines(output.codeLines);
    }
<commit_msg>Use `equals` since primitives aren't used anymore<commit_after>/*
 * Copyright 2018, TeamDev. All rights reserved.
 *
 * Redistribution and use in source and/or binary forms, with or without
 * modification, must retain the above copyright notice and the following
 * disclaimer.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */

package io.spine.js.generate;

import com.google.common.annotations.VisibleForTesting;
import io.spine.code.Depth;
import io.spine.code.Indent;

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkNotNull;
import static java.lang.String.join;
import static java.lang.System.lineSeparator;

/**
 * The aggregator of the JavaScript output.
 *
 * <p>This class serves as the JS code storage as well as provides the convenience methods for
 * adding the code.
 *
 * <p>The writable representation of the output may be obtained through the {@link #toString()}
 * method.
 */
@SuppressWarnings({"DuplicateStringLiteralInspection"
        /* The generated code duplicates the code used in test that checks it. */,
        "ClassWithTooManyMethods" /* A lot of simple utility methods for code generation. */})
public final class CodeLines {

    @VisibleForTesting
    static final String LINE_SEPARATOR = lineSeparator();

    /**
     * The modifier which is used to create variables.
     *
     * <p>Currently is set to ES6 {@code let}.
     */
    private static final String VARIABLE_MODIFIER = "let";

    private static final int STANDARD_INDENTATION = 2;

    /**
     * The indentation of the code, i.e. how many spaces each depth level takes.
     */
    private final Indent indentation;

    /**
     * The aggregator of the JS code.
     */
    private final List<CodeLine> codeLines;

    /**
     * The current depth of the code on which the next line will be added.
     */
    private Depth currentDepth;

    /**
     * Creates an instance of the {@code JsOutput} with the default indentation.
     */
    public CodeLines() {
        this(STANDARD_INDENTATION);
    }

    /**
     * Creates an instance of the {@code JsOutput} with the custom indentation.
     *
     * @param indentation
     *         the indentation to use
     */
    public CodeLines(int indentation) {
        this.codeLines = new ArrayList<>();
        this.currentDepth = Depth.zero();
        this.indentation = Indent.of(indentation);
    }

    /**
     * Appends another ouput to this output.
     *
     * @param output
     *         the code to add
     */
    public void addLinesFrom(CodeLines output) {
        checkArgument(indentation.equals(output.indentation),
                      "Cannot merge code parts with different indentation.");
        checkArgument(currentDepth.equals(output.currentDepth),
                      "Cannot merge code parts with different depth.");
        addLines(output.codeLines);
    }

{'fraction_non_alphanumeric': 0.08056300268096515, 'fraction_numerical': 0.0016085790884718498, 'mean_word_length': 3.0615133369624385, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 13, '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': '5218941', 'n_tokens_mistral': 2051, 'n_tokens_neox': 1922, 'n_words': 788}