<commit_before>package com.elmakers.mine.bukkit.configuration;

import static org.bukkit.util.NumberConversions.toLong;

import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.logging.Logger;
import javax.annotation.Nullable;

import org.apache.commons.lang.StringUtils;
import org.apache.commons.lang.Validate;
import org.bukkit.configuration.Configuration;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.configuration.MemorySection;
import org.bukkit.util.NumberConversions;

import com.elmakers.mine.bukkit.utility.ConfigUtils;
import com.elmakers.mine.bukkit.utility.platform.PlatformInterpreter;

public class TranslatingConfigurationSection extends MemorySection {
    private static Logger logger;
    private ConfigurationSection parameterMap;

    public static void setLogger(Logger log) {
        logger = log;
    }

    protected static void warn(String message) {
        if (logger != null) {
            logger.warning(message);
        }
    }

    protected TranslatingConfigurationSection() {
        super();
    }

    public TranslatingConfigurationSection(ConfigurationSection parent, String path) {
        super(parent, path);
    }

    public TranslatingConfigurationSection(ConfigurationSection copy) {
        super(copy.getParent(), copy.getName());
    }

    public static TranslatingConfigurationSection getWrapped(ConfigurationSection wrap) {
        TranslatingConfigurationSection newSection = new TranslatingConfigurationSection(wrap);
        newSection.wrap(wrap);
        return newSection;
    }

    public void wrap(ConfigurationSection wrap) {
        Map<String, Object> data = PlatformInterpreter.getPlatform().getCompatibilityUtils().getMap(wrap);
        if (data != null) {
            PlatformInterpreter.getPlatform().getCompatibilityUtils().setMap(this, data);
        }
    }

    public TranslatingConfigurationSection newSection(String key) {
        return createSection(this, key);
    }

    protected TranslatingConfigurationSection createSection(TranslatingConfigurationSection parent, String key) {
        return new TranslatingConfigurationSection(parent, key);
    }

    /**
     * Borrowed from Bukkit's MemorySection
     */
    @Override
    public ConfigurationSection createSection(String path) {
        Validate.notEmpty(path, "Cannot create section at empty path");
        Configuration root = getRoot();
        if (root == null) {
            throw new IllegalStateException("Cannot create section without a root");
        }

        final char separator = root.options().pathSeparator();
        // i1 is the leading (higher) index
        // i2 is the trailing (lower) index
        int i1 = -1;
        int i2;
        ConfigurationSection section = this;
        while ((i1 = path.indexOf(separator, i2 = i1 + 1)) != -1) {
            String node = path.substring(i2, i1);
            ConfigurationSection subSection = section.getConfigurationSection(node);
            if (subSection == null) {
                section = section.createSection(node);
            } else {
                section = subSection;
            }
        }

        String key = path.substring(i2);
        if (section == this) {
            ConfigurationSection result = createSection(this, key);
            map.put(key, result);
            return result;
        }
        return section.createSection(key);
    }

    @Override
    public Object get(String path, Object def) {
        if (parameterMap != null) {
            Object rawValue = super.get(path, def);
            if (rawValue != null && rawValue instanceof String) {
                String stringValue = (String)rawValue;
                if (stringValue.startsWith("$")) {
                    stringValue = stringValue.substring(1);
                    if (parameterMap.contains(stringValue)) {
                        return parameterMap.get(stringValue);
                    }<commit_msg>Don't manipulate the config map directly since we no longer can presume to know what it contains<commit_after>package com.elmakers.mine.bukkit.configuration;

import static org.bukkit.util.NumberConversions.toLong;

import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.logging.Logger;
import javax.annotation.Nullable;

import org.apache.commons.lang.StringUtils;
import org.apache.commons.lang.Validate;
import org.bukkit.configuration.Configuration;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.configuration.MemorySection;
import org.bukkit.util.NumberConversions;

import com.elmakers.mine.bukkit.utility.ConfigUtils;
import com.elmakers.mine.bukkit.utility.platform.PlatformInterpreter;

public class TranslatingConfigurationSection extends MemorySection {
    private static Logger logger;
    private ConfigurationSection parameterMap;

    public static void setLogger(Logger log) {
        logger = log;
    }

    protected static void warn(String message) {
        if (logger != null) {
            logger.warning(message);
        }
    }

    protected TranslatingConfigurationSection() {
        super();
    }

    public TranslatingConfigurationSection(ConfigurationSection parent, String path) {
        super(parent, path);
    }

    public TranslatingConfigurationSection(ConfigurationSection copy) {
        super(copy.getParent(), copy.getName());
    }

    public static TranslatingConfigurationSection getWrapped(ConfigurationSection wrap) {
        TranslatingConfigurationSection newSection = new TranslatingConfigurationSection(wrap);
        newSection.wrap(wrap);
        return newSection;
    }

    public void wrap(ConfigurationSection wrap) {
        Map<String, Object> data = PlatformInterpreter.getPlatform().getCompatibilityUtils().getMap(wrap);
        if (data != null) {
            PlatformInterpreter.getPlatform().getCompatibilityUtils().setMap(this, data);
        }
    }

    public TranslatingConfigurationSection newSection(String key) {
        return createSection(this, key);
    }

    protected TranslatingConfigurationSection createSection(TranslatingConfigurationSection parent, String key) {
        return new TranslatingConfigurationSection(parent, key);
    }

    /**
     * Borrowed from Bukkit's MemorySection
     */
    @Override
    public ConfigurationSection createSection(String path) {
        Validate.notEmpty(path, "Cannot create section at empty path");
        Configuration root = getRoot();
        if (root == null) {
            throw new IllegalStateException("Cannot create section without a root");
        }

        final char separator = root.options().pathSeparator();
        // i1 is the leading (higher) index
        // i2 is the trailing (lower) index
        int i1 = -1;
        int i2;
        ConfigurationSection section = this;
        while ((i1 = path.indexOf(separator, i2 = i1 + 1)) != -1) {
            String node = path.substring(i2, i1);
            ConfigurationSection subSection = section.getConfigurationSection(node);
            if (subSection == null) {
                section = section.createSection(node);
            } else {
                section = subSection;
            }
        }

        String key = path.substring(i2);
        if (section == this) {
            ConfigurationSection result = createSection(this, key);
            super.set(key, result);
            return result;
        }
        return section.createSection(key);
    }

    @Override
    public Object get(String path, Object def) {
        if (parameterMap != null) {
            Object rawValue = super.get(path, def);
            if (rawValue != null && rawValue instanceof String) {
                String stringValue = (String)rawValue;
                if (stringValue.startsWith("$")) {
                    stringValue = stringValue.substring(1);
                    if (parameterMap.contains(stringValue)) {
                        return parameterMap.get(stringValue);
                    }
{'fraction_non_alphanumeric': 0.09025270758122744, 'fraction_numerical': 0.0034856218100336113, 'mean_word_length': 2.693793103448276, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '1122545', 'n_tokens_mistral': 2045, 'n_tokens_neox': 1968, 'n_words': 496}