<commit_before>/*
 * FindBugs - Find bugs in Java programs
 * Copyright (C) 2004,2005 <NAME> <<EMAIL>>
 * Copyright (C) 2004,2005 University of Maryland
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

/*
 * UserPreferences.java
 *
 * Created on May 26, 2004, 11:55 PM
 */

package edu.umd.cs.findbugs.config;

import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.Collection;
import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Properties;
import java.util.Set;
import java.util.TreeMap;
import java.util.TreeSet;

import javax.annotation.WillClose;

import edu.umd.cs.findbugs.DetectorFactory;
import edu.umd.cs.findbugs.FindBugs;
import edu.umd.cs.findbugs.IFindBugsEngine;
import edu.umd.cs.findbugs.Plugin;
import edu.umd.cs.findbugs.SystemProperties;

/**
 * User Preferences outside of any one Project. This consists of a class to
 * manage the findbugs.prop file found in the user.home.
 *
 * @author <NAME>
 */
public class UserPreferences implements Cloneable {

    /**
     * Separator string for values composed from a string and boolean
     */
    private static final char BOOL_SEPARATOR = '|';

    public static final String EFFORT_MIN = "min";

    public static final String EFFORT_DEFAULT = "default";

    public static final String EFFORT_MAX = "max";

    /**
     * Key prefix for custom plugins, full key consists of a prefix + plugin index starting with 0
     */
    public static final String KEY_PLUGIN = "plugin";

    // Private constants

    private static final String PREF_FILE_NAME = ".Findbugs_prefs";

    private static final int MAX_RECENT_FILES = 9;

    private static final String DETECTOR_THRESHOLD_KEY = "detector_threshold";

    private static final String FILTER_SETTINGS_KEY = "filter_settings";

    private static final String FILTER_SETTINGS2_KEY = "filter_settings_neg";

    private static final String RUN_AT_FULL_BUILD = "run_at_full_build";

    private static final String EFFORT_KEY = "effort";

    /**
     * Key prefix for custom filters, full key consists of a prefix + filter index starting with 0
     */
    public static final String KEY_INCLUDE_FILTER = "includefilter";

    /**
     * Key prefix for custom filters, full key consists of a prefix + filter index starting with 0
     */
    public static final String KEY_EXCLUDE_FILTER = "excludefilter";

    /**
     * Key prefix for custom filters, full key consists of a prefix + filter index starting with 0
     */
    public static final String KEY_EXCLUDE_BUGS = "excludebugs";

    // Fields

    private LinkedList<String> recentProjectsList;

    private Map<String, Boolean> detectorEnablementMap;

    private ProjectFilterSettings filterSettings;

    private boolean runAtFullBuild;

    private String effort;

    private Map<String, Boolean> includeFilterFiles;

    private Map<String, Boolean> excludeFilterFiles;

    private Map<String, Boolean> excludeBugsFiles;

    private Map<String, Boolean> customPlugins;

    private UserPreferences() {
        filterSettings = ProjectFilterSettings.createDefault();
        recentProjectsList = new LinkedList<>();
        detectorEnablementMap = new HashMap<>();
        runAtFullBuild = true;
        effort = EFFORT_DEFAULT;
        includeFilterFiles = new TreeMap<>();
        excludeFilterFiles = new TreeMap<>();
        excludeBugsFiles = new TreeMap<>();
        customPlugins = new TreeMap<>();
    }

    /**
     * Create default UserPreferences.
     *
     * @return default UserPreferences
     */
    public static UserPreferences createDefaultUserPreferences() {
        return new UserPreferences();
    }

    /**
     * Read persistent global UserPreferences from file in the user's home
     * directory.
     */
    public void read() {
        File prefFile = new File(SystemProperties.getProperty("user.home"), PREF_FILE_NAME);
        if (!prefFile.exists() || !prefFile.isFile()) {
            return;
        }
        try {
            read(new FileInputStream(prefFile));
        } catch (IOException e) {
            // Ignore - just use default preferences
        }
    }

