public abstract class VariableInterpolator extends Object implements IClusterable
String. So, a variable interpolator substitutes the values of one or more variables
into a String.
The String to interpolate (substitute into) is passed to the
VariableInterpolator's constructor. Variables are denoted in this string by the
syntax ${variableName}. A subclass provides an implementation for the abstract
method getValue(String variableName). The toString() method then
performs an interpolation by replacing each variable of the form ${variableName}
with the value returned by getValue("variableName").
"$" is the escape char. Thus "$${text}" can be used to escape it (ignore interpretation). If '$3.24' is needed then '$$${amount}' should be used. The first $ sign escapes the second, and the third is used to interpolate the variable.
| Modifier and Type | Field and Description |
|---|---|
protected String |
string
The
String to interpolate into |
| Constructor and Description |
|---|
VariableInterpolator(String string)
Constructor.
|
VariableInterpolator(String string,
boolean exceptionOnNullVarValue)
Constructor.
|
| Modifier and Type | Method and Description |
|---|---|
protected abstract String |
getValue(String variableName)
Retrieves a value for a variable name during interpolation.
|
String |
toString()
Interpolates using variables.
|
protected final String string
String to interpolate intopublic VariableInterpolator(String string)
string - a String to interpolate with variable valuespublic VariableInterpolator(String string, boolean exceptionOnNullVarValue)
string - a String to interpolate with variable valuesexceptionOnNullVarValue - if true an IllegalStateException will be thrown if
getValue(String) returns null, otherwise the
${varname} string will be left in the String so that
multiple interpolators can be chainedCopyright © 2006–2020 Apache Software Foundation. All rights reserved.