Modifier and Type | Method and Description |
---|---|
static String |
encode(String varname)
Returns the string encoding for a variable with the given
name . |
static String |
encode(String varname,
int index)
Returns the string encoding for an indexed variable with the given
name and index . |
static boolean |
isVariable(String expression)
Returns true if the given
expression represents an encoded
variable. |
static String |
resolve(String expression,
Map<String,String> variables)
If
expression represents an encoded variable, it is resolved
using the values in the given map . |
public static String encode(String varname)
name
.
The returned string has the form "{varname}". For instance, a
variable named "hostname" would result in a string
"{hostname}".varname
- the name of the variablepublic static String encode(String varname, int index)
name
and index
. The returned string has the form
"{varname[index]}". For instance, the second element of a
variable named "args" would result in a string
"{args[1]}".varname
- the name of the variableindex
- the zero-based variable indexpublic static boolean isVariable(String expression)
expression
represents an encoded
variable. A variable expression starts with "{" and ends with
"}" as described for encode(String)
and
encode(String, int)
.expression
- the expression to be checkedpublic static String resolve(String expression, Map<String,String> variables)
expression
represents an encoded variable, it is resolved
using the values in the given map
. The key in the map must
exactly match the encoded expression to be successfully resolved. If no
value is found for the variable expression, an expression is thrown.
If the given expression does not represent a variable, it is returned unchanged.
expression
- the expression to resolvevariables
- the variable values with the encoded variable name as keyexpression
represents a
variable, and the unchanged expression otherwiseIllegalArgumentException
- if expression
represents a variable but no value for
this variable is found in the given variables
mapCopyright © 2024. All rights reserved.