    /**
     * Read user preferences from given input stream. The InputStream is
     * guaranteed to be closed by this method.
     *
     * @param in
     *            the InputStream
     * @throws IOException
     */
    public void read(@WillClose InputStream in) throws IOException {
        Properties props = new Properties();
        try (BufferedInputStream prefStream = new BufferedInputStream(in)) {
            props.load(prefStream);
        }
        // Ignore
    
        if (props.size() == 0) {
            return;
        }

        Properties prefixlessProperties = new Properties();
        for (Map.Entry<?, ?> e : props.entrySet()) {
            if(e.getKey() instanceof String) {
                String key = e.getKey().toString();<commit_msg>Remove unnecessary comments<commit_after>/*
 * FindBugs - Find bugs in Java programs
 * Copyright (C) 2004,2005 <NAME> <<EMAIL>>
 * Copyright (C) 2004,2005 University of Maryland
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

/*
 * UserPreferences.java
 *
 * Created on May 26, 2004, 11:55 PM
 */

package edu.umd.cs.findbugs.config;

import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.Collection;
import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Properties;
import java.util.Set;
import java.util.TreeMap;
import java.util.TreeSet;

import javax.annotation.WillClose;

import edu.umd.cs.findbugs.DetectorFactory;
import edu.umd.cs.findbugs.FindBugs;
import edu.umd.cs.findbugs.IFindBugsEngine;
import edu.umd.cs.findbugs.Plugin;
import edu.umd.cs.findbugs.SystemProperties;

/**
 * User Preferences outside of any one Project. This consists of a class to
 * manage the findbugs.prop file found in the user.home.
 *
 * @author <NAME>
 */
public class UserPreferences implements Cloneable {

    /**
     * Separator string for values composed from a string and boolean
     */
    private static final char BOOL_SEPARATOR = '|';

    public static final String EFFORT_MIN = "min";

    public static final String EFFORT_DEFAULT = "default";

    public static final String EFFORT_MAX = "max";

    /**
     * Key prefix for custom plugins, full key consists of a prefix + plugin index starting with 0
     */
    public static final String KEY_PLUGIN = "plugin";

    // Private constants

    private static final String PREF_FILE_NAME = ".Findbugs_prefs";

    private static final int MAX_RECENT_FILES = 9;

    private static final String DETECTOR_THRESHOLD_KEY = "detector_threshold";

    private static final String FILTER_SETTINGS_KEY = "filter_settings";

    private static final String FILTER_SETTINGS2_KEY = "filter_settings_neg";

    private static final String RUN_AT_FULL_BUILD = "run_at_full_build";

    private static final String EFFORT_KEY = "effort";

    /**
     * Key prefix for custom filters, full key consists of a prefix + filter index starting with 0
     */
    public static final String KEY_INCLUDE_FILTER = "includefilter";

    /**
     * Key prefix for custom filters, full key consists of a prefix + filter index starting with 0
     */
    public static final String KEY_EXCLUDE_FILTER = "excludefilter";

    /**
     * Key prefix for custom filters, full key consists of a prefix + filter index starting with 0
     */
    public static final String KEY_EXCLUDE_BUGS = "excludebugs";

    // Fields

    private LinkedList<String> recentProjectsList;

    private Map<String, Boolean> detectorEnablementMap;

    private ProjectFilterSettings filterSettings;

    private boolean runAtFullBuild;

    private String effort;

    private Map<String, Boolean> includeFilterFiles;

    private Map<String, Boolean> excludeFilterFiles;

    private Map<String, Boolean> excludeBugsFiles;

    private Map<String, Boolean> customPlugins;

    private UserPreferences() {
        filterSettings = ProjectFilterSettings.createDefault();
        recentProjectsList = new LinkedList<>();
        detectorEnablementMap = new HashMap<>();
        runAtFullBuild = true;
        effort = EFFORT_DEFAULT;
        includeFilterFiles = new TreeMap<>();
        excludeFilterFiles = new TreeMap<>();
        excludeBugsFiles = new TreeMap<>();
        customPlugins = new TreeMap<>();
    }

    /**
     * Create default UserPreferences.
     *
     * @return default UserPreferences
     */
    public static UserPreferences createDefaultUserPreferences() {
        return new UserPreferences();
    }

    /**
     * Read persistent global UserPreferences from file in the user's home
     * directory.
     */
    public void read() {
        File prefFile = new File(SystemProperties.getProperty("user.home"), PREF_FILE_NAME);
        if (!prefFile.exists() || !prefFile.isFile()) {
            return;
        }
        try {
            read(new FileInputStream(prefFile));
        } catch (IOException e) {
            // Ignore - just use default preferences
        }
    }

    /**
     * Read user preferences from given input stream. The InputStream is
     * guaranteed to be closed by this method.
     *
     * @param in
     *            the InputStream
     * @throws IOException
     */
    public void read(@WillClose InputStream in) throws IOException {
        Properties props = new Properties();
        try (BufferedInputStream prefStream = new BufferedInputStream(in)) {
            props.load(prefStream);
        }
    
        if (props.size() == 0) {
            return;
        }

        Properties prefixlessProperties = new Properties();
        for (Map.Entry<?, ?> e : props.entrySet()) {
            if(e.getKey() instanceof String) {
                String key = e.getKey().toString();
{'fraction_non_alphanumeric': 0.08504847763225039, 'fraction_numerical': 0.008334750807960537, 'mean_word_length': 3.0702665282104533, 'pattern_counts': {'":': 0, '<': 37, '<?xml version=': 0, '>': 37, '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': '5045296', 'n_tokens_mistral': 3272, 'n_tokens_neox': 3119, 'n_words': 1104}