public class SI extends Object
| 限定符和类型 | 类 | 说明 |
|---|---|---|
(专用程序包) static class |
SI.LRUCache<K,V> |
Simple LRU Cache, this implementation is not synchronized and not thread-safe.
|
| 限定符和类型 | 字段 | 说明 |
|---|---|---|
private static int |
CACHE_SIZE |
|
private boolean |
enableSIInValues |
|
private boolean |
enableSIInVariables |
是否开启嵌套插值
|
private boolean |
enableUndefinedVariableException |
是否抛出异常,当
valueMap 中不存在指定的变量 |
private static Map<String,String> |
KEY_CACHE |
|
private static int |
KEY_CACHE_SIZE |
|
private static String |
MSG_UNEXPECTED_PARAM |
|
private static int |
NESTED_CACHE_SIZE |
|
private static Map<String,List<Object>> |
NESTED_TEMPLATE_CACHE |
|
private static Map<String,List<StringToken>> |
TEMPLATE_CACHE |
|
private Map<String,Object> |
valueMap |
| 限定符和类型 | 方法 | 说明 |
|---|---|---|
String |
$(CharSequence source) |
Interpolating for strings.
执行插值程序,解析字符串 |
static String |
$(CharSequence source,
Object... arguments) |
Interpolating for strings.
字符串插值 |
SI |
add(Tuple... tuples) |
|
SI |
add(Object... kvs) |
Add key-value pairs to this SI object.
|
SI |
add(Map<String,?> valueMap) |
|
private void |
checkCyclic(String variable,
List<String> variablesStack,
String source) |
Check for circular references when inspecting string interpolation.
|
SI |
del(String... keys) |
|
SI |
fill(Object... kvs) |
Fill key-value pairs to this SI object.
|
private static List<Object> |
getNestedTokens(String source) |
|
private static List<StringToken> |
getTokens(String source) |
|
Map<String,Object> |
getValueMap() |
|
static SI |
init(Object... kvs) |
Instantiate an SI object by key-value pairs, and key must be end with " ->" or " >>>" or " >>",
and key will be removed leading and trailing whitespace.
|
private Object |
interpolate(String source,
NestedStringToken nestedToken,
List<String> variablesStack) |
字符串插值处理
|
boolean |
isEnableSIInValues() |
|
boolean |
isEnableSIInVariables() |
|
boolean |
isEnableUndefinedVariableException() |
|
static SI |
load(Object... kvs) |
Instantiate an SI object by key-value pairs, and key must be end with " ->" or " >>>" or " >>".
|
static SI |
of(Tuple... tuples) |
|
static SI |
of(Object... kvs) |
Instantiate an SI object by key-value pairs.
|
static SI |
of(Map<String,?> map) |
|
SI |
set(Tuple... tuples) |
|
SI |
set(Object... kvs) |
Reset this SI object with key-value pairs.
|
SI |
set(Map<String,?> valueMap) |
|
SI |
setEnableNestedSI(boolean enableNestedSI) |
|
SI |
setEnableSIInValues(boolean enableSIInValues) |
|
SI |
setEnableSIInVariables(boolean enableSIInVariables) |
|
SI |
setEnableUndefinedVariableException(boolean enableUndefinedVariableException) |
|
private static Map<String,Object> |
toMap(boolean withSuffix,
boolean needTrim,
Object... kvs) |
|
String |
toString() |
|
private String |
traverseInterpolation(String source,
List<String> variablesStack,
List<Object> tokens) |
遍历token进行字符串插值
|
private void |
tuplesPutToMap(Tuple... tuples) |
|
private static void |
verifyPairWithStringKey(Object... kvs) |
private static final int CACHE_SIZE
private static final int NESTED_CACHE_SIZE
private static final int KEY_CACHE_SIZE
private static final Map<String,List<StringToken>> TEMPLATE_CACHE
private boolean enableSIInVariables
private boolean enableSIInValues
private boolean enableUndefinedVariableException
valueMap 中不存在指定的变量public static SI of(Object... kvs)
kvs - key-value pairsRuntimeException - if the kvs length not be even.NullPointerException - if the key is null.ClassCastException - if the key is not String.UnexpectedParameterException - if the key is not end with " ->" or " >>>" or " >>".public static SI init(Object... kvs)
String infoTemplate = "ip: ${ip}---port: ${port}---db: ${db}---otherInfo: ${other_info}"; SI si = SI.init(" ip ->", "127.0.0.1", " db ->", "testdb", " port ->", 3306, " dbType ->", "mysql", " other_info ->", Tuple.of("isCluster", true), "description ->", new Object()); String dbInfo = si.$(infoTemplate);
kvs - key-value pairsRuntimeException - if the kvs length not be even.NullPointerException - if the key is null.ClassCastException - if the key is not String.UnexpectedParameterException - if the key is not end with " ->" or " >>>" or " >>".public static SI load(Object... kvs)
SI si = SI.load("ip ->", "127.0.0.1", "port ->", 3306, "db ->", "testdb", "dbType ->", "mysql", "other_info ->", Tuple.of("isCluster", true), "description ->", new Object()); String dbInfo = si.$("ip: ${ip}---port: ${port}---db: ${db}---otherInfo: ${other_info}");
kvs - key-value pairsRuntimeException - if the kvs length not be even.NullPointerException - if the key is null.ClassCastException - if the key is not String.UnexpectedParameterException - if the key is not end with " ->" or " >>>" or " >>".public SI add(Object... kvs)
kvs - key-value pairsRuntimeException - if the kvs length not be even.NullPointerException - if the key is null.ClassCastException - if the key is not String.public SI fill(Object... kvs)
String infoTemplate = "ip: ${ip}---port: ${port}---db: ${db}---otherInfo: ${other_info}"; SI si = SI.of(); si.fill(" ip ->", "127.0.0.1", " db ->", "testdb", " port ->", 3306, " dbType ->", "mysql", " other_info ->", Tuple.of("isCluster", true), "description ->", new Object()); String dbInfo = si.$(infoTemplate);
kvs - key-value pairsRuntimeException - if the kvs length not be even.NullPointerException - if the key is null.ClassCastException - if the key is not String.UnexpectedParameterException - if the key is not end with " ->" or " >>>" or " >>".public SI set(Object... kvs)
kvs - key-value pairsRuntimeException - if the kvs length not be even.NullPointerException - if the key is null.ClassCastException - if the key is not String.private void tuplesPutToMap(Tuple... tuples)
public String $(CharSequence source)
source - source stringCircularReferencesException - when the circular reference occursUndefinedVariableException - No variable was found during string interpolation when enableUndefinedVariableException is true.private Object interpolate(String source, NestedStringToken nestedToken, List<String> variablesStack)
source - 原始字符串nestedToken - nestedTokenvariablesStack - 变量栈private String traverseInterpolation(String source, List<String> variablesStack, List<Object> tokens)
source - 原始字符串variablesStack - 变量栈tokens - tokensprivate void checkCyclic(String variable, List<String> variablesStack, String source)
variable - 当前检查的变量variablesStack - 变量栈source - 原始字符串public static String $(CharSequence source, Object... arguments)
source - source stringarguments - argumentsprivate static List<StringToken> getTokens(String source)
private static void verifyPairWithStringKey(Object... kvs)
public boolean isEnableSIInVariables()
public SI setEnableSIInVariables(boolean enableSIInVariables)
public boolean isEnableSIInValues()
public SI setEnableSIInValues(boolean enableSIInValues)
public SI setEnableNestedSI(boolean enableNestedSI)
public boolean isEnableUndefinedVariableException()
public SI setEnableUndefinedVariableException(boolean enableUndefinedVariableException)
Copyright © 2023 io-fairy. All rights reserved.