public class Substitute extends Object
| Modifier and Type | Field and Description |
|---|---|
static StrMatcher |
DEFAULT_PREFIX
默认变量前缀.
|
static StrMatcher |
DEFAULT_SUFFIX
默认变量后缀.
|
static StrMatcher |
DEFAULT_VALUE_DELIMITER
默认值分隔符.
|
| Constructor and Description |
|---|
Substitute()
默认值为变量前缀和后缀以及转义字符.
|
Substitute(Map<String,V> valueMap)
创建一个新实例并初始化它 对变量使用默认值
前缀和后缀以及转义字符
|
Substitute(Map<String,V> valueMap,
String prefix,
String suffix)
创建一个新实例并初始化它 使用默认转义字符
|
Substitute(Map<String,V> valueMap,
String prefix,
String suffix,
char escape)
创建一个新实例并初始化.
|
Substitute(Map<String,V> valueMap,
String prefix,
String suffix,
char escape,
String delimiter)
创建一个新实例并初始化.
|
Substitute(StrLookup<?> resolver)
创建一个新实例并初始化.
|
Substitute(StrLookup<?> resolver,
String prefix,
String suffix,
char escape)
创建一个新实例并初始化.
|
Substitute(StrLookup<?> resolver,
String prefix,
String suffix,
char escape,
String delimiter)
创建一个新实例并初始化.
|
Substitute(StrLookup<?> resolver,
StrMatcher prefixMatcher,
StrMatcher suffixMatcher,
char escape)
创建一个新实例并初始化.
|
Substitute(StrLookup<?> resolver,
StrMatcher prefixMatcher,
StrMatcher suffixMatcher,
char escape,
StrMatcher delimiter)
创建一个新实例并初始化.
|
| Modifier and Type | Method and Description |
|---|---|
char |
getEscapeChar()
返回转义字符.
|
StrMatcher |
getValueDelimiterMatcher() |
StrMatcher |
getVariablePrefixMatcher()
获取当前使用的变量前缀匹配器
|
StrLookup<?> |
getVariableResolver() |
StrMatcher |
getVariableSuffixMatcher()
获取当前使用的变量后缀匹配器
|
boolean |
isEnableSubstitutionInVariables() |
boolean |
isPreserveEscapes() |
String |
replace(char[] source)
用匹配的值替换所有出现的变量
从使用给定源数组作为模板的解析器
该方法不改变数组
|
String |
replace(char[] source,
int offset,
int length)
用匹配的值替换所有出现的变量
|
String |
replace(CharSequence source)
用匹配的值替换所有出现的变量
|
String |
replace(CharSequence source,
int offset,
int length)
用匹配的值替换所有出现的变量
|
String |
replace(Object source)
用匹配的值替换所有出现的变量
|
static <V> String |
replace(Object source,
Map<String,V> valueMap)
替换给定源对象中出现的所有变量
它们在映射中的匹配值
|
static <V> String |
replace(Object source,
Map<String,V> valueMap,
String prefix,
String suffix)
将给定源对象中出现的所有变量替换
它们在映射中匹配的值 这种方法允许指定自定义变量前缀和后缀
|
static String |
replace(Object source,
Properties value)
用匹配的变量替换给定源对象中出现的所有变量
|
String |
replace(StrBuilder source)
用匹配的值替换所有出现的变量
|
String |
replace(StrBuilder source,
int offset,
int length)
用匹配的值替换所有出现的变量
|
String |
replace(String source)
用匹配的值替换所有出现的变量
从使用给定源字符串作为模板的解析器
|
String |
replace(StringBuffer source)
用匹配值替换所有出现的变量
从使用给定源缓冲区作为模板的解析器
|
String |
replace(StringBuffer source,
int offset,
int length)
用匹配的值替换所有出现的变量
|
String |
replace(String source,
int offset,
int length)
用匹配的值替换所有出现的变量
|
boolean |
replaceIn(StrBuilder source)
用匹配的值替换所有出现的变量
|
boolean |
replaceIn(StrBuilder source,
int offset,
int length)
用匹配的值替换所有出现的变量
|
boolean |
replaceIn(StringBuffer source)
用匹配的值替换所有出现的变量
|
boolean |
replaceIn(StringBuffer source,
int offset,
int length)
用匹配的值替换所有出现的变量
|
boolean |
replaceIn(StringBuilder source)
用匹配的值替换所有出现的变量
|
boolean |
replaceIn(StringBuilder source,
int offset,
int length)
用匹配的值替换所有出现的变量
|
static String |
replaceSystemProperties(Object source)
替换给定源对象中出现的所有变量
它们在系统属性中匹配的值
|
protected String |
resolveVariable(String variableName,
StrBuilder buf,
int startPos,
int endPos)
解析变量值的内部方法
getVariableResolver(),其中变量名作为键 |
void |
setEnableSubstitutionInVariables(boolean enableSubstitutionInVariables) |
void |
setEscapeChar(char escapeCharacter)
设置转义字符
如果该字符放在源中的变量引用之前,这个变量将被忽略
|
void |
setPreserveEscapes(boolean preserveEscapes) |
Substitute |
setValueDelimiter(char valueDelimiter) |
Substitute |
setValueDelimiter(String valueDelimiter)
设置要使用的变量默认值分隔符
|
Substitute |
setValueDelimiterMatcher(StrMatcher valueDelimiterMatcher) |
Substitute |
setVariablePrefix(char prefix)
设置要使用的变量前缀
|
Substitute |
setVariablePrefix(String prefix)
设置要使用的变量前缀
|
Substitute |
setVariablePrefixMatcher(StrMatcher prefixMatcher)
设置当前使用的变量前缀匹配器
|
void |
setVariableResolver(StrLookup<?> variableResolver) |
Substitute |
setVariableSuffix(char suffix)
设置要使用的变量后缀
|
Substitute |
setVariableSuffix(String suffix)
设置要使用的变量后缀
|
Substitute |
setVariableSuffixMatcher(StrMatcher suffixMatcher)
设置当前使用的变量后缀匹配器
|
protected boolean |
substitute(StrBuilder buffer,
int offset,
int length)
替换变量的内部方法
|
public static final StrMatcher DEFAULT_PREFIX
public static final StrMatcher DEFAULT_SUFFIX
public static final StrMatcher DEFAULT_VALUE_DELIMITER
public Substitute()
public Substitute(Map<String,V> valueMap)
V - 映射中值的类型valueMap - 带有变量值的映射可能为nullpublic Substitute(Map<String,V> valueMap, String prefix, String suffix)
V - 映射中值的类型valueMap - 带有变量值的映射可能为nullprefix - 变量的前缀,而不是nullsuffix - 变量的后缀,而不是nullpublic Substitute(Map<String,V> valueMap, String prefix, String suffix, char escape)
V - 映射中值的类型valueMap - 带有变量值的映射可能为nullprefix - 变量的前缀,而不是nullsuffix - 变量的后缀,而不是nullescape - 转义字符public Substitute(Map<String,V> valueMap, String prefix, String suffix, char escape, String delimiter)
V - 映射中值的类型valueMap - 带有变量值的映射可能为nullprefix - 变量的前缀,而不是nullsuffix - 变量的后缀,而不是nullescape - 转义字符delimiter - 变量默认值分隔符可以为空public Substitute(StrLookup<?> resolver)
resolver - 变量解析器可以为空public Substitute(StrLookup<?> resolver, String prefix, String suffix, char escape)
resolver - 变量解析器可以为空prefix - 变量的前缀,而不是nullsuffix - 变量的后缀,而不是nullescape - 转义字符public Substitute(StrLookup<?> resolver, String prefix, String suffix, char escape, String delimiter)
resolver - 变量解析器可以为空prefix - 变量的前缀,而不是nullsuffix - 变量的后缀,而不是nullescape - 转义字符delimiter - 变量默认值分隔符可以为空public Substitute(StrLookup<?> resolver, StrMatcher prefixMatcher, StrMatcher suffixMatcher, char escape)
resolver - 变量解析器,可以为空prefixMatcher - 前缀解析器,而不是nullsuffixMatcher - 后缀解析器,而不是nullescape - 转义转义字符public Substitute(StrLookup<?> resolver, StrMatcher prefixMatcher, StrMatcher suffixMatcher, char escape, StrMatcher delimiter)
resolver - 变量解析器,可以为空prefixMatcher - 前缀解析器,而不是nullsuffixMatcher - 后缀解析器,而不是nullescape - 转义转义字符delimiter - 变量默认值分隔符可以为空public static <V> String replace(Object source, Map<String,V> valueMap)
V - 映射中值的类型source - 包含要替换的变量的源文本valueMap - 映射的值可能为空public static <V> String replace(Object source, Map<String,V> valueMap, String prefix, String suffix)
V - 映射中值的类型source - 包含要替换的变量的源文本valueMap - 映射的值可能为空prefix - 变量的前缀,而不是nullsuffix - 变量的后缀,而不是nullpublic static String replace(Object source, Properties value)
source - 包含要替换的变量的源文本value - 带值的属性可以为空public static String replaceSystemProperties(Object source)
source - 包含要替换的变量的源文本public String replace(String source)
source - 获取要替换的字符串public String replace(String source, int offset, int length)
source - 获取要替换的字符串offset - 偏移数组中的起始偏移必须有效length - 偏移数组中的起始偏移必须有效public String replace(char[] source)
source - 获取要替换的字符数组的源代码public String replace(char[] source, int offset, int length)
source - 获取要替换的字符数组的源代码offset - 偏移数组中的起始偏移必须有效length - 要处理的数组中的长度必须是有效的public String replace(StringBuffer source)
source - 获取要替换的字符数组的源代码public String replace(StringBuffer source, int offset, int length)
source - 源缓冲区用作模板,没有更改offset - 偏移数组中的起始偏移必须有效length - 要处理的数组中的长度必须是有效的public String replace(CharSequence source)
source - 源缓冲区用作模板,没有更改public String replace(CharSequence source, int offset, int length)
source - 获取要替换的字符数组的源代码offset - 偏移数组中的起始偏移必须有效length - 要处理的数组中的长度必须是有效的public String replace(StrBuilder source)
source - 获取要替换的字符数组的源代码public String replace(StrBuilder source, int offset, int length)
source - 获取要替换的字符数组的源代码offset - 偏移数组中的起始偏移必须有效length - 要处理的数组中的长度必须是有效的public String replace(Object source)
source - 获取要替换的字符数组的源代码public boolean replaceIn(StringBuffer source)
source - 获取要替换的字符数组的源代码public boolean replaceIn(StringBuffer source, int offset, int length)
source - 获取要替换的字符数组的源代码offset - 偏移数组中的起始偏移必须有效length - 要处理的数组中的长度必须是有效的public boolean replaceIn(StringBuilder source)
source - 获取要替换的字符数组的源代码public boolean replaceIn(StringBuilder source, int offset, int length)
source - 获取要替换的字符数组的源代码offset - 偏移数组中的起始偏移必须有效length - 要处理的数组中的长度必须是有效的public boolean replaceIn(StrBuilder source)
source - 获取要替换的字符数组的源代码public boolean replaceIn(StrBuilder source, int offset, int length)
source - 获取要替换的字符数组的源代码offset - 偏移数组中的起始偏移必须有效length - 要处理的数组中的长度必须是有效的protected boolean substitute(StrBuilder buffer, int offset, int length)
buffer - 要替换为的字符串生成器,而不是nulloffset - 构造器中的起始偏移量必须有效length - 要处理的构建器中的长度必须是有效的protected String resolveVariable(String variableName, StrBuilder buf, int startPos, int endPos)
getVariableResolver(),其中变量名作为键variableName - 变量名,而不是nullbuf - 是发生替换的缓冲区,而不是nullstartPos - 变量的起始位置,包括前缀,有效endPos - 变量的结束位置,包括后缀,有效public char getEscapeChar()
public void setEscapeChar(char escapeCharacter)
escapeCharacter - 转义字符(0表示禁用转义)public StrMatcher getVariablePrefixMatcher()
public Substitute setVariablePrefixMatcher(StrMatcher prefixMatcher)
prefixMatcher - 前缀匹配器,null被忽略public Substitute setVariablePrefix(char prefix)
prefix - 要使用的前缀字符public Substitute setVariablePrefix(String prefix)
prefix - 变量的前缀,而不是nullpublic StrMatcher getVariableSuffixMatcher()
public Substitute setVariableSuffixMatcher(StrMatcher suffixMatcher)
suffixMatcher - 后缀匹配器,null被忽略public Substitute setVariableSuffix(char suffix)
suffix - 要使用的后缀字符public Substitute setVariableSuffix(String suffix)
suffix - 变量的后缀,而不是nullpublic StrMatcher getValueDelimiterMatcher()
public Substitute setValueDelimiterMatcher(StrMatcher valueDelimiterMatcher)
public Substitute setValueDelimiter(char valueDelimiter)
public Substitute setValueDelimiter(String valueDelimiter)
valueDelimiter - 要使用的变量默认值分隔符字符串可以为null或空public StrLookup<?> getVariableResolver()
public void setVariableResolver(StrLookup<?> variableResolver)
public boolean isEnableSubstitutionInVariables()
public void setEnableSubstitutionInVariables(boolean enableSubstitutionInVariables)
public boolean isPreserveEscapes()
public void setPreserveEscapes(boolean preserveEscapes)
Copyright © 2019. All rights reserved.