<commit_before>package stream.flarebot.flarebot.util;

import com.google.gson.Gson;
import com.google.gson.JsonParser;
import org.json.JSONObject;
import org.json.JSONTokener;
import stream.flarebot.flarebot.FlareBot;

import java.io.IOException;
import java.io.InputStreamReader;
import java.io.Reader;
import java.net.URL;
import java.util.Arrays;
import java.util.stream.Collectors;

public class LocalConfig {

    private final Gson gson = FlareBot.GSON;
    private final JsonParser parser = new JsonParser();

    private JSONObject object;

    public LocalConfig(URL url) {

        if (url == null)
            throw new IllegalArgumentException("URL cannot be null!");

        try (Reader r = new InputStreamReader(url.openStream())) {
            JSONTokener tokener = new JSONTokener(r);
            this.object = new JSONObject(tokener);
        } catch (IOException e) {
            FlareBot.LOGGER.error("There was an error reading the config file!", e);
        }
    }

    public String getString(JSONObject json, String path) {
        String[] subpaths = path.split("\\.");
        for (int i = 0; i < subpaths.length; i++) {
            String subpath = subpaths[i];
            if (json.get(subpath) == null) {
                return null;
            } else if (this.object.get(subpath) instanceof JSONObject) {
                return getString((JSONObject) this.object.get(subpath), Arrays.stream(subpaths).skip(i + 1).collect(Collectors.joining(".")));
            } else {
                return (String) this.object.get(subpath);
            }
        }
        return null;
    }

    public String getString(String path) {
        return getString(this.object, path);
    }

    public boolean exists(String s) {
        try {
            return getString(this.object, s) != null;
        } catch (IllegalArgumentException e) {
            return false;
        }
    }

    public JSONObject getJsonObject() {
        return object;
    }
}<commit_msg>Change to use original recursive features<commit_after>package stream.flarebot.flarebot.util;

import com.google.gson.Gson;
import com.google.gson.JsonParser;
import org.json.JSONObject;
import org.json.JSONTokener;
import stream.flarebot.flarebot.FlareBot;

import java.io.IOException;
import java.io.InputStreamReader;
import java.io.Reader;
import java.net.URL;
import java.util.Arrays;
import java.util.stream.Collectors;

public class LocalConfig {

    private final Gson gson = FlareBot.GSON;
    private final JsonParser parser = new JsonParser();

    private JSONObject object;

    public LocalConfig(URL url) {

        if (url == null)
            throw new IllegalArgumentException("URL cannot be null!");

        try (Reader r = new InputStreamReader(url.openStream())) {
            JSONTokener tokener = new JSONTokener(r);
            this.object = new JSONObject(tokener);
        } catch (IOException e) {
            FlareBot.LOGGER.error("There was an error reading the config file!", e);
        }
    }

    public String getString(JSONObject json, String path) {
        String[] subpaths = path.split("\\.");
        for (int i = 0; i < subpaths.length; i++) {
            String subpath = subpaths[i];
            if (json.get(subpath) == null) {
                return null;
            } else if (json.get(subpath) instanceof JSONObject) {
                return getString((JSONObject) this.object.get(subpath), Arrays.stream(subpaths).skip(i + 1).collect(Collectors.joining(".")));
            } else {
                return (String) json.get(subpath);
            }
        }
        return null;
    }

    public String getString(String path) {
        return getString(this.object, path);
    }

    public boolean exists(String s) {
        try {
            return getString(this.object, s) != null;
        } catch (IllegalArgumentException e) {
            return false;
        }
    }

    public JSONObject getJsonObject() {
        return object;
    }
}
{'fraction_non_alphanumeric': 0.1089904570567554, 'fraction_numerical': 0.0010045203415369162, 'mean_word_length': 2.3984641638225255, 'pattern_counts': {'":': 0, '<': 5, '<?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': '935553', 'n_tokens_mistral': 1155, 'n_tokens_neox': 1118, 'n_words': 293}