Class NamedStringTemplate
java.lang.Object
org.miaixz.bus.core.text.placeholder.StringTemplate
org.miaixz.bus.core.text.placeholder.template.NamedStringTemplate
有前后缀的字符串模板
例如,"{1}", "{name}", "#{data}"
- Since:
- Java 17+
- Author:
- Kimi Liu
-
Nested Class Summary
Nested ClassesNested classes/interfaces inherited from class org.miaixz.bus.core.text.placeholder.StringTemplate
StringTemplate.AbstractBuilder<BuilderChild extends StringTemplate.AbstractBuilder<BuilderChild,TemplateChild>, TemplateChild extends StringTemplate>, StringTemplate.Feature -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final String默认前缀static final String默认后缀protected int在下标占位符中,最大的下标值protected String占位符前缀,默认为:DEFAULT_PREFIXprotected String占位符后缀,默认为:DEFAULT_SUFFIXFields inherited from class org.miaixz.bus.core.text.placeholder.StringTemplate
defaultValue, defaultValueHandler, escape, fixedTextTotalLength, globalDefaultValueHandler, globalFeatures, placeholderSegments, segments -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedNamedStringTemplate(String template, int features, String prefix, String suffix, char escape, String defaultValue, UnaryOperator<String> defaultValueHandler) -
Method Summary
Modifier and TypeMethodDescriptionstatic NamedStringTemplate.Builder创建 builder使用占位变量名称,从 Bean 或 Map 中查询值来替换占位符使用占位变量名称,从 valueSupplier 中查询值来替换占位符使用占位变量名称,从 valueSupplier 中查询值来替换占位符使用占位变量名称,从 Map 中查询值来替换占位符formatArrayIndexed(Object array) 按下标使用原始数组元素替换占位符formatArrayIndexed(Object[] array) 按 下标 使用 数组元素 替换 占位符formatArraySequence(Object array) 按顺序使用原始数组元素替换占位符formatArraySequence(Object[] array) 按顺序使用数组元素替换占位符formatIndexed(Object... args) 按下标使用数组元素替换占位符formatIndexed(Collection<?> collection) 按下标使用集合元素替换占位符formatIndexed(Collection<?> collection, IntFunction<String> missingIndexHandler) 按 下标 使用 集合元素 替换 占位符formatSequence(Iterable<?> iterable) 按顺序使用迭代器元素替换占位符formatSequence(Object... args) 按顺序使用数组元素替换占位符根据占位变量和对应位置解析值,构造Map<T> T根据占位变量和对应位置解析值,构造 map 或者 beans 实例matchesIndexed(String text) 将占位符位置的值,按占位符下标值解析为字符串列表voidmatchesIndexed(String text, BiConsumer<Integer, String> idxValueConsumer, IntFunction<String> missingIndexHandler) 根据下标和下标占位符位置的值,自行提取结果值matchesIndexed(String text, IntFunction<String> missingIndexHandler) 将占位符位置的值,按占位符下标值解析为字符串列表String[]matchesIndexedToArray(String text) 将占位符位置的值,按占位符下标值解析为字符串数组String[]matchesIndexedToArray(String text, IntFunction<String> missingIndexHandler) 将占位符位置的值,按占位符下标值解析为字符串数组matchesSequence(String text) 将占位符位置的值,按顺序解析为字符串列表String[]matchesSequenceToArray(String text) 将占位符位置的值,按顺序解析为字符串数组protected List<StringSegment> parseSegments(String template) 将 模板 解析为 SectionBuffer 列表Methods inherited from class org.miaixz.bus.core.text.placeholder.StringTemplate
addLiteralSegment, afterInit, formatBySegment, formatMissingKey, formatNullValue, formatRawByKey, formatRawBySegment, getDefaultValue, getFeatures, getPlaceholderSegments, getPlaceholderTexts, getPlaceholderVariableNames, getSegments, getTemplate, hasDefaultValue, isMatches, matchesByKey, matchesByKey, matchesRawByKey, matchesRawBySegment, of, ofNamed, setGlobalDefaultValue, setGlobalFeatures
-
Field Details
-
DEFAULT_PREFIX
默认前缀- See Also:
-
DEFAULT_SUFFIX
默认后缀- See Also:
-
prefix
占位符前缀,默认为:DEFAULT_PREFIX -
suffix
占位符后缀,默认为:DEFAULT_SUFFIX -
indexedSegmentMaxIdx
protected int indexedSegmentMaxIdx在下标占位符中,最大的下标值
-
-
Constructor Details
-
NamedStringTemplate
-
-
Method Details
-
builder
创建 builder- Parameters:
template- 字符串模板,不能为null- Returns:
- builder实例
-
parseSegments
Description copied from class:StringTemplate将 模板 解析为 SectionBuffer 列表- Specified by:
parseSegmentsin classStringTemplate- Parameters:
template- 字符串模板- Returns:
- Segment列表
-
formatSequence
按顺序使用数组元素替换占位符- Parameters:
args- 可变参数- Returns:
- 格式化字符串
-
formatArraySequence
按顺序使用原始数组元素替换占位符- Parameters:
array- 原始类型数组,例如:int[]- Returns:
- 格式化字符串
-
formatArraySequence
按顺序使用数组元素替换占位符- Parameters:
array- 数组- Returns:
- 格式化字符串
-
formatSequence
按顺序使用迭代器元素替换占位符- Overrides:
formatSequencein classStringTemplate- Parameters:
iterable- iterable- Returns:
- 格式化字符串
-
formatIndexed
按下标使用数组元素替换占位符- Parameters:
args- 可变参数- Returns:
- 格式化字符串
-
formatArrayIndexed
按下标使用原始数组元素替换占位符- Parameters:
array- 原始类型数组- Returns:
- 格式化字符串
-
formatArrayIndexed
按 下标 使用 数组元素 替换 占位符- Parameters:
array- 数组- Returns:
- 格式化字符串
-
formatIndexed
按下标使用集合元素替换占位符- Parameters:
collection- 集合元素- Returns:
- 格式化字符串
-
formatIndexed
按 下标 使用 集合元素 替换 占位符- Parameters:
collection- 集合元素missingIndexHandler- 集合中不存在下标位置时的处理器,根据 下标 返回 代替值- Returns:
- 格式化字符串
-
format
使用占位变量名称,从 Bean 或 Map 中查询值来替换占位符- Parameters:
beanOrMap- Bean 或 Map 实例- Returns:
- 格式化字符串
-
format
使用占位变量名称,从 Map 中查询值来替换占位符- Parameters:
map- map- Returns:
- 格式化字符串
-
format
使用占位变量名称,从 valueSupplier 中查询值来替换占位符- Parameters:
valueSupplier- 根据 占位变量名称 返回 值- Returns:
- 格式化字符串
-
format
使用占位变量名称,从 valueSupplier 中查询值来替换占位符- Parameters:
valueSupplier- 根据 占位变量名称 返回 值containsKey- 占位变量名称 是否存在,例如:map.containsKey(data)- Returns:
- 格式化字符串
-
matchesSequenceToArray
将占位符位置的值,按顺序解析为字符串数组- Parameters:
text- 待解析的字符串,一般是格式化方法的返回值- Returns:
- 字符串数组
-
matchesSequence
将占位符位置的值,按顺序解析为字符串列表- Overrides:
matchesSequencein classStringTemplate- Parameters:
text- 待解析的字符串,一般是格式化方法的返回值- Returns:
- 字符串列表
-
matchesIndexedToArray
将占位符位置的值,按占位符下标值解析为字符串数组- Parameters:
text- 待解析的字符串,一般是格式化方法的返回值- Returns:
- 字符串数组
- See Also:
-
matchesIndexedToArray
将占位符位置的值,按占位符下标值解析为字符串数组- Parameters:
text- 待解析的字符串,一般是格式化方法的返回值missingIndexHandler- 根据 下标 返回 默认值,该参数可以为null,仅在StringTemplate.Feature.MATCH_EMPTY_VALUE_TO_DEFAULT_VALUE策略时生效- Returns:
- 字符串数组
- See Also:
-
matchesIndexed
将占位符位置的值,按占位符下标值解析为字符串列表- Parameters:
text- 待解析的字符串,一般是格式化方法的返回值- Returns:
- 字符串列表
- See Also:
-
matchesIndexed
将占位符位置的值,按占位符下标值解析为字符串列表例如,模板中为 "This is between {1} and {2}",格式化结果为 "This is between 666 and 999", 由于其最大下标为 2, 则解析结果中固定有 3 个元素,解析结果为
[null, "666", "999"]- Parameters:
text- 待解析的字符串,一般是格式化方法的返回值missingIndexHandler- 根据 下标 返回 默认值,该参数可以为null,仅在StringTemplate.Feature.MATCH_EMPTY_VALUE_TO_DEFAULT_VALUE策略时生效- Returns:
- 字符串列表
-
matchesIndexed
public void matchesIndexed(String text, BiConsumer<Integer, String> idxValueConsumer, IntFunction<String> missingIndexHandler) 根据下标和下标占位符位置的值,自行提取结果值例如,模板中为 "This is between {1} and {2}",格式化结果为 "This is between 666 and 999", 由于其最大下标为 2, 则解析结果中固定有 3 个元素,解析结果为
[null, "666", "999"]- Parameters:
text- 待解析的字符串,一般是格式化方法的返回值idxValueConsumer- 处理 下标 和 下标占位符位置的值 的消费者,例如:(idx, value) -> list.set(idx, value)missingIndexHandler- 根据 下标 返回 默认值,该参数可以为null,仅在StringTemplate.Feature.MATCH_EMPTY_VALUE_TO_DEFAULT_VALUE策略时生效
-
matches
根据占位变量和对应位置解析值,构造Map- Parameters:
text- 待解析的字符串,一般是格式化方法的返回值- Returns:
Map
-
matches
根据占位变量和对应位置解析值,构造 map 或者 beans 实例- Type Parameters:
T- 返回结果对象类型- Parameters:
text- 待解析的字符串,一般是格式化方法的返回值beanOrMapSupplier- 提供一个 beans 或者 map,例如:HashMap::new- Returns:
- map 或者 beans 实例
-