<commit_before>package it.sevenbits;

import it.sevenbits.exceptions.FormatterException;
import it.sevenbits.exceptions.StreamException;
import it.sevenbits.stream.InStream;
import it.sevenbits.stream.OutStream;
import org.apache.log4j.Logger;

/**
 * Class used to format java code (very primitive implementation).
 * User: kirill
 * Date: 09.10.13
 * Time: 14:24
 */
public class CodeFormatter {

    static Logger logger = Logger.getLogger(Main.class);
    /**
     * Method formats the code.
     * @param inStream Provides input stream containing unformatted code.
     * @param outStream Provides stream to output formatted code.
     * @param indentation Provides indentation of strings.
     * @throws it.sevenbits.exceptions.FormatterException When something goes wrong
     * @return Whether formatting operation was successful or not.
     */
    public boolean format(InStream inStream, OutStream outStream, String indentation) throws FormatterException {

        char currentChar = 0;
        char lastChar = 0;
        int braceCount = 0;

        boolean startOfLine = true;

        try {
            while (!inStream.isEnd()) {
                currentChar = inStream.readSymbol();
                if (lastChar == '{' || lastChar == '}' || lastChar == ';') {
                    if (currentChar != '\n') {
                        outStream.writeSymbol('\n');
                        startOfLine = true;
                    }
                }
                if (startOfLine) {
                    if (currentChar != '}') {
                        writeString(multiplyString(indentation, braceCount), outStream);
                    } else {
                        writeString(multiplyString(indentation, braceCount - 1), outStream);
                    }
                    startOfLine = false;
                }
                if (currentChar == '{') {
                    braceCount++;
                }
                if (currentChar == '}') {
                    braceCount--;
                }
                if (currentChar == '+' || currentChar == '-' || currentChar == '/' || currentChar == '*') {
                    if (currentChar == '*') {
                        if (lastChar != '.') {
                            outStream.writeSymbol(' ');
                        }
                    } else if (lastChar != ' ') {
                        outStream.writeSymbol(' ');
                    }
                }
                if (lastChar == '+' || lastChar == '-' || lastChar == '/' || lastChar == '*') {
                    if (lastChar == '*') {
                        if (currentChar != ';') {
                            outStream.writeSymbol(' ');
                        }
                    } else if (currentChar != ' ') {<commit_msg>fixed extra spaces before right brace.<commit_after>package it.sevenbits;

import it.sevenbits.exceptions.FormatterException;
import it.sevenbits.exceptions.StreamException;
import it.sevenbits.stream.InStream;
import it.sevenbits.stream.OutStream;
import org.apache.log4j.Logger;

/**
 * Class used to format java code (very primitive implementation).
 * User: kirill
 * Date: 09.10.13
 * Time: 14:24
 */
public class CodeFormatter {

    static Logger logger = Logger.getLogger(Main.class);
    /**
     * Method formats the code.
     * @param inStream Provides input stream containing unformatted code.
     * @param outStream Provides stream to output formatted code.
     * @param indentation Provides indentation of strings.
     * @throws it.sevenbits.exceptions.FormatterException When something goes wrong
     * @return Whether formatting operation was successful or not.
     */
    public boolean format(InStream inStream, OutStream outStream, String indentation) throws FormatterException {

        char currentChar = 0;
        char lastChar = 0;
        int braceCount = 0;

        boolean startOfLine = true;

        try {
            while (!inStream.isEnd()) {
                currentChar = inStream.readSymbol();
                if (lastChar == '{' || lastChar == '}' || lastChar == ';') {
                    if (currentChar != '\n') {
                        outStream.writeSymbol('\n');
                        startOfLine = true;
                    }
                }
                if (startOfLine && currentChar != ' ') {
                    if (currentChar != '}') {
                        writeString(multiplyString(indentation, braceCount), outStream);
                    } else {
                        writeString(multiplyString(indentation, braceCount - 1), outStream);
                    }
                    startOfLine = false;
                }
                if (currentChar == '{') {
                    braceCount++;
                }
                if (currentChar == '}') {
                    braceCount--;
                }
                if (currentChar == '+' || currentChar == '-' || currentChar == '/' || currentChar == '*') {
                    if (currentChar == '*') {
                        if (lastChar != '.') {
                            outStream.writeSymbol(' ');
                        }
                    } else if (lastChar != ' ') {
                        outStream.writeSymbol(' ');
                    }
                }
                if (lastChar == '+' || lastChar == '-' || lastChar == '/' || lastChar == '*') {
                    if (lastChar == '*') {
                        if (currentChar != ';') {
                            outStream.writeSymbol(' ');
                        }
                    } else if (currentChar != ' ') {
{'fraction_non_alphanumeric': 0.11713317881975396, 'fraction_numerical': 0.005348546978070958, 'mean_word_length': 1.4285714285714286, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '6262520', 'n_tokens_mistral': 1425, 'n_tokens_neox': 1318, 'n_words': 322}