<commit_before>/*
 * Copyright (c) 2013-2016 Cinchapi Inc.
 * 
 * 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 com.cinchapi.concourse.server.plugin;

import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Map;

import javax.annotation.Nullable;

import org.apache.commons.configuration.ConfigurationException;

import ch.qos.logback.classic.Level;

import com.cinchapi.concourse.config.PreferencesHandler;
import com.cinchapi.concourse.util.Logging;
import com.google.common.base.CaseFormat;
import com.google.common.base.Function;
import com.google.common.base.Throwables;
import com.google.common.collect.Maps;

/**
 * A collection of preferences that are used to configure a plugin's JVM and
 * possible internal operations.
 * <p>
 * Defaults can be {@link #addDefault(String, Object) declared} programmatically
 * by the plugin and can be overridden by the user by specifying a prefs file in
 * the plugin's home directory.
 * </p>
 * 
 * @author <NAME>
 */
public abstract class PluginConfiguration {

    static {
        // Prevent logging from showing up in the console
        Logging.disable(PluginConfiguration.class);
    }

    /**
     * The default value for the {@link SystemPreference#HEAP_SIZE} preference
     * (in bytes).
     */
    private static final long DEFAULT_HEAP_SIZE_IN_BYTES = 268435456;

    /**
     * The name of the prefs file in the plugin's home directory.
     */
    protected static final String PLUGIN_PREFS_FILENAME = "plugin.prefs";

    /**
     * The absolute path to the prefs file in the plugin's home directory.
     */
    private static final Path PLUGIN_PREFS_LOCATION = Paths.get(
            System.getProperty(Plugin.PLUGIN_HOME_JVM_PROPERTY), "conf",
            PLUGIN_PREFS_FILENAME).toAbsolutePath();

    /**
     * The name of the dev prefs file in the plugin's home directory.
     */
    protected static final String PLUGIN_PREFS_DEV_FILENAME = "plugin.prefs.dev";

    /**
     * The absolute path to the dev prefs file in the plugin's home directory.
     */
    private static final Path PLUGIN_PREFS_DEV_LOCATION = Paths.get(
            System.getProperty(Plugin.PLUGIN_HOME_JVM_PROPERTY),
            PLUGIN_PREFS_DEV_FILENAME).toAbsolutePath();

    /**
     * The absolute {@link Path} to plugin pref file in the plugin's home dir
     * */
    protected static Path PLUGIN_PREFS;

    /**
     * Default configuration values that are defined within the plugin. These
     * defaults are used if they are not overridden in the prefs file.
     */
    private final Map<String, Object> defaults = Maps.newHashMap();

    /**
     * A handler to the underlying prefs file, if it exists within the plugin's
     * home directory.
     */
    @Nullable
    private final PreferencesHandler prefs;

    /**
     * Set location of the plugin preferences files depending on the existence
     * of the preferences files
     * */
    {
        PLUGIN_PREFS = Files.exists(PLUGIN_PREFS_DEV_LOCATION) ?
                PLUGIN_PREFS_DEV_LOCATION :
                PLUGIN_PREFS_LOCATION;
    }
    /**
     * Construct a new instance.
     */
    public PluginConfiguration() {
        this(PLUGIN_PREFS);
    }

    /**
     * DO NOT CALL
     * <p>
     * Provided for the plugin manager to create a local handler for every
     * plugin's preferences.
     * </p>
     * 
     * @param location
     */
    protected PluginConfiguration(Path location) {
        if(Files.exists(location)) {
            try {
                this.prefs = new PreferencesHandler(location.toString()) {};
            }
            catch (ConfigurationException e) {
                throw Throwables.propagate(e);
            }
        }<commit_msg>refactor changes made for CON-511<commit_after>/*
 * Copyright (c) 2013-2016 Cinchapi Inc.
 * 
 * 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 com.cinchapi.concourse.server.plugin;

import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Map;

import javax.annotation.Nullable;

import org.apache.commons.configuration.ConfigurationException;

import ch.qos.logback.classic.Level;

import com.cinchapi.concourse.config.PreferencesHandler;
import com.cinchapi.concourse.util.Logging;
import com.google.common.base.CaseFormat;
import com.google.common.base.Function;
import com.google.common.base.Throwables;
import com.google.common.collect.Maps;

/**
 * A collection of preferences that are used to configure a plugin's JVM and
 * possible internal operations.
 * <p>
 * Defaults can be {@link #addDefault(String, Object) declared} programmatically
 * by the plugin and can be overridden by the user by specifying a prefs file in
 * the plugin's home directory.
 * </p>
 * 
 * @author <NAME>
 */
public abstract class PluginConfiguration {

    /**
     * The default value for the {@link SystemPreference#HEAP_SIZE} preference
     * (in bytes).
     */
    private static final long DEFAULT_HEAP_SIZE_IN_BYTES = 268435456;

    /**
     * The name of the prefs file in the plugin's home directory.
     */
    protected static final String PLUGIN_PREFS_FILENAME = "plugin.prefs";

    /**
     * The absolute path to the prefs file in the plugin's home directory.
     */
    private static final Path PLUGIN_PREFS_LOCATION = Paths.get(
            System.getProperty(Plugin.PLUGIN_HOME_JVM_PROPERTY), "conf",
            PLUGIN_PREFS_FILENAME).toAbsolutePath();

    /**
     * The name of the dev prefs file in the plugin's home directory.
     */
    protected static final String PLUGIN_PREFS_DEV_FILENAME = "plugin.prefs.dev";

    /**
     * The absolute path to the dev prefs file in the plugin's home directory.
     */
    private static final Path PLUGIN_PREFS_DEV_LOCATION = Paths.get(
            System.getProperty(Plugin.PLUGIN_HOME_JVM_PROPERTY),
            PLUGIN_PREFS_DEV_FILENAME).toAbsolutePath();

    /**
     * The absolute {@link Path} to plugin pref file in the plugin's home dir
     */
    protected static Path PLUGIN_PREFS;

    /**
     * Default configuration values that are defined within the plugin. These
     * defaults are used if they are not overridden in the prefs file.
     */
    private final Map<String, Object> defaults = Maps.newHashMap();

    /**
     * A handler to the underlying prefs file, if it exists within the plugin's
     * home directory.
     */
    @Nullable
    private final PreferencesHandler prefs;

    static {
        // Prevent logging from showing up in the console
        Logging.disable(PluginConfiguration.class);

        // Set location of the plugin preferences files depending on the
        // existence of the preferences files
        PLUGIN_PREFS = Files.exists(PLUGIN_PREFS_DEV_LOCATION) ? PLUGIN_PREFS_DEV_LOCATION
                : PLUGIN_PREFS_LOCATION;
    }

    /**
     * Construct a new instance.
     */
    public PluginConfiguration() {
        this(PLUGIN_PREFS);
    }

    /**
     * DO NOT CALL
     * <p>
     * Provided for the plugin manager to create a local handler for every
     * plugin's preferences.
     * </p>
     * 
     * @param location
     */
    protected PluginConfiguration(Path location) {
        if(Files.exists(location)) {
            try {
                this.prefs = new PreferencesHandler(location.toString()) {};
            }
            catch (ConfigurationException e) {
                throw Throwables.propagate(e);
            }
        }
{'fraction_non_alphanumeric': 0.08499117127722189, 'fraction_numerical': 0.00529723366686286, 'mean_word_length': 2.789473684210526, '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': '6351282', 'n_tokens_mistral': 2448, 'n_tokens_neox': 2340, 'n_words': 788}