public class Template extends Object
You supply a template String and an array of tokens to replace when calling
#apply(String...). The order of tokens supplied in the constructor
corresponds to the order of strings supplied in apply().
The Template will compile your string into an executable stack, which generates output with extreme efficiency; the only string-matching performed is during Template compile, and it processes all tokens in a single, efficient iteration of the template String.
This ensures an absolute minimum of processing, and allows large templates with a large number of replacements to scale nicely.
Usage:
assert
new Template("$1, $2!", "$1", "$2")
.apply("Hello", "World")
.equals("Hello, World!");
assert
new Template("(*[])$.toArray(new Object[$.size()])", "*", "$")
.apply("Callable<String>", "myList")
.equals("(Callable<String>[])myList.toArray(new Object[myList.size()])");
| Constructor and Description |
|---|
Template(String template,
Iterable<String> replaceables) |
Template(String template,
String... replaceables) |
| Modifier and Type | Method and Description |
|---|---|
String |
apply(Object... args)
Applies the current template to the supplied arguments.
|
void |
setToStringer(ToStringer toString) |
protected static String[] |
toArray(Iterable<String> items) |
Copyright © December 07, 2012–2015 The Internet Party. All rights reserved.