PropertyKey class provides a unified way to access configuration values from both environment variables and Java system properties, with automatic camelCase to CONSTANT_CASE conversion.
Package
Class Declaration
Constructors
PropertyKey(String key, String env)
Creates a PropertyKey with explicit property key and environment variable names.The system property key name
The environment variable name
PropertyKey(String key)
Creates a PropertyKey with automatic environment variable name conversion from camelCase to CONSTANT_CASE.The system property key name (camelCase)
Methods
getKey
Returns the system property key name.The system property key
getEnv
Returns the environment variable name.The environment variable name
getValue
Retrieves the property value, checking environment variables first, then system properties.The property value, or null if not found
getValue(String defaultValue)
Retrieves the property value with a fallback default.The default value to return if the property is not found
The property value, or the default value if not found
setValue(String value)
Sets the property value as a system property.The value to set
setValue(Object value)
Sets the property value from any object usingtoString().
The object to convert to a string and set
isPresent
Checks if the property has a value.True if the property value is not null
isAbsent
Checks if the property has no value.True if the property value is null
asNumber
Parses the property value as a number.The default value to return if parsing fails or property is absent
The parsed number, or the default value
asBoolean
Parses the property value as a boolean.The default value to return if property is absent
The parsed boolean, or the default value
CamelCase to CONSTANT_CASE Conversion
The automatic conversion transforms property keys:Property Resolution Order
- Environment variable (e.g.,
GITHUB_TOKEN) - System property (e.g.,
github.token) - Default value (if provided)
null(if no default)
Example Usage
Related Classes
- CLIPropertyKey - CLI-specific properties
- CommonPropertyKey - Shared properties