public final class JkProperties
extends java.lang.Object
String
.This object provides interpolation and fallback features.
Part of the value can be expressed by referencing the name of another property. For example, if we have
foo=bar foo2=${foo}${foo}then
foo2=barbar
JkProperties
objects can be combined to form a chain of resolution using a fallback mechanism.
Modifier and Type | Field and Description |
---|---|
static JkProperties |
EMPTY |
static JkProperties |
ENVIRONMENT_VARIABLES
Environment variables exposed as JkProperties.
|
static java.util.function.Predicate<java.lang.String> |
SENSITIVE_KEY_PATTERN
A predicate used to determine if a given string is a sensitive key.
|
Modifier and Type | Method and Description |
---|---|
boolean |
containsKey(java.lang.String propName)
Checks if the given property name exists in the properties.
|
java.util.Set<java.lang.String> |
find(java.lang.String prefix)
Returns all keys with the specified prefix.
|
java.lang.String |
get(java.lang.String propertyName)
Returns the value associated with the specified property name or
null if no value has been
specified for this name. |
java.lang.String |
get(java.lang.String propertyName,
java.lang.String defaultValue)
Returns the value associated with the specified property name or the defaultValue if no value has been
specified for this name.
|
java.util.Map<java.lang.String,java.lang.String> |
getAllStartingWith(java.lang.String prefix,
boolean keepPrefix) |
static JkProperties |
ofFile(java.nio.file.Path propertyFile)
Returns an instance of JkProperties by loading properties from the specified file.
|
static JkProperties |
ofMap(java.util.Map<java.lang.String,java.lang.String> props) |
static JkProperties |
ofMap(java.lang.String sourceName,
java.util.Map<java.lang.String,java.lang.String> props) |
static JkProperties |
ofStandardProperties()
Returns an instance of JkProperties from system properties and environment variables,
with fallback to global.properties if they exist.
|
static JkProperties |
ofSysPropsThenEnv() |
JkColumnText |
toColumnText(int keyMaxLength,
int valueMaxLength,
boolean canTruncate)
Converts the properties to a formatted column text representation.
|
java.lang.String |
toString() |
JkProperties |
withFallback(JkProperties fallback)
Returns a JkProperties instance from this one plus the specified fallback.
|
public static final java.util.function.Predicate<java.lang.String> SENSITIVE_KEY_PATTERN
public static final JkProperties ENVIRONMENT_VARIABLES
Each environment variable is exposed with 2 names :
public static final JkProperties EMPTY
public static JkProperties ofMap(java.lang.String sourceName, java.util.Map<java.lang.String,java.lang.String> props)
public static JkProperties ofMap(java.util.Map<java.lang.String,java.lang.String> props)
public static JkProperties ofSysPropsThenEnv()
public static JkProperties ofStandardProperties()
public static JkProperties ofFile(java.nio.file.Path propertyFile)
public JkProperties withFallback(JkProperties fallback)
public java.lang.String get(java.lang.String propertyName)
null
if no value has been
specified for this name.
public java.lang.String get(java.lang.String propertyName, java.lang.String defaultValue)
public boolean containsKey(java.lang.String propName)
public java.util.Map<java.lang.String,java.lang.String> getAllStartingWith(java.lang.String prefix, boolean keepPrefix)
public java.util.Set<java.lang.String> find(java.lang.String prefix)
null
or empty,
then returns all keys.public java.lang.String toString()
toString
in class java.lang.Object
public JkColumnText toColumnText(int keyMaxLength, int valueMaxLength, boolean canTruncate)
keyMaxLength
- The maximum length of the key column.valueMaxLength
- The maximum length of the value column.canTruncate
- Flag indicating whether the values can be truncated if they exceed the maximum length.