<commit_before>/*
 * ExtendedProperties.java (Class: com.madphysicist.tools.util.ExtendedProperties)
 *
 * Mad Physicist JTools Project (General Purpose Utilities)
 *
 * The MIT License (MIT)
 *
 * Copyright (c) 2013 by <NAME>
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 * THE SOFTWARE.
 */
package com.madphysicist.tools.util;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.Serializable;
import java.util.Map;
import java.util.MissingResourceException;
import java.util.Properties;
import java.util.ResourceBundle;
import javax.swing.KeyStroke;

/**
 * Provides extended functionality to the {@link java.util.Properties
 * Properties} class, including convenience loaders and methods to retreive
 * values as primitive, array, and other types. Note that the search in default
 * properties will be done regardless of whether the default property set is
 * {@code ExtendedProperties} or not.
 *
 * @author <NAME>
 * @version 1.0.0, 2 Nov 2012 - <NAME> - Created
 * @version 1.0.1, 10 Dec 2013 - <NAME> - Added {@code
 * loadFromFile(File)} method, {@code load*NoEx()} methods, special getters.
 * @since 1.0
 */
public class ExtendedProperties extends Properties
{
    /**
     * The version ID for serialization.
     *
     * @serial Increment the least significant three digits when compatibility
     * is not compromised by a structural change (e.g. adding a new field with
     * a sensible default value), and the upper digits when the change makes
     * serialized versions of of the class incompatible with previous releases.
     * @since 1.0.0
     */
    private static final long serialVersionUID = 1000L;

    /**
     * Initializes a property set with no parent properties. If a property is
     * not found in this set, no other set will be searched.
     * @since 1.0.0
     */
    public ExtendedProperties()
    {
        super();
    }

    /**
     * Initializes a property set with the specified parent properties. If a
     * property is not found in this set, the parent property sets will be
     * searched recursively.
     *
     * @param defaults the default values to use if a property is not found in
     * this property set.
     * @since 1.0.0
     */
    public ExtendedProperties(Properties defaults)
    {
        super(defaults);
    }

    /**
     * Loads properties from a property resource. The rules for searching for
     * resources and loading property files can be found in the documentation
     * of {@link ClassLoader#getSystemResourceAsStream(java.lang.String)} and
     * {@link Properties#load(java.io.InputStream)}, respectively.
     *
     * @param baseName the name of the resource to load.
     * @throws IOException if the resource can not be found or loaded for any
     * reason.
     * @since 1.0.0
     */
    public void loadFromResource(String baseName) throws IOException
    {
        try(InputStream input = ClassLoader.getSystemResourceAsStream(baseName)) {
            load(input);
        }
    }

    /**
     * Loads properties from a property resource, ignoring any exceptions that
     * may occur. The rules for searching for resources and loading property
     * files can be found in the documentation of {@link
     * ClassLoader#getSystemResourceAsStream(java.lang.String)} and {@link
     * Properties#load(java.io.InputStream)}, respectively.
     *
     * @param baseName the name of the resource to load. If the resource could
     * be found or loaded, this instance will remain unchanged.
     * @since 1.0.1
     */
    public void loadFromResourceNoEx(String baseName)
    {
        try(InputStream input = ClassLoader.getSystemResourceAsStream(baseName)) {
            load(input);
        } catch(IOException | IllegalArgumentException ex) {}
    }

    /**
     * Loads a property file into this property set.
     *
     * @param fileName the name of the file to load.
     * @throws IOException if an error occurrs while searching for, opening or
     * reading the file.
     * @since 1.0.0
     */
    public void loadFromFile(String fileName) throws IOException
    {
        try(InputStream input = new FileInputStream(fileName)) {
            load(input);
        }
    }

    /**
     * Loads a property file into this property set, ignoring any exceptions
     * that may occur.
     *
     * @param fileName the name of the file to load. If an error occurrs while
     * searching for, opening or reading the file, this instance remains
     * unchanged.
     * @since 1.0.1
     */
    public void loadFromFileNoEx(String fileName) throws IOException
    {
        try(InputStream input = new FileInputStream(fileName)) {
            load(input);
        } catch(IOException | IllegalArgumentException ex) {}
    }

    /**
     * Loads a property file into this property set.
     *
     * @param file the file to load.
     * @throws IOException if an error occurrs while searching for, opening or
     * reading the file.
     * @since 1.0.1
     */
    public void loadFromFile(File file) throws IOException
    {
        try(InputStream input = new FileInputStream(file)) {
            load(input);
        }
    }

