public final class ConfigValueParser
extends java.lang.Object
Supported placeholder syntax:
${name}${name:defaultValue}Notes:
name may include separators such as ., - and _.: (if present) separates the name from the default value.${a:${b}}) are intentionally not supported.| Modifier and Type | Class and Description |
|---|---|
static class |
ConfigValueParser.ConfigValue
Result of parsing an input configuration value.
|
static class |
ConfigValueParser.Placeholder
Immutable representation of a parsed placeholder.
|
static class |
ConfigValueParser.ValueType |
| Modifier and Type | Field and Description |
|---|---|
static java.util.function.Predicate<java.lang.String> |
BOOLEAN_VALUE_VALIDATOR
Validator suitable for boolean-like values:
allowed values: "", "true", "false" (case-insensitive).
|
| Modifier and Type | Method and Description |
|---|---|
static boolean |
isValidPlaceholder(java.lang.String raw)
Returns
true if the supplied value is syntactically a valid placeholder. |
static ConfigValueParser.ConfigValue |
parse(java.lang.String valueName,
java.lang.String raw)
Parses the provided value and classifies it as EMPTY, PLACEHOLDER, or LITERAL.
|
static ConfigValueParser.ConfigValue |
parse(java.lang.String valueName,
java.lang.String raw,
java.util.function.Predicate<java.lang.String> valueValidator)
Parses the provided value and classifies it as EMPTY, PLACEHOLDER, or LITERAL, while also validating:
Placeholder syntax (always, when value starts with ${)
Placeholder default value (only when present, using
valueValidator if provided)
Literal value (using valueValidator if provided)
|
static java.util.Optional<ConfigValueParser.Placeholder> |
parsePlaceholder(java.lang.String valueName,
java.lang.String raw)
Parses a placeholder if (and only if) the entire value is a placeholder.
|
public static final java.util.function.Predicate<java.lang.String> BOOLEAN_VALUE_VALIDATOR
public static ConfigValueParser.ConfigValue parse(java.lang.String valueName, java.lang.String raw)
This overload performs only placeholder syntax validation. Literals and placeholder defaults are accepted as-is.
valueName - logical name used in exception messages (e.g. "origin", "emptyOriginAllowed")raw - raw input valuepublic static ConfigValueParser.ConfigValue parse(java.lang.String valueName, java.lang.String raw, java.util.function.Predicate<java.lang.String> valueValidator)
valueValidator if provided)valueValidator if provided)Fail-fast rule: if the value starts with ${} but is not a valid placeholder,
this method throws IllegalArgumentException.
valueName - logical name used in exception messages (e.g. "origin", "emptyOriginAllowed")raw - raw input valuevalueValidator - validator applied to literal values and placeholder default values (may be null)public static java.util.Optional<ConfigValueParser.Placeholder> parsePlaceholder(java.lang.String valueName, java.lang.String raw)
Returns Optional.empty() if the input is null, blank, or not a placeholder.
Important: if the value starts with ${} but is not a valid placeholder,
this method throws IllegalArgumentException.
public static boolean isValidPlaceholder(java.lang.String raw)
true if the supplied value is syntactically a valid placeholder.
This method never throws. If you need fail-fast behaviour for values starting with ${,
use parse(String, String).