Package com.unboundid.util
Class PropertyManager
java.lang.Object
com.unboundid.util.PropertyManager
This class provides a mechanism for retrieving the values of specified
properties in the form of either Java system properties or process
environment variables (using an alternative name generated from the provided
property name using the
generateEnvironmentVariableNameFromPropertyName(java.lang.String) method). System
properties will be given a higher priority than environment variables, and
the value can be parsed in accordance with a number of syntaxes.-
Method Summary
Modifier and TypeMethodDescriptionstatic StringgenerateEnvironmentVariableNameFromPropertyName(String propertyName) Generates an alternative environment variable name that can be used for a given property name.static StringRetrieves the value of the specified system property or environment variable.static StringRetrieves the value of the specified system property or environment variable.static BooleangetBoolean(String propertyName) Retrieves the value of the specified property or environment variable as a Boolean value.static BooleangetBoolean(String propertyName, Boolean defaultValue) Retrieves the value of the specified property or environment variable as a Boolean value.static BooleangetBoolean(String propertyName, Boolean defaultValue, boolean throwOnInvalidValue) Retrieves the value of the specified property or environment variable as a Boolean value.getCommaDelimitedList(String propertyName) Retrieves the value of the specified property or environment variable as a list of comma-delimited values.getCommaDelimitedList(String propertyName, boolean trimItems) Retrieves the value of the specified property or environment variable as a list of comma-delimited values.static IntegerRetrieves the value of the specified property or environment variable as an integer.static IntegerRetrieves the value of the specified property or environment variable as an integer.static IntegerRetrieves the value of the specified property or environment variable as an integer.static LongRetrieves the value of the specified property or environment variable as a long.static LongRetrieves the value of the specified property or environment variable as a long.static LongRetrieves the value of the specified property or environment variable as a long.static PropertiesgetProperties(String... propertyNames) Retrieves aPropertiesobject with values for any of the specified properties that are currently set.
-
Method Details
-
get
Retrieves the value of the specified system property or environment variable.- Parameters:
propertyName- The name of the system property to retrieve, and to use to generate an alternative environment variable. It must not benullor empty.- Returns:
- The requested value, or
nullif it has not been set as either a system property or an environment variable.
-
get
Retrieves the value of the specified system property or environment variable.- Parameters:
propertyName- The name of the system property to retrieve, and to use to generate an alternative environment variable. It must not benullor empty.defaultValue- The default value to return if neither the system property nor associated environment variable have been set. It may benullif no default value should be returned.- Returns:
- The requested value, or
nullif it has not been set as either a system property or an environment variable.
-
getBoolean
Retrieves the value of the specified property or environment variable as a Boolean value.- Parameters:
propertyName- The name of the system property to retrieve, and to use to generate an alternative environment variable. It must not benullor empty.- Returns:
- The Boolean value of the specified property or environment
variable, or
nullif neither are set or are set to a value that cannot be parsed as a Boolean.
-
getBoolean
@Nullable public static Boolean getBoolean(@NotNull String propertyName, @Nullable Boolean defaultValue) Retrieves the value of the specified property or environment variable as a Boolean value.- Parameters:
propertyName- The name of the system property to retrieve, and to use to generate an alternative environment variable. It must not benullor empty.defaultValue- The default value to return if neither the system property nor associated environment variable have been set, or if the value cannot be parsed as a Boolean. It may benullif no default value should be returned.- Returns:
- The Boolean value of the specified property or environment variable, or the provided default value if neither are set or are set to a value that cannot be parsed as a Boolean.
-
getBoolean
@Nullable public static Boolean getBoolean(@NotNull String propertyName, @Nullable Boolean defaultValue, boolean throwOnInvalidValue) throws IllegalArgumentException Retrieves the value of the specified property or environment variable as a Boolean value.- Parameters:
propertyName- The name of the system property to retrieve, and to use to generate an alternative environment variable. It must not benullor empty.defaultValue- The default value to return if neither the system property nor associated environment variable have been set, or if the value cannot be parsed as a Boolean andthrowOnInvalidValueisfalse. It may benullif no default value should be returned.throwOnInvalidValue- Indicates whether this method should throw anIllegalArgumentExceptionif the system property or environment variable is set but its value cannot be parsed as a Boolean.- Returns:
- The Boolean value of the specified property or environment
variable, or the provided default value if neither are set or are
set to a value that cannot be parsed as a Boolean and
throwOnInvalidValueisfalse. - Throws:
IllegalArgumentException- If the property or environment variable is set, but its value cannot be parsed as a Boolean, andthrowOnInvalidValueistrue.
-
getInt
Retrieves the value of the specified property or environment variable as an integer.- Parameters:
propertyName- The name of the system property to retrieve, and to use to generate an alternative environment variable. It must not benullor empty.- Returns:
- The integer value of the specified property or environment
variable, or
nullif neither are set or are set to a value that cannot be parsed as an integer.
-
getInt
@Nullable public static Integer getInt(@NotNull String propertyName, @Nullable Integer defaultValue) Retrieves the value of the specified property or environment variable as an integer.- Parameters:
propertyName- The name of the system property to retrieve, and to use to generate an alternative environment variable. It must not benullor empty.defaultValue- The default value to return if neither the system property nor associated environment variable have been set, or if the value cannot be parsed as an integer. It may benullif no default value should be returned.- Returns:
- The integer value of the specified property or environment variable, or the provided default value if neither are set or are set to a value that cannot be parsed as an integer.
-
getInt
@Nullable public static Integer getInt(@NotNull String propertyName, @Nullable Integer defaultValue, boolean throwOnInvalidValue) throws IllegalArgumentException Retrieves the value of the specified property or environment variable as an integer.- Parameters:
propertyName- The name of the system property to retrieve, and to use to generate an alternative environment variable. It must not benullor empty.defaultValue- The default value to return if neither the system property nor associated environment variable have been set, or if the value cannot be parsed as an integer andthrowOnInvalidValueisfalse. It may benullif no default value should be returned.throwOnInvalidValue- Indicates whether this method should throw anIllegalArgumentExceptionif the system property or environment variable is set but its value cannot be parsed as an integer.- Returns:
- The integer value of the specified property or environment
variable, or the provided default value if neither are set or are
set to a value that cannot be parsed as an integer and
throwOnInvalidValueisfalse. - Throws:
IllegalArgumentException- If the property or environment variable is set, but its value cannot be parsed as an integer, andthrowOnInvalidValueistrue.
-
getLong
Retrieves the value of the specified property or environment variable as a long.- Parameters:
propertyName- The name of the system property to retrieve, and to use to generate an alternative environment variable. It must not benullor empty.- Returns:
- The long value of the specified property or environment variable,
or
nullif neither are set or are set to a value that cannot be parsed as a long.
-
getLong
Retrieves the value of the specified property or environment variable as a long.- Parameters:
propertyName- The name of the system property to retrieve, and to use to generate an alternative environment variable. It must not benullor empty.defaultValue- The default value to return if neither the system property nor associated environment variable have been set, or if the value cannot be parsed as a long. It may benullif no default value should be returned.- Returns:
- The long value of the specified property or environment variable, or the provided default value if neither are set or are set to a value that cannot be parsed as a long.
-
getLong
@Nullable public static Long getLong(@NotNull String propertyName, @Nullable Long defaultValue, boolean throwOnInvalidValue) throws IllegalArgumentException Retrieves the value of the specified property or environment variable as a long.- Parameters:
propertyName- The name of the system property to retrieve, and to use to generate an alternative environment variable. It must not benullor empty.defaultValue- The default value to return if neither the system property nor associated environment variable have been set, or if the value cannot be parsed as a long andthrowOnInvalidValueisfalse. It may benullif no default value should be returned.throwOnInvalidValue- Indicates whether this method should throw anIllegalArgumentExceptionif the system property or environment variable is set but its value cannot be parsed as a long.- Returns:
- The long value of the specified property or environment variable,
or the provided default value if neither are set or are set to a
value that cannot be parsed as a long and
throwOnInvalidValueisfalse. - Throws:
IllegalArgumentException- If the property or environment variable is set, but its value cannot be parsed as a long, andthrowOnInvalidValueistrue.
-
getCommaDelimitedList
Retrieves the value of the specified property or environment variable as a list of comma-delimited values. Any spaces around commas will be trimmed.- Parameters:
propertyName- The name of the system property to retrieve, and to use to generate an alternative environment variable. It must not benullor empty.- Returns:
- An unmodifiable list containing the comma-delimited values of the specified property or environment variable, or an empty list if neither is set.
-
getCommaDelimitedList
@NotNull public static List<String> getCommaDelimitedList(@NotNull String propertyName, boolean trimItems) Retrieves the value of the specified property or environment variable as a list of comma-delimited values. Any spaces around commas will be trimmed.- Parameters:
propertyName- The name of the system property to retrieve, and to use to generate an alternative environment variable. It must not benullor empty.trimItems- Indicates whether the individual items in the list should be trimmed to remove leading and/or trailing spaces.- Returns:
- An unmodifiable list containing the comma-delimited values of the specified property or environment variable, or an empty list if neither is set.
-
getProperties
Retrieves aPropertiesobject with values for any of the specified properties that are currently set.- Parameters:
propertyNames- The name of the properties whose values should be retrieved. It must not benull, but may be empty.- Returns:
- A
Propertiesobject with any of the specified properties that are set as either JVM system properties or environment variables. It may be empty if none of the specified properties have been set.
-
generateEnvironmentVariableNameFromPropertyName
@NotNull public static String generateEnvironmentVariableNameFromPropertyName(@NotNull String propertyName) Generates an alternative environment variable name that can be used for a given property name. All alphabetic letters in the provided name will be converted to uppercase, and all characters other than ASCII letters and digits will be converted to underscores.- Parameters:
propertyName- The property name to use to generate the environment variable name. It must not benullor empty.- Returns:
- The alternative environment variable name generated from the given property name.
-