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

io.elsci.mocks.util.PropertyReader Maven / Gradle / Ivy

There is a newer version: 20231025.1145-36
Show newest version
package io.elsci.mocks.util;

/**
 * Utility class that helps read both System and ENV properties. At the first it looks into System properties and if
 * property was not found it goes to the ENV properties. In case if property has been defined nowhere, it falls back
 * to the default value, passed by user.
 */
public class PropertyReader {

    private final String value;

    private PropertyReader(String value) {
        this.value = value;
    }

    public int intValueOr(int defaultValue) {
        return value != null ? Integer.parseInt(value) : defaultValue;
    }

    public String stringValueOr(String defaultValue) {
        return value != null ? value : defaultValue;
    }

    public static PropertyReader readProperty(String propertyName) {
        String systemProperty = System.getProperty(propertyName);
        if (systemProperty != null) {
            return new PropertyReader(systemProperty);
        }
        String envProperty = System.getenv(propertyName);
        if (envProperty != null) {
            return new PropertyReader(envProperty);
        }
        return new PropertyReader(null);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy