Class Template.Extractor
java.lang.Object
io.aiven.kafka.connect.common.templating.Template.Extractor
- Enclosing class:
- Template
Given a template, the
Template.Extractor finds the matching variables from a string.
Where an Template.Instance generates strings by filling in the variables in a template, the Template.Extractor does
the opposite:
// Renders the string "Hello World!"
var tmpl = Template.of("Hello {{name}}!");
var greeting = tmpl.instance().bindVariable("name", () -> "World").render();
// The other way around, extracts a name from a string:
tmpl.extractor().extract(greeting); // returns a map {name=World}
tmpl.extractor().extract("Hello everyone!"); // returns a map {name=everyone}
The intention is that applying the map back to the template will yield the original string, but the round-trip is
not always exact.
- Rendering a string uses a supplier and the extractor returns a fixed string.
- Variable parameters are currently ignored (to be determined).
-
Method Summary
-
Method Details
-
extract
Performs the variable extraction from the input string.- Parameters:
input- A string to extract variables from.- Returns:
- An immutable map of key-value pairs extracted from the input string, corresponding to the template variable names.
- Throws:
IllegalArgumentException- If the input string does not match the template.
-