All Downloads are FREE. Search and download functionalities are using the official Maven repository.

net.scattersphere.util.PropertyUtil Maven / Gradle / Ivy

The newest version!
package net.scattersphere.util;

import java.util.Properties;

/**
 * Created by kenji on 2/22/15.
 */
public class PropertyUtil {

    /**
     * This function retrieves a property by key from the system properties first (system properties are passed in through
     * the command line), then checks the specified {@link Properties} object.
     *
     * @param key The key to look for.
     * @param props {@link Properties} haystack if not found in {@code System.getProperty}.
     * @param defaultValue {@code String} containing a default value, if not found in either source.
     * @return {@code String} if found in either {@code System.getProperty} or supplied {@link Properties}, {@code null} otherwise.
     */
    public static String get(String key, Properties props, String defaultValue) {
        if (System.getProperty(key) != null) {
            return System.getProperty(key);
        }

        return props.getProperty(key) == null ? defaultValue : props.getProperty(key);
    }

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy