<commit_before>/*
 * Copyright 2016 MovingBlocks
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.terasology.config.flexible;

import com.google.common.collect.Maps;
import org.terasology.engine.SimpleUri;

import java.util.Map;

public class FlexibleConfig {
    private Map<SimpleUri, Setting> settingMap;

    public FlexibleConfig() {
        this.settingMap = Maps.newHashMap();
    }

    public <V> boolean add(Setting<V> setting) {
        SimpleUri key = setting.getId();

        if (key == null || has(key))
            return false;

        settingMap.put(key, setting);
        return true;
    }

    public boolean remove(SimpleUri id) {
        Setting setting = get(id);

        if (setting == null || setting.hasSubscribers())
            return false;

        settingMap.remove(id);
        return true;
    }

    @SuppressWarnings("unchecked")
    public <V> Setting<V> get(SimpleUri key) {
        return (Setting<V>) settingMap.get(key);
    }

    public boolean has(SimpleUri key) {
        return settingMap.containsKey(key);<commit_msg>Log warnings when Setting can't be removed<commit_after>/*
 * Copyright 2016 MovingBlocks
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.terasology.config.flexible;

import com.google.common.collect.Maps;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.terasology.engine.SimpleUri;

import java.util.Map;

public class FlexibleConfig {
    private static final Logger LOGGER = LoggerFactory.getLogger(FlexibleConfig.class);

    private Map<SimpleUri, Setting> settingMap;

    public FlexibleConfig() {
        this.settingMap = Maps.newHashMap();
    }

    public <V> boolean add(Setting<V> setting) {
        SimpleUri key = setting.getId();

        if (key == null || has(key))
            return false;

        settingMap.put(key, setting);
        return true;
    }

    public boolean remove(SimpleUri id) {
        Setting setting = get(id);

        if (setting == null) {
            LOGGER.warn("The setting to remove with the id \"{}\" does not exist in the config.", id);
            return false;
        }
        else if (setting.hasSubscribers()) {
            LOGGER.warn("The setting with the id \"{}\" still has subscribers and cannot be removed.", id);
            return false;
        }

        settingMap.remove(id);
        return true;
    }

    @SuppressWarnings("unchecked")
    public <V> Setting<V> get(SimpleUri key) {
        return (Setting<V>) settingMap.get(key);
    }

    public boolean has(SimpleUri key) {
        return settingMap.containsKey(key);
{'fraction_non_alphanumeric': 0.09738651994497936, 'fraction_numerical': 0.0049518569463548835, 'mean_word_length': 2.8887700534759357, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '4628491', 'n_tokens_mistral': 1016, 'n_tokens_neox': 983, 'n_words': 347}