<commit_before>package stexfires.io.properties;

import stexfires.core.record.KeyValueRecord;
import stexfires.io.spec.AbstractRecordFileSpec;
import stexfires.util.LineSeparator;

import java.io.InputStream;
import java.io.OutputStream;
import java.nio.charset.Charset;
import java.nio.charset.CodingErrorAction;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Objects;

/**
 * @author <NAME>
 * @since 0.1
 */
public final class PropertiesFileSpec extends AbstractRecordFileSpec {

    public static final String DEFAULT_READ_NULL_VALUE_REPLACEMENT = "";
    public static final String DEFAULT_WRITE_NULL_VALUE_REPLACEMENT = "";
    public static final boolean DEFAULT_ESCAPE_UNICODE = false;
    public static final boolean DEFAULT_CATEGORY_AS_KEY_PREFIX = false;
    public static final String DEFAULT_KEY_PREFIX_DELIMITER = ".";
    public static final boolean DEFAULT_DATE_COMMENT = false;

    private final List<PropertiesFieldSpec> fieldSpecs;

    private final boolean escapeUnicode;
    private final boolean categoryAsKeyPrefix;
    private final String keyPrefixDelimiter;
    private final boolean dateComment;

    public PropertiesFileSpec(Charset charset, CodingErrorAction codingErrorAction,
                              String readNullValueReplacement, String writeNullValueReplacement,
                              boolean escapeUnicode, boolean categoryAsKeyPrefix, String keyPrefixDelimiter,
                              boolean dateComment, LineSeparator lineSeparator) {
        super(charset, codingErrorAction, lineSeparator);
        Objects.requireNonNull(writeNullValueReplacement);
        Objects.requireNonNull(keyPrefixDelimiter);
        this.escapeUnicode = escapeUnicode;
        this.categoryAsKeyPrefix = categoryAsKeyPrefix;
        this.keyPrefixDelimiter = keyPrefixDelimiter;
        this.dateComment = dateComment;

        fieldSpecs = new ArrayList<>(2);
        fieldSpecs.add(KeyValueRecord.KEY_INDEX,
                new PropertiesFieldSpec());
        fieldSpecs.add(KeyValueRecord.VALUE_INDEX,
                new PropertiesFieldSpec(readNullValueReplacement, writeNullValueReplacement));
    }

    public static PropertiesFileSpec read(Charset charset, CodingErrorAction codingErrorAction) {
        return new PropertiesFileSpec(charset, codingErrorAction,
                DEFAULT_READ_NULL_VALUE_REPLACEMENT, DEFAULT_WRITE_NULL_VALUE_REPLACEMENT,
                DEFAULT_ESCAPE_UNICODE, DEFAULT_CATEGORY_AS_KEY_PREFIX, DEFAULT_KEY_PREFIX_DELIMITER,
                DEFAULT_DATE_COMMENT, DEFAULT_LINE_SEPARATOR);
    }

    public static PropertiesFileSpec read(Charset charset, CodingErrorAction codingErrorAction,
                                          String nullValueReplacement) {
        return new PropertiesFileSpec(charset, codingErrorAction,
                nullValueReplacement, DEFAULT_WRITE_NULL_VALUE_REPLACEMENT,
                DEFAULT_ESCAPE_UNICODE, DEFAULT_CATEGORY_AS_KEY_PREFIX, DEFAULT_KEY_PREFIX_DELIMITER,
                DEFAULT_DATE_COMMENT, DEFAULT_LINE_SEPARATOR);
    }

    public static PropertiesFileSpec write(Charset charset, CodingErrorAction codingErrorAction,
                                           boolean escapeUnicode,
                                           LineSeparator lineSeparator) {
        return new PropertiesFileSpec(charset, codingErrorAction,
                DEFAULT_READ_NULL_VALUE_REPLACEMENT, DEFAULT_WRITE_NULL_VALUE_REPLACEMENT,
                escapeUnicode, DEFAULT_CATEGORY_AS_KEY_PREFIX, DEFAULT_KEY_PREFIX_DELIMITER,
                DEFAULT_DATE_COMMENT, lineSeparator);
    }

    public static PropertiesFileSpec write(Charset charset, CodingErrorAction codingErrorAction,
                                           String nullValueReplacement,
                                           boolean escapeUnicode, boolean categoryAsKeyPrefix, String keyPrefixDelimiter,
                                           boolean dateComment, LineSeparator lineSeparator) {
        return new PropertiesFileSpec(charset, codingErrorAction,
                DEFAULT_READ_NULL_VALUE_REPLACEMENT, nullValueReplacement,
                escapeUnicode, categoryAsKeyPrefix, keyPrefixDelimiter,
                dateComment, lineSeparator);
    }

    public PropertiesFile file(Path path) {
        return new PropertiesFile(path, this);
    }

