<commit_before>package myessentials.json;

import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import myessentials.MyEssentialsCore;
import org.apache.commons.lang3.exception.ExceptionUtils;

import java.io.*;
import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.List;

/**
 * An abstract class for all JSON configs.
 */
public abstract class JsonConfig<T, L extends List<T>> {

    /**
     * The path to the file used.
     */
    protected final String path, name;
    protected Gson gson;
    protected Type gsonType;


    public JsonConfig(String path, String name) {
        this.path = path;
        this.name = name;
        gson = new GsonBuilder().setPrettyPrinting().create();
    }

    protected abstract L newList();

    public void init() {
        init(newList());
    }

    /**
     * Initializes everything.
     */
    public void init(L items) {
        File file = new File(path);

        File parent = file.getParentFile();
        if (!parent.exists() && !parent.mkdirs()) {
            throw new IllegalStateException("Couldn't create dir: " + parent);
        }
        if (!file.exists() || file.isDirectory())
            create(items);
        else {
            read();
        }
    }

    /**
     * Creates the file if it doesn't exist with the initial given items
     */
    public void create(L initialItems) {
        try {
            Writer writer = new FileWriter(path);
            gson.toJson(initialItems, gsonType, writer);
            writer.close();
            MyEssentialsCore.instance.LOG.info("Created new " + name + " file successfully!");
        } catch (IOException ex) {
            MyEssentialsCore.instance.LOG.error(ExceptionUtils.getStackTrace(ex));
            MyEssentialsCore.instance.LOG.error("Failed to create " + name + " file!");
        }
    }

    /**
     * Writes the given list to the file, completely overwriting it
     */
    public void write(L items) {
        try {
            Writer writer = new FileWriter(path);
            gson.toJson(items, gsonType, writer);<commit_msg>Read after creation of JsonConfig files.<commit_after>package myessentials.json;

import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import myessentials.MyEssentialsCore;
import org.apache.commons.lang3.exception.ExceptionUtils;

import java.io.*;
import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.List;

/**
 * An abstract class for all JSON configs.
 */
public abstract class JsonConfig<T, L extends List<T>> {

    /**
     * The path to the file used.
     */
    protected final String path, name;
    protected Gson gson;
    protected Type gsonType;


    public JsonConfig(String path, String name) {
        this.path = path;
        this.name = name;
        gson = new GsonBuilder().setPrettyPrinting().create();
    }

    protected abstract L newList();

    public void init() {
        init(newList());
    }

    /**
     * Initializes everything.
     */
    public void init(L items) {
        File file = new File(path);

        File parent = file.getParentFile();
        if (!parent.exists() && !parent.mkdirs()) {
            throw new IllegalStateException("Couldn't create dir: " + parent);
        }
        if (!file.exists() || file.isDirectory()) {
            create(items);
        }
        read();
    }

    /**
     * Creates the file if it doesn't exist with the initial given items
     */
    public void create(L initialItems) {
        try {
            Writer writer = new FileWriter(path);
            gson.toJson(initialItems, gsonType, writer);
            writer.close();
            MyEssentialsCore.instance.LOG.info("Created new " + name + " file successfully!");
        } catch (IOException ex) {
            MyEssentialsCore.instance.LOG.error(ExceptionUtils.getStackTrace(ex));
            MyEssentialsCore.instance.LOG.error("Failed to create " + name + " file!");
        }
    }

    /**
     * Writes the given list to the file, completely overwriting it
     */
    public void write(L items) {
        try {
            Writer writer = new FileWriter(path);
            gson.toJson(items, gsonType, writer);
{'fraction_non_alphanumeric': 0.11452380952380953, 'fraction_numerical': 0.0004761904761904762, 'mean_word_length': 2.292319749216301, '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': '6015353', 'n_tokens_mistral': 1196, 'n_tokens_neox': 1161, 'n_words': 319}