    /**
     * Loads a property file into this property set, ignoring any exceptions
     * that may occur.
     *
     * @param file the file to load. If an error occurrs while searching for,<commit_msg>Fixed exception bug<commit_after>/*
 * ExtendedProperties.java (Class: com.madphysicist.tools.util.ExtendedProperties)
 *
 * Mad Physicist JTools Project (General Purpose Utilities)
 *
 * The MIT License (MIT)
 *
 * Copyright (c) 2013 by <NAME>
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 * THE SOFTWARE.
 */
package com.madphysicist.tools.util;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.Serializable;
import java.util.Map;
import java.util.MissingResourceException;
import java.util.Properties;
import java.util.ResourceBundle;
import javax.swing.KeyStroke;

/**
 * Provides extended functionality to the {@link java.util.Properties
 * Properties} class, including convenience loaders and methods to retreive
 * values as primitive, array, and other types. Note that the search in default
 * properties will be done regardless of whether the default property set is
 * {@code ExtendedProperties} or not.
 *
 * @author <NAME>
 * @version 1.0.0, 2 Nov 2012 - <NAME> - Created
 * @version 1.0.1, 10 Dec 2013 - <NAME> - Added `loadFromFile(File)` method, `load*NoEx()` methods, special getters.
 * @version 1.0.2, 09 Dec 2014 - <NAME> - Removed exceptions erroneously thrown by `load*NoEx()` methods.
 * @since 1.0
 */
public class ExtendedProperties extends Properties
{
    /**
     * The version ID for serialization.
     *
     * @serial Increment the least significant three digits when compatibility
     * is not compromised by a structural change (e.g. adding a new field with
     * a sensible default value), and the upper digits when the change makes
     * serialized versions of of the class incompatible with previous releases.
     * @since 1.0.0
     */
    private static final long serialVersionUID = 1000L;

    /**
     * Initializes a property set with no parent properties. If a property is
     * not found in this set, no other set will be searched.
     * @since 1.0.0
     */
    public ExtendedProperties()
    {
        super();
    }

    /**
     * Initializes a property set with the specified parent properties. If a
     * property is not found in this set, the parent property sets will be
     * searched recursively.
     *
     * @param defaults the default values to use if a property is not found in
     * this property set.
     * @since 1.0.0
     */
    public ExtendedProperties(Properties defaults)
    {
        super(defaults);
    }

    /**
     * Loads properties from a property resource. The rules for searching for
     * resources and loading property files can be found in the documentation
     * of {@link ClassLoader#getSystemResourceAsStream(java.lang.String)} and
     * {@link Properties#load(java.io.InputStream)}, respectively.
     *
     * @param baseName the name of the resource to load.
     * @throws IOException if the resource can not be found or loaded for any
     * reason.
     * @since 1.0.0
     */
    public void loadFromResource(String baseName) throws IOException
    {
        try(InputStream input = ClassLoader.getSystemResourceAsStream(baseName)) {
            load(input);
        }
    }

    /**
     * Loads properties from a property resource, ignoring any exceptions that
     * may occur. The rules for searching for resources and loading property
     * files can be found in the documentation of {@link
     * ClassLoader#getSystemResourceAsStream(java.lang.String)} and {@link
     * Properties#load(java.io.InputStream)}, respectively.
     *
     * @param baseName the name of the resource to load. If the resource could
     * be found or loaded, this instance will remain unchanged.
     * @since 1.0.1
     */
    public void loadFromResourceNoEx(String baseName)
    {
        try(InputStream input = ClassLoader.getSystemResourceAsStream(baseName)) {
            load(input);
        } catch(IOException | IllegalArgumentException ex) {}
    }

    /**
     * Loads a property file into this property set.
     *
     * @param fileName the name of the file to load.
     * @throws IOException if an error occurrs while searching for, opening or
     * reading the file.
     * @since 1.0.0
     */
    public void loadFromFile(String fileName) throws IOException
    {
        try(InputStream input = new FileInputStream(fileName)) {
            load(input);
        }
    }

    /**
     * Loads a property file into this property set, ignoring any exceptions
     * that may occur.
     *
     * @param fileName the name of the file to load. If an error occurrs while
     * searching for, opening or reading the file, this instance remains
     * unchanged.
     * @since 1.0.1
     */
    public void loadFromFileNoEx(String fileName)
    {
        try(InputStream input = new FileInputStream(fileName)) {
            load(input);
        } catch(IOException | IllegalArgumentException ex) {}
    }

    /**
     * Loads a property file into this property set.
     *
     * @param file the file to load.
     * @throws IOException if an error occurrs while searching for, opening or
     * reading the file.
     * @since 1.0.1
     */
    public void loadFromFile(File file) throws IOException
    {
        try(InputStream input = new FileInputStream(file)) {
            load(input);
        }
    }

    /**
     * Loads a property file into this property set, ignoring any exceptions
     * that may occur.
     *
     * @param file the file to load. If an error occurrs while searching for,
{'fraction_non_alphanumeric': 0.07678018575851393, 'fraction_numerical': 0.008591331269349845, 'mean_word_length': 2.9024463908184837, 'pattern_counts': {'":': 0, '<': 12, '<?xml version=': 0, '>': 12, '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': '2399784', 'n_tokens_mistral': 3421, 'n_tokens_neox': 3286, 'n_words': 1440}