Package com.unboundid.util
Class PropertyManager
- java.lang.Object
-
- com.unboundid.util.PropertyManager
-
@ThreadSafety(level=COMPLETELY_THREADSAFE) public final class PropertyManager extends java.lang.Object
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 thegenerateEnvironmentVariableNameFromPropertyName(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
All Methods Static Methods Concrete Methods Modifier and Type Method Description static java.lang.StringgenerateEnvironmentVariableNameFromPropertyName(java.lang.String propertyName)Generates an alternative environment variable name that can be used for a given property name.static java.lang.Stringget(java.lang.String propertyName)Retrieves the value of the specified system property or environment variable.static java.lang.Stringget(java.lang.String propertyName, java.lang.String defaultValue)Retrieves the value of the specified system property or environment variable.static java.lang.BooleangetBoolean(java.lang.String propertyName)Retrieves the value of the specified property or environment variable as a Boolean value.static java.lang.BooleangetBoolean(java.lang.String propertyName, java.lang.Boolean defaultValue)Retrieves the value of the specified property or environment variable as a Boolean value.static java.lang.BooleangetBoolean(java.lang.String propertyName, java.lang.Boolean defaultValue, boolean throwOnInvalidValue)Retrieves the value of the specified property or environment variable as a Boolean value.static java.util.List<java.lang.String>getCommaDelimitedList(java.lang.String propertyName)Retrieves the value of the specified property or environment variable as a list of comma-delimited values.static java.util.List<java.lang.String>getCommaDelimitedList(java.lang.String propertyName, boolean trimItems)Retrieves the value of the specified property or environment variable as a list of comma-delimited values.static java.lang.IntegergetInt(java.lang.String propertyName)Retrieves the value of the specified property or environment variable as an integer.static java.lang.IntegergetInt(java.lang.String propertyName, java.lang.Integer defaultValue)Retrieves the value of the specified property or environment variable as an integer.static java.lang.IntegergetInt(java.lang.String propertyName, java.lang.Integer defaultValue, boolean throwOnInvalidValue)Retrieves the value of the specified property or environment variable as an integer.static java.lang.LonggetLong(java.lang.String propertyName)Retrieves the value of the specified property or environment variable as a long.static java.lang.LonggetLong(java.lang.String propertyName, java.lang.Long defaultValue)Retrieves the value of the specified property or environment variable as a long.static java.lang.LonggetLong(java.lang.String propertyName, java.lang.Long defaultValue, boolean throwOnInvalidValue)Retrieves the value of the specified property or environment variable as a long.static java.util.PropertiesgetProperties(java.lang.String... propertyNames)Retrieves aPropertiesobject with values for any of the specified properties that are currently set.
-
-
-
Method Detail
-
get
@Nullable public static java.lang.String get(@NotNull java.lang.String propertyName)
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
@Nullable public static java.lang.String get(@NotNull java.lang.String propertyName, @Nullable java.lang.String defaultValue)
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
@Nullable public static java.lang.Boolean getBoolean(@NotNull java.lang.String propertyName)
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 java.lang.Boolean getBoolean(@NotNull java.lang.String propertyName, @Nullable java.lang.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 java.lang.Boolean getBoolean(@NotNull java.lang.String propertyName, @Nullable java.lang.Boolean defaultValue, boolean throwOnInvalidValue) throws java.lang.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:
java.lang.IllegalArgumentException- If the property or environment variable is set, but its value cannot be parsed as a Boolean, andthrowOnInvalidValueistrue.
-
getInt
@Nullable public static java.lang.Integer getInt(@NotNull java.lang.String propertyName)
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 java.lang.Integer getInt(@NotNull java.lang.String propertyName, @Nullable java.lang.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 java.lang.Integer getInt(@NotNull java.lang.String propertyName, @Nullable java.lang.Integer defaultValue, boolean throwOnInvalidValue) throws java.lang.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:
java.lang.IllegalArgumentException- If the property or environment variable is set, but its value cannot be parsed as an integer, andthrowOnInvalidValueistrue.
-
getLong
@Nullable public static java.lang.Long getLong(@NotNull java.lang.String propertyName)
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
@Nullable public static java.lang.Long getLong(@NotNull java.lang.String propertyName, @Nullable java.lang.Long defaultValue)
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 java.lang.Long getLong(@NotNull java.lang.String propertyName, @Nullable java.lang.Long defaultValue, boolean throwOnInvalidValue) throws java.lang.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:
java.lang.IllegalArgumentException- If the property or environment variable is set, but its value cannot be parsed as a long, andthrowOnInvalidValueistrue.
-
getCommaDelimitedList
@NotNull public static java.util.List<java.lang.String> getCommaDelimitedList(@NotNull java.lang.String propertyName)
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 java.util.List<java.lang.String> getCommaDelimitedList(@NotNull java.lang.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
@NotNull public static java.util.Properties getProperties(@NotNull java.lang.String... propertyNames)
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 java.lang.String generateEnvironmentVariableNameFromPropertyName(@NotNull java.lang.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.
-
-