本文整理了Java中org.crsh.util.Utils.interpolate()
方法的一些代码示例,展示了Utils.interpolate()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Utils.interpolate()
方法的具体详情如下:
包路径:org.crsh.util.Utils
类名称:Utils
方法名:interpolate
[英]Interpolate a string and replace the occurence from a context map, the syntax for a variable is ${}
and it can accept a default value used when the variable cannot be resolved with the :-
separator:
{}
+ "foo" => "foo"{}
+ "${foo}" => ""{}
+ "\${foo}" => "${foo}"{foo:bar}
+ "${foo}" => "bar"{}
+ "${foo:-bar}" => "bar"${}
,当无法使用:-
分隔符解析变量时,它可以接受使用的默认值:{}
+“${foo}”=>{}
+“\${foo}”=>“${foo}”{foo:bar}
+“${foo}”=>“酒吧”{}
+“${foo:-bar}”=>“bar”代码示例来源:origin: crashub/crash
/**
* The path property is resolved from the servlet context parameters. When the parameter does not exist,
* the <code>defaultValue</code> argument is used instead, so it should not be null.
* After the path is resolved, it is interpolated using the JVM system properties and the syntax
* defined by the {@link org.crsh.util.Utils#interpolate(String, java.util.Map)} function.
*
* @param propertyName the property name to resolve
* @param defaultValue the default property value
* @return the path value
*/
private String resolvePathProperty(String propertyName, String defaultValue) {
String path = context.getInitParameter(propertyName);
if (path == null) {
path = defaultValue;
}
return Utils.interpolate(path, System.getProperties());
}
代码示例来源:origin: crashub/crash
public void testInterpolate() {
Map<String,String> context = Collections.singletonMap("foo", "bar");
assertEquals("", Utils.interpolate("", context));
assertEquals("$", Utils.interpolate("$", context));
assertEquals("${foo}", Utils.interpolate("\\${foo}", context));
assertEquals("${", Utils.interpolate("${", context));
assertEquals("${a", Utils.interpolate("${a", context));
assertEquals("bar", Utils.interpolate("${foo}", context));
assertEquals("<bar>", Utils.interpolate("<${foo}>", context));
assertEquals("<bar></bar>", Utils.interpolate("<${foo}></${foo}>", context));
assertEquals("", Utils.interpolate("${bar}", context));
assertEquals("juu", Utils.interpolate("${bar:-juu}", context));
assertEquals("bar", Utils.interpolate("${foo:-juu}", context));
assertEquals("", Utils.interpolate("${bar:-}", context));
assertEquals("juu", Utils.interpolate("${:-juu}", context));
assertEquals(":-", Utils.interpolate("${bar:-:-}", context));
}
}
代码示例来源:origin: com.github.corda.crash/crash.shell
/**
* The path property is resolved from the servlet context parameters. When the parameter does not exist,
* the <code>defaultValue</code> argument is used instead, so it should not be null.
* After the path is resolved, it is interpolated using the JVM system properties and the syntax
* defined by the {@link org.crsh.util.Utils#interpolate(String, java.util.Map)} function.
*
* @param propertyName the property name to resolve
* @param defaultValue the default property value
* @return the path value
*/
private String resolvePathProperty(String propertyName, String defaultValue) {
String path = context.getInitParameter(propertyName);
if (path == null) {
path = defaultValue;
}
return Utils.interpolate(path, System.getProperties());
}
代码示例来源:origin: org.crashub/crash.shell
/**
* The path property is resolved from the servlet context parameters. When the parameter does not exist,
* the <code>defaultValue</code> argument is used instead, so it should not be null.
* After the path is resolved, it is interpolated using the JVM system properties and the syntax
* defined by the {@link org.crsh.util.Utils#interpolate(String, java.util.Map)} function.
*
* @param propertyName the property name to resolve
* @param defaultValue the default property value
* @return the path value
*/
private String resolvePathProperty(String propertyName, String defaultValue) {
String path = context.getInitParameter(propertyName);
if (path == null) {
path = defaultValue;
}
return Utils.interpolate(path, System.getProperties());
}
内容来源于网络,如有侵权,请联系作者删除!