    public PropertiesProducer producer(InputStream inputStream) {
        return new PropertiesProducer(newBufferedReader(inputStream), this);<commit_msg>Refactor PropertiesFileSpec<commit_after>package stexfires.io.properties;

import stexfires.core.record.KeyValueRecord;
import stexfires.io.spec.AbstractRecordFileSpec;
import stexfires.util.LineSeparator;

import java.io.InputStream;
import java.io.OutputStream;
import java.nio.charset.Charset;
import java.nio.charset.CodingErrorAction;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Objects;

/**
 * @author <NAME>
 * @since 0.1
 */
public final class PropertiesFileSpec extends AbstractRecordFileSpec {

    public static final String DEFAULT_READ_NULL_VALUE_REPLACEMENT = "";
    public static final String DEFAULT_WRITE_NULL_VALUE_REPLACEMENT = "";
    public static final boolean DEFAULT_ESCAPE_UNICODE = false;
    public static final boolean DEFAULT_CATEGORY_AS_KEY_PREFIX = false;
    public static final String DEFAULT_KEY_PREFIX_DELIMITER = ".";
    public static final boolean DEFAULT_DATE_COMMENT = false;

    // both
    private final List<PropertiesFieldSpec> fieldSpecs;

    // read
    private final boolean escapeUnicode;
    private final boolean categoryAsKeyPrefix;
    private final String keyPrefixDelimiter;
    private final boolean dateComment;

    public PropertiesFileSpec(Charset charset, CodingErrorAction codingErrorAction,
                              String readNullValueReplacement,
                              LineSeparator lineSeparator,
                              String writeNullValueReplacement,
                              boolean escapeUnicode, boolean categoryAsKeyPrefix,
                              String keyPrefixDelimiter, boolean dateComment) {
        super(charset, codingErrorAction, lineSeparator);
        Objects.requireNonNull(writeNullValueReplacement);
        Objects.requireNonNull(keyPrefixDelimiter);

        // both
        fieldSpecs = new ArrayList<>(2);
        fieldSpecs.add(KeyValueRecord.KEY_INDEX,
                new PropertiesFieldSpec());
        fieldSpecs.add(KeyValueRecord.VALUE_INDEX,
                new PropertiesFieldSpec(readNullValueReplacement, writeNullValueReplacement));

        // write
        this.escapeUnicode = escapeUnicode;
        this.categoryAsKeyPrefix = categoryAsKeyPrefix;
        this.keyPrefixDelimiter = keyPrefixDelimiter;
        this.dateComment = dateComment;
    }

    public static PropertiesFileSpec read(Charset charset, CodingErrorAction codingErrorAction) {
        return new PropertiesFileSpec(charset, codingErrorAction,
                DEFAULT_READ_NULL_VALUE_REPLACEMENT,
                DEFAULT_LINE_SEPARATOR,
                DEFAULT_WRITE_NULL_VALUE_REPLACEMENT,
                DEFAULT_ESCAPE_UNICODE, DEFAULT_CATEGORY_AS_KEY_PREFIX,
                DEFAULT_KEY_PREFIX_DELIMITER, DEFAULT_DATE_COMMENT);
    }

    public static PropertiesFileSpec read(Charset charset, CodingErrorAction codingErrorAction,
                                          String nullValueReplacement) {
        return new PropertiesFileSpec(charset, codingErrorAction,
                nullValueReplacement,
                DEFAULT_LINE_SEPARATOR,
                DEFAULT_WRITE_NULL_VALUE_REPLACEMENT,
                DEFAULT_ESCAPE_UNICODE, DEFAULT_CATEGORY_AS_KEY_PREFIX,
                DEFAULT_KEY_PREFIX_DELIMITER, DEFAULT_DATE_COMMENT);
    }

    public static PropertiesFileSpec write(Charset charset, CodingErrorAction codingErrorAction,
                                           LineSeparator lineSeparator,
                                           boolean escapeUnicode) {
        return new PropertiesFileSpec(charset, codingErrorAction,
                DEFAULT_READ_NULL_VALUE_REPLACEMENT,
                lineSeparator,
                DEFAULT_WRITE_NULL_VALUE_REPLACEMENT,
                escapeUnicode, DEFAULT_CATEGORY_AS_KEY_PREFIX,
                DEFAULT_KEY_PREFIX_DELIMITER, DEFAULT_DATE_COMMENT);
    }

    public static PropertiesFileSpec write(Charset charset, CodingErrorAction codingErrorAction,
                                           LineSeparator lineSeparator,
                                           String nullValueReplacement,
                                           boolean escapeUnicode, boolean categoryAsKeyPrefix,
                                           String keyPrefixDelimiter, boolean dateComment) {
        return new PropertiesFileSpec(charset, codingErrorAction,
                DEFAULT_READ_NULL_VALUE_REPLACEMENT,
                lineSeparator,
                nullValueReplacement,
                escapeUnicode, categoryAsKeyPrefix,
                keyPrefixDelimiter, dateComment);
    }

    public PropertiesFile file(Path path) {
        return new PropertiesFile(path, this);
    }

    public PropertiesProducer producer(InputStream inputStream) {
        return new PropertiesProducer(newBufferedReader(inputStream), this);
{'fraction_non_alphanumeric': 0.05063825298027218, 'fraction_numerical': 0.0006329781622534023, 'mean_word_length': 2.75594294770206, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 26, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3434553', 'n_tokens_mistral': 2323, 'n_tokens_neox': 2275, 'n_words': 478}