Class PropertyPlaceholder
java.lang.Object
cloud.opencode.base.yml.placeholder.PropertyPlaceholder
Property Placeholder - Represents a parsed placeholder
属性占位符 - 表示解析后的占位符
This class represents a parsed placeholder with key and optional default value.
此类表示解析后的占位符,包含键和可选的默认值。
Features | 主要功能:
- Parse ${key} and ${key:default} expressions - 解析 ${key} 和 ${key:default} 表达式
- Custom delimiter support - 自定义分隔符支持
- Optional default value handling - 可选默认值处理
Usage Examples | 使用示例:
// Parse placeholder
PropertyPlaceholder ph = PropertyPlaceholder.parse("${server.port:8080}");
String key = ph.getKey(); // "server.port"
String def = ph.getDefaultValue(); // "8080"
// Check if has default
if (ph.hasDefaultValue()) {
// use default
}
Security | 安全性:
- Thread-safe: Yes (immutable after construction) - 线程安全: 是(构建后不可变)
- Null-safe: No (null expression throws NullPointerException) - 空值安全: 否(空表达式抛出 NullPointerException)
- Since:
- JDK 25, opencode-base-yml V1.0.0
- Author:
- Leon Soo www.LeonSoo.com
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionGets the default value as Optional.booleanGets the default value.getKey()Gets the placeholder key.Gets the raw expression.booleanChecks if this placeholder has a default value.inthashCode()static PropertyPlaceholderCreates a placeholder with key only.static PropertyPlaceholderCreates a placeholder with key and default value.static PropertyPlaceholderParses a placeholder expression.static PropertyPlaceholderParses a placeholder expression with custom delimiters.toString()
-
Method Details
-
parse
Parses a placeholder expression. 解析占位符表达式。- Parameters:
expression- the expression (e.g., "${key}" or "${key:default}") | 表达式- Returns:
- the parsed placeholder | 解析后的占位符
- Throws:
IllegalArgumentException- if expression is invalid | 如果表达式无效
-
parse
public static PropertyPlaceholder parse(String expression, String prefix, String suffix, String separator) Parses a placeholder expression with custom delimiters. 使用自定义分隔符解析占位符表达式。- Parameters:
expression- the expression | 表达式prefix- the placeholder prefix | 占位符前缀suffix- the placeholder suffix | 占位符后缀separator- the default value separator | 默认值分隔符- Returns:
- the parsed placeholder | 解析后的占位符
- Throws:
IllegalArgumentException- if expression is invalid | 如果表达式无效
-
of
Creates a placeholder with key only. 仅使用键创建占位符。- Parameters:
key- the key | 键- Returns:
- the placeholder | 占位符
-
of
Creates a placeholder with key and default value. 使用键和默认值创建占位符。- Parameters:
key- the key | 键defaultValue- the default value | 默认值- Returns:
- the placeholder | 占位符
-
getKey
-
getDefaultValue
Gets the default value. 获取默认值。- Returns:
- the default value, or null if none | 默认值,如果没有则返回 null
-
defaultValue
-
hasDefaultValue
public boolean hasDefaultValue()Checks if this placeholder has a default value. 检查此占位符是否有默认值。- Returns:
- true if has default value | 如果有默认值则返回 true
-
getRawExpression
Gets the raw expression. 获取原始表达式。- Returns:
- the raw expression | 原始表达式
-
toString
-
equals
-
hashCode
-