public class VariableReplacer
extends java.lang.Object
${variable}.
Example code:
VariableReplacer varrep = new VariableReplacer("a ${var} string");
while (varrep.findNext())
{
...
String var = varrep.getVariable();
...
varrep.replaceWith("short");
...
}
varrep.getResult()
| Modifier and Type | Field and Description |
|---|---|
static java.util.regex.Pattern |
VAR_PATTERN
the regular expression pattern used to find the variables
|
| Constructor and Description |
|---|
VariableReplacer(java.lang.String string)
Constructs a new
VariableReplacer. |
| Modifier and Type | Method and Description |
|---|---|
boolean |
findNext()
Finds the next variable.
|
java.lang.String |
getResult()
Returns the string after replacing the variables.
|
java.lang.String |
getVariable()
Returns the current variable name.
|
static java.lang.String |
replace(java.lang.String string,
java.util.Map<java.lang.String,java.lang.String> values)
Replaces all variables with the values provided in the map.
|
static java.lang.String |
replace(java.lang.String string,
java.util.Map<java.lang.String,java.lang.String> values,
boolean exceptionOnMissing)
Replaces all variables with the values provided in the map.
|
void |
replaceWith(java.lang.String value)
Replace the current variable with the given value.
|
public static final java.util.regex.Pattern VAR_PATTERN
public VariableReplacer(java.lang.String string)
VariableReplacer.string - the string to be parsedpublic boolean findNext()
public java.lang.String getVariable()
findNext()
has returned true.public void replaceWith(java.lang.String value)
value - the value to replace the current variable withpublic java.lang.String getResult()
public static java.lang.String replace(java.lang.String string,
java.util.Map<java.lang.String,java.lang.String> values)
string - the string containing the variablesvalues - the values to replace the variables withpublic static java.lang.String replace(java.lang.String string,
java.util.Map<java.lang.String,java.lang.String> values,
boolean exceptionOnMissing)
string - the string containing the variablesvalues - the values to replace the variables withexceptionOnMissing - whether a missing value for a variable should
lead to an exceptionjava.util.MissingResourceException - if exceptionOnMissing is
true and the value for an encountered variable is missing
from the map