@ThreadSafety(level=COMPLETELY_THREADSAFE) public final class PropertyManager extends java.lang.Object
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.Modifier and Type | Method and Description |
---|---|
static java.lang.String |
generateEnvironmentVariableNameFromPropertyName(java.lang.String propertyName)
Generates an alternative environment variable name that can be used for a
given property name.
|
static java.lang.String |
get(java.lang.String propertyName)
Retrieves the value of the specified system property or environment
variable.
|
static java.lang.String |
get(java.lang.String propertyName,
java.lang.String defaultValue)
Retrieves the value of the specified system property or environment
variable.
|
static java.lang.Boolean |
getBoolean(java.lang.String propertyName)
Retrieves the value of the specified property or environment variable as a
Boolean value.
|
static java.lang.Boolean |
getBoolean(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.Boolean |
getBoolean(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.Integer |
getInt(java.lang.String propertyName)
Retrieves the value of the specified property or environment variable as an
integer.
|
static java.lang.Integer |
getInt(java.lang.String propertyName,
java.lang.Integer defaultValue)
Retrieves the value of the specified property or environment variable as an
integer.
|
static java.lang.Integer |
getInt(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.Long |
getLong(java.lang.String propertyName)
Retrieves the value of the specified property or environment variable as a
long.
|
static java.lang.Long |
getLong(java.lang.String propertyName,
java.lang.Long defaultValue)
Retrieves the value of the specified property or environment variable as a
long.
|
static java.lang.Long |
getLong(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.Properties |
getProperties(java.lang.String... propertyNames)
Retrieves a
Properties object with values for any of the specified
properties that are currently set. |
@Nullable public static java.lang.String get(@NotNull java.lang.String propertyName)
propertyName
- The name of the system property to retrieve, and to
use to generate an alternative environment variable.
It must not be null
or empty.null
if it has not been set as
either a system property or an environment variable.@Nullable public static java.lang.String get(@NotNull java.lang.String propertyName, @Nullable java.lang.String defaultValue)
propertyName
- The name of the system property to retrieve, and to
use to generate an alternative environment variable.
It must not be null
or empty.defaultValue
- The default value to return if neither the system
property nor associated environment variable have
been set. It may be null
if no default value
should be returned.null
if it has not been set as
either a system property or an environment variable.@Nullable public static java.lang.Boolean getBoolean(@NotNull java.lang.String propertyName)
propertyName
- The name of the system property to retrieve, and to
use to generate an alternative environment variable.
It must not be null
or empty.null
if neither are set or are set to a
value that cannot be parsed as a Boolean.@Nullable public static java.lang.Boolean getBoolean(@NotNull java.lang.String propertyName, @Nullable java.lang.Boolean defaultValue)
propertyName
- The name of the system property to retrieve, and to
use to generate an alternative environment variable.
It must not be null
or 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 be null
if no default value
should be returned.@Nullable public static java.lang.Boolean getBoolean(@NotNull java.lang.String propertyName, @Nullable java.lang.Boolean defaultValue, boolean throwOnInvalidValue) throws java.lang.IllegalArgumentException
propertyName
- The name of the system property to retrieve,
and to use to generate an alternative
environment variable. It must not be
null
or 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 and
throwOnInvalidValue
is false
.
It may be null
if no default value
should be returned.throwOnInvalidValue
- Indicates whether this method should throw an
IllegalArgumentException
if the
system property or environment variable is
set but its value cannot be parsed as a
Boolean.throwOnInvalidValue
is false
.java.lang.IllegalArgumentException
- If the property or environment variable
is set, but its value cannot be parsed
as a Boolean, and
throwOnInvalidValue
is
true
.@Nullable public static java.lang.Integer getInt(@NotNull java.lang.String propertyName)
propertyName
- The name of the system property to retrieve, and to
use to generate an alternative environment variable.
It must not be null
or empty.null
if neither are set or are set to a
value that cannot be parsed as an integer.@Nullable public static java.lang.Integer getInt(@NotNull java.lang.String propertyName, @Nullable java.lang.Integer defaultValue)
propertyName
- The name of the system property to retrieve, and to
use to generate an alternative environment variable.
It must not be null
or 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 be null
if no default value
should be returned.@Nullable public static java.lang.Integer getInt(@NotNull java.lang.String propertyName, @Nullable java.lang.Integer defaultValue, boolean throwOnInvalidValue) throws java.lang.IllegalArgumentException
propertyName
- The name of the system property to retrieve,
and to use to generate an alternative
environment variable. It must not be
null
or 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 and
throwOnInvalidValue
is false
.
It may be null
if no default value
should be returned.throwOnInvalidValue
- Indicates whether this method should throw an
IllegalArgumentException
if the
system property or environment variable is
set but its value cannot be parsed as an
integer.throwOnInvalidValue
is false
.java.lang.IllegalArgumentException
- If the property or environment variable
is set, but its value cannot be parsed
as an integer, and
throwOnInvalidValue
is
true
.@Nullable public static java.lang.Long getLong(@NotNull java.lang.String propertyName)
propertyName
- The name of the system property to retrieve, and to
use to generate an alternative environment variable.
It must not be null
or empty.null
if neither are set or are set to a value that
cannot be parsed as a long.@Nullable public static java.lang.Long getLong(@NotNull java.lang.String propertyName, @Nullable java.lang.Long defaultValue)
propertyName
- The name of the system property to retrieve, and to
use to generate an alternative environment variable.
It must not be null
or 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 be null
if no default value should be
returned.@Nullable public static java.lang.Long getLong(@NotNull java.lang.String propertyName, @Nullable java.lang.Long defaultValue, boolean throwOnInvalidValue) throws java.lang.IllegalArgumentException
propertyName
- The name of the system property to retrieve,
and to use to generate an alternative
environment variable. It must not be
null
or 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 and
throwOnInvalidValue
is false
.
It may be null
if no default value
should be returned.throwOnInvalidValue
- Indicates whether this method should throw an
IllegalArgumentException
if the
system property or environment variable is
set but its value cannot be parsed as a
long.throwOnInvalidValue
is false
.java.lang.IllegalArgumentException
- If the property or environment variable
is set, but its value cannot be parsed
as a long, and
throwOnInvalidValue
is
true
.@NotNull public static java.util.List<java.lang.String> getCommaDelimitedList(@NotNull java.lang.String propertyName)
propertyName
- The name of the system property to retrieve, and to
use to generate an alternative environment variable.
It must not be null
or empty.@NotNull public static java.util.List<java.lang.String> getCommaDelimitedList(@NotNull java.lang.String propertyName, boolean trimItems)
propertyName
- The name of the system property to retrieve, and to
use to generate an alternative environment variable.
It must not be null
or empty.trimItems
- Indicates whether the individual items in the list
should be trimmed to remove leading and/or trailing
spaces.@NotNull public static java.util.Properties getProperties(@NotNull java.lang.String... propertyNames)
Properties
object with values for any of the specified
properties that are currently set.propertyNames
- The name of the properties whose values should be
retrieved. It must not be null
, but may be
empty.Properties
object 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.@NotNull public static java.lang.String generateEnvironmentVariableNameFromPropertyName(@NotNull java.lang.String propertyName)
propertyName
- The property name to use to generate the environment
variable name. It must not be null
or